Cache-control when using mod_cache and mod_pagespeed

cache-controlmod-cachemod-pagespeed

I'm using mod_pagespeed with mod_cache.

When mod_pagespeed is off and mod_cache is off I see the following header:

cache-control:public,max-age=7200,must-revalidate

When mod_pagespeed is on and mod_cache is off, I see the following header on the response:

cache-control:max-age=0, no-cache, must-revalidate

As expected pagespeed has rewritten the cache-control.

However, when mod_pagespeed is on and mod_cache is on I see the following:

cache-control:public,max-age=7200,must-revalidate

According to the docs:

"By default, PageSpeed serves all HTML with Cache-Control: no-cache,
max-age=0 because the transformations made to the page may not be
cacheable for extended periods of time."

Why is the html being served as cacheable when mod_pagespeed and mod_cache is enabled?

Best Answer

There appears to be a bug when running mod_pagespeed 1.11.33.2-0 with Apache Httpd 2.4.23 running mod_cache.

For some reason mod_pagespeed does not rewrite the cache headers which leaves the html publically cacheable.

The workaround I used was to have virtualhost on port 81 running as a caching server with no pagespeed.

<VirtualHost *:81>
ProxyPass / ajp://tomcat-ipaddress:8009/
ProxyPassReverse / https://final-hostname/
ModPagespeed off
RemoteIPHeader X-Forwarded-For
CacheEnable disk /
CacheHeader on
</VirtualHost>

On virtualhost 443 or 80, you can then proxy the host on 81.

 <VirtualHost _default_:443>
 ProxyPass / http://localhost:81/
 ProxyPreserveHost On
 ModPagespeed on
 ProxyPassReverse / https://final-hostname/
Related Topic