0

Apache 2.2 on RedHat 6.3. I have a virtual host that is setup like so:

<VirtualHost xxx.xxx.xxx.xxx:80>
ServerAdmin some@email.com
DocumentRoot /home/xxxxx/Sites/xxxxxxx.com/htdocs
ServerName xxxxxxx.com

ServerAlias xxxxxxxx.com

SuexecUserGroup xxxx xxxx
suPHP_UserGroup xxxx xxxx


## a cache hit will log -, while a cache miss will log 1.
SetEnv CACHE_MISS 1
LogFormat "%h %l %u %t \"%r\" %>s %b %{CACHE_MISS}e" common-cache
CustomLog /var/log/cache.log common-cache

<IfModule mod_mime_magic.c>
#   MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
</IfModule>
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot "/var/www/cache"
CacheDefaultExpire 3600
CacheIgnoreCacheControl On
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
CacheMaxFileSize 1000000
</IfModule>
</IfModule>

# support perl + cgi
ScriptAlias /cgi-bin/ /home/ls414-100/Sites/xxxx.com/htdocs/cgi-bin/

<Directory /home/xxxx/Sites/xxxxx.com/htdocs/cgi-bin/>
      Options ExecCGI -Indexes -MultiViews
      AddHandler cgi-script cgi pl
</Directory>
</VirtualHost>

But it will not log cache hits.

[25/Sep/2013:15:24:22 -0400] "GET /icons/stuff5.jpg HTTP/1.1" 304 - 1

Please notice the '1' at the end, it means it didn't cache.

Any help will be greatly appreciated.

user1663896
  • 9
  • 1
  • 3

2 Answers2

0

All I see is that you are forcing CACHE_MISS to have a value of 1

SetEnv CACHE_MISS 1

So, it will always be 1 in the log output. Take a look at the 304 response code. It means that the file requested is not modified so it can be served by the browser cache.

Mauricio López
  • 974
  • 4
  • 9
  • Thanks! I did and it led me to this bug in apache: https://issues.apache.org/bugzilla/show_bug.cgi?id=45341 – user1663896 Sep 26 '13 at 14:38
  • I have done similar changes and I see value value 1 and sometime empty , which means resource is served from cache. I am on apache 2.2.3 – skillguru Oct 29 '15 at 17:29
0

I have a very similar setup to record cache hit in my logs. Most likely reasons that you stop seeing cache hits, based on my experience:

  • permissions on the cache directory are incorrect.
  • ran out of space df -h or inodes df -ih in your cache filesystem

I would invite you to reengineer your decision to use Apache httpd as a cache; I've had a lot of issues with this in the past with odd errors, incomplete images, the truly sucky excuse for a cache maintenance tool that is htcacheclean (you are running this right?) my most recent frustration (which is triggering a re-architect) is that it won't cache 206 responses (MP4s, PDFs).

There is much you can do to reduce the amount of objects you ask httpd to cache for you; disabling the Vary of User-Agent is a big win. You can also rewrite compression related request headers, which helps to massively reduce the number of useless variations you end up caching.

Cameron Kerr
  • 4,069
  • 19
  • 25