How to enable cache in Apache httpd server ?

Apache comes with three modules for caching content, one enables it and the remaining two determine where the cache store exists – on disk or in memory. Determining which module to use for the cache store depends on your available hardware resources and performance requirements.

Serving from disk is slow but less expensive. Serving from memory is fast, but expensive – both in cost and in resource consumption. However, you can boost disk cache performances by placing it on SSDFLASH storage instead of conventional spinning disk

1.Ensure the cache_module is being loaded by Apache, by verifying the following line exists in Apache’s server configuration file, uncommented.

LoadModule cache_module modules/

2.For disk caching, ensure the disk_cache_module is being loaded by Apache. Look for the following line, uncommented.

LoadModule cache_disk_module modules/

3.Add the following lines in to either the Apache server configuration file (for global) or inside of a VirtualHost directive (application localized).

CacheEnable disk /
CacheRoot /etc/httpd/cache
CacheDefaultExpire 84000
CacheDisable /admin
CacheEnable disk /Unable caching to disk for relative directory “/”.
CacherootSet the cache store directory, where all cached content will be saved.
CacheDefaultExpireSet the default expire date, relative to the original request date, in seconds.
CacheDisableDisables caching for relative paths following the option. Sensitive areas and those that shouldn’t be cached should be added here.

Once the above settings are done access the page and see for the first time 200 responce you can see in the access logs and subsequent request will get 304 from the same client which means the conent was not modified from the last accesss and it served from the cache.

HTTP 304 Not Modified client

The HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *