Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a PHP site that has many dynamically generated pages. I'm trying to turn to mod_cache to help boost performance, because in most cases, content does not change in a given day.

I have configured mod_cache as best I could, following examples around the web, including the mod_cache page on When I set LogLevel debug, I see a bit of information about the caching that is [not] happening. There are plenty of pairs of lines like this:

[Fri Jun 01 17:28:18 2012] [debug] mod_cache.c(141): Adding CACHE_SAVE filter for /foo/bar
[Fri Jun 01 17:28:18 2012] [debug] mod_cache.c(148): Adding CACHE_REMOVE_URL filter for /foo/bar

Which is fine, because I've set CacheEnable disk /foo, to indicate that I want everything under /foo cached. I'm new to mod_cache, but my understanding about these lines is that it just means that mod_cache has acknowledged that the URL is supposed to be cached, but there are supposed to be more lines indicating that it is saving the data to cache, and then later retrieving them on subsequent hits to the same URL.

I can hit the same URL till I'm blue in the face, whether with F5 refreshing, or not, or with different browsers, or different computers. It's always that pair of lines that shows in the logs, and nothing else.

When I set CacheEnable disk /, then I see more activity. But I don't want to cache the entire site, and there are many, many different subpaths to the site, so I don't want to have to modify code to set no-cache headers in all the necessary places.

I'll mention that mod_rewrite is in use here, rewriting /foo/bar to something like index.php?baz=/foo/bar, but my understanding is that mod_cache uses the pre-rewrite URL, not the post-rewrite URL.

As far as I can tell, I have the response headers not getting in the way of caching. Here's an example from one hit:

Cache-Control:must-revalidate, max-age=3600
Date:Fri, 01 Jun 2012 21:43:09 GMT
Expires:Fri,  1 Jun 2012 18:43:09 -0400
Keep-Alive:timeout=15, max=100

mod_cache config is as follows:

CacheRoot   /var/cache/apache2/
CacheDirLevels 3
CacheDirLength 2
CacheEnable disk /foo

What is getting in the way of mod_cache doing its job of caching?

share|improve this question
I should add that I am outputting time() at the bottom of each page, so I can see whether a served page is cached or not. – Pistos Jun 1 '12 at 22:29
Please check first if apache created directories in /var/cache/apache2. This was my problem. You need to create the cache directory with the right permissions. – Janning Jun 3 '12 at 9:24
@Janning: Yes, the cache directory is getting filled with dirs and files with recent timestamps. – Pistos Jun 4 '12 at 1:00
I can clear that dir out and double check, though. – Pistos Jun 4 '12 at 1:01
Possibly related:… – Pistos Jun 4 '12 at 3:34

2 Answers 2

This is my configuration and it works fine:

<IfModule mod_disk_cache.c>
    CacheEnable disk /
    CacheRoot /var/cache/apache2/mod_disk_cache
    CacheIgnoreCacheControl On
    CacheMaxFileSize 2500000
    CacheIgnoreURLSessionIdentifiers jsessionid
    CacheIgnoreHeaders Set-Cookie

You need to have CacheIgnoreURLSessionIdentifiers which fits your needs so maybe on PHP you need

CacheIgnoreURLSessionIdentifiers PHPSESSID

regards Janning

share|improve this answer
Ignoring PHPSESSID didn't help, but I appreciate you taking the time to comment on my problem. – Pistos Jun 4 '12 at 21:49
send your full and real config to me per PM at i will check it out and try to help you. We shouldn't use SO as a messaging platform. btw: your question relates to and not stackoverflow – Janning Jun 5 '12 at 7:43

I was facing the same problem trying to map

CacheEnable Disk /api

The only mapping that worked was

CacheEnable Disk / 

Which cached everything.

Even though the documentation says that mod_cache runs after url-rewrite it didn't. To get it working I changed it to

CacheEnable Disk /index.php/api
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.