Fragmented Thought

Apache Content Caching

By

Published

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

# Cache Control with .htaccess
# from http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=$Time"
</FilesMatch>

And list of some common times:

  • 300 5 MIN
  • 600 10 MIN
  • 900 15 MIN
  • 1800 30 MIN
  • 2700 45 MIN
  • 3600 1 HR
  • 18000 5 HR
  • 43200 12 HR
  • 86400 24 HR
  • 86400 1 DAY
  • 172800 2 DAY
  • 259200 3 DAY - This is the limit for YSlow's Far Future Restriction
  • 345600 4 DAY
  • 432000 5 DAY
  • 518400 6 DAY
  • 604800 7 DAY
  • 604800 1 WEEK
  • 1209600 2 WEEK
  • 1814400 3 WEEK
  • 2419200 4 WEEK
  • 2419200 1 MONTH (FEBRUARY)
  • 2505600 1 MONTH (FEBRUARY LEAP YEAR)
  • 2592000 1 MONTH (APRIL, JUNE, SEPTEMBER, NOVEMBER)
  • 2678400 1 MONTH (JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER)
  • 31536000 12 MONTH

Of course, the best policy would be to implement permanent caching of static content, then use version numbers on your content. A huge bonus of doing this is that people visiting your site get fresh files, every time you make a change, instead of telling your client to reload.

For more information on the reasoning behind doing this, you can read up on Yahoo's YSlow site.