In Apache, there are three ways to set cache control rules:
1.Via <meta> tags (<meta http-equiv="Expires"...>)
This method works with browsers, but most intermediate proxy servers don’t parse HTML files, they look for HTTP headers to set caching policy.
2.Programmatically by setting HTTP headers (in PHP scripts etc.)
This method is useful for dynamic PHP scripts that output dynamic data. This is done by setting cache control headers (Expires and CacheControl for example).
3.Through web server configuration file (httpd.conf)
This approach is widely used for caching of static web objects. This requires mod_expires and mod_headers to be installed with apache. To turn on mod_expires set ExpiresActive to ON and target the web directory to specify the expiry time for all files based on their extensions. Eg:
<Directory "/home/website/public_html"> Options FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all ExpiresDefault A300 <FilesMatch "\.html$"> Expires A86400 </Files> <FilesMatch "\.(gif|jpg|png|js|css)$"> Expires A2592000 </Files></Directory>
You may refer to the “Use Server Cache Control to Improve Performance” article for more details.
Tags: apache, caching, performance












0 Responses to “Caching in Apache”
Leave a Reply