Showing posts with label cache cleaning aborted. Show all posts
Showing posts with label cache cleaning aborted. Show all posts

Tuesday, April 23, 2013

Cleaning cache for Apache by htcacheclean


Detecting apache cache problem, cleaning cache for apache by htcacheclean.
good pages: page1, page2, page3.

My case:
in apache config /www/etc/apache/adm/virt.serv/10_my-service.cfg:

CacheRoot /www/cache/my-service
CacheDirLevels 2
CacheDirLength 1
CacheDefaultExpire 3600
CacheIgnoreCacheControl On
CacheEnable disk /my-service/

I get different content:
wget https://server.com/my-service/css/layout.css
wget https://test-server.com/my-service/css/layout.css

as HTTP Header have value:
Cache-Control: max-age=31556926, must-revalidate 
How to get this in Firebug addon of Firefox:

Or you can do this from terminal :
06:20 PM ~ $ curl -I https://server.com/my-service/css/layout.css
HTTP/1.1 200 OK
Date: Wed, 24 Apr 2013 01:20:08 GMT
Server: Apache/2.2.19 (FreeBSD)
Expires: Thu, 24 Apr 2014 07:08:54 GMT
Cache-Control: max-age=31556926, must-revalidate
Last-Modified: Mon, 22 Apr 2013 17:32:10 GMT
Content-Length: 36490
Connection: close
Content-Type: text/css
Set-Cookie: Coyote-2-4a7446e9=c0a89971:0; path=/

So caching could be adjusted on Tomcat side, after then on Apache side(CacheDefaultExpire and "CacheEnable disk /my-service/"), and then kept by user's Browser(Cache-Control: max-age). 

Cache could be adjusted in tomcat side in Spring config (28800 = 8 hour):
<mvc:resources mapping="/css/**" location="/css/" cache-period="28800" />

So after each Tomcat rollout we have to do:
htcacheclean -p/www/cache/my-service -l1K -v

if you have problem on apache clear cache like "An error occurred, cache cleaning aborted."
be sure you  /www/cache/my-service/ is created and "chown apache /www/cache/my-service/", "apache" username is taken from "ps -ef| grep http" as on Freebsd it is "www". Also be sure you launch htcacheclean under right user.