Cache Control?


I’m very new to using the Cache Control in PHP.

I’m keen to see what others typically use in their PHP Applications.
I suppose it depends on what the site is about and what kind of files are delivered.

Typically I use the following for most of my sites:

# 480 weeks
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
# 2 DAYS
<FilesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
<FilesMatch "\\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"

I got it from here:

Also, how does the user retrieve a NEW version of a PDF of the same file name? If, say, a new PDF was uploaded with the same file name as a previous one, how do you force the user to view the new version?

Thanks for your thoughts.


Well, you’ve hit on the reason NOT to use LONG cache numbers! IMHO, you can’t go crazy with this stuff or you’ll shoot yourself in the foot!

I HAVE used caching but only with the OUTPUT of a long page (client control and I couldn’t control the client) when the contents of that page were updated.

Browsers do cache files and, unless there is a GOOD reason to cache, it’s not worth the additional effort and problems (especially in this world of broadband).