Caching in Apache
There are many different Apache Modules which implement different kinds of caching behaviors using different mechanisms. Some of these modules are experimental and I don't exactly feel comfortable using them unless its for experimental purposes on my Home Web Server.
From what I understand caching, there can be 2 kinds of caching:
1. Client Side
Client side caching is primarily the Browser cache such as the Temporary Internet files in case of IE.
The Browser has its own default settings for these which the user can tweak per his requirements. But, aside from that, the behavior of this cache is controlled by HTTP header directives. Things like what to cache, how long to cache are determined by what values are set in the HTTP Header. In apache, this can be achieved using modules like mod_expires or mod_header.
2. Server Side.
Server side caching is done by any Server application which implements caching in some way. It could be a dedicated cache or a proxy server with caching enabled or a web server with caching enabled. In apache, this can be achieved using modules like mod_cache.
My personal favorite is client side caching because it can be achieved with little or no overhead and cost.
Mod_Expires
Adding the following to httpd.conf, can improve performance of static content by caching them in the browser for 1 month:
LoadModule expires_module modules/mod_expires.so
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
< Directory "/var/www/" >
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
# Added to improve Static Content Performace
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 day"
< /Directory >
Mod_headers
LoadModule headers_module modules/mod_headers.so
< IfModule mod_header.c >
< FilesMatch "\.(gif|jpg|jpeg|png|css)$" >
Header set Cache-control max-age=2592000
< /FilesMatch >
< /IfModule >
