Apache File Cache Module

If you don’t have a CDN and would like to improve the performance of some of your webpages, you can easily do it using Apache File Cache Module.  Apache’s file cache module allows you to specify specific images and files for your Apache httpd to load into memory.  This saves your machine from all of the read access needed to load the files each time they are requested by browsing clients.  Instead, Apache will serve the requests for the cached objects directly from memory.  To use Apache’s file cache module, you need to download and install mod_file_cache.  Below are instructions for installing it in CentOS 6.

File_mod_cache Prerequisites

Install file_mod_cache prerequisites using yum:

# yum install gcc gcc-c++ kernel-devel httpd-devel

Download and Install File_mod_cache

# mkdir -p /installs/mod_file_cache# cd /installs/mod_file_cache

# wget http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz

–2013-11-14 22:41:46– http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz
Resolving archive.apache.org… 2001:610:1:80bc:192:87:106:229,,
Connecting to archive.apache.org|2001:610:1:80bc:192:87:106:229|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 6593633 (6.3M) [application/x-gzip]
Saving to: “httpd-2.2.15.tar.gz”

100%[===========================================>] 6,593,633 955K/s in 13s

2013-11-14 22:42:00 (497 KB/s) – “httpd-2.2.15.tar.gz” saved [6593633/6593633]


# gunzip httpd-2.2.15.tar.gz

# tar -xvf httpd-2.2.15.tar

# cd httpd-2.2.15/modules/cache

# apxs -i -a -c mod_file_cache.c


That should get mod_file_cache installed, now we need to edit the apache configuration files and list the files that we want it to load into cache when the Apache httpd starts up.

Setup Cached Files in the Apache Configuration Files

See the files added to the VirtualHost below using the “CacheFile /Path/Filename” syntax.

<VirtualHost *:80>
ServerName www.uptimemadeeasy.com
ServerAlias uptimemadeeasy.com
DocumentRoot “/www/uptimemadeeasy.com/”
CustomLog logs/uptimemadeeasy.com-access_log combined        CacheFile /www/uptimemadeeasy.com/index.html
        CacheFile /www/uptimemadeeasy.com/image1.jpg
        CacheFile /www/uptimemadeeasy.com/image2.jpg
        CacheFile /www/uptimemadeeasy.com/contact-us.html
        CacheFile /www/uptimemadeeasy.com/contact-us1.jpg
        CacheFile /www/uptimemadeeasy.com/contact-us2.jpg

<Directory “/www/uptimemadeeasy.com”>
Options FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All


Before Apache can cache and serve the files, it needs to be restarted.  Apache will find the files at startup and cache them then.

# service httpd restart

That should do it.

One Thing to Remember

One thing to remember when you are editing your webpage later on, after you edit the files, you need to restart the Apache httpd to allow the changes to be displayed on your webpage.  The file cache module loads the files at startup and then doesn’t look for them again until the httpd is restarted.  You could even delete the files and there wouldn’t be a noticeable problem until the httpd was restarted and it couldn’t find the files.

The following two tabs change content below.
Jeff has 20 years of professional IT experience, having done nearly everything in his roles of IT consultant, Systems Integrator, Systems Engineer, CNOC Engineer, Systems Administrator, Network Systems Administrator, and IT Director. If there is one thing he knows for sure, it is that there is always a simple answer to every IT problem and that downtime begins with complexity. Seasoned IT professional by day, Jeff hopes to help other IT professionals by blogging about his experiences at night on his blog: http://uptimemadeeasy.com. You can find Jeff on or LinkedIn at: LinkedIn or Twitter at: Twitter

Latest posts by Jeff Staten (see all)

Leave a Reply

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