Forum Moderators: phranque
I've tried putting configurations into various context's i.e server-config->VirtualHost->Directory, then in server-config->VirtualHost then in server-config. No joy from any.
Here's my try mod_cache setup attempt in httpd.conf
...LoadModule cache_module modules/mod_cache.so
LoadModule disk_cache_module modules/mod_disk_cache.so
...
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot /var/lib/webserver_cache
# Cache size in KBytes, 50mb
CacheSize 50000
# Enable caching for all files in the directory /dir/
CacheEnable disk domain.net/dir/
CacheDirLevels 2
CacheDirLength 1
# store for one hour
CacheDefaultExpire 3600
# override http headers cache control
CacheIgnoreCacheControl On
# dont send set-Cookie in headers
CacheIgnoreHeaders Set-Cookie
# max expiry set to one day
CacheMaxExpire 86400
</IfModule>
</IfModule>
mod_cache
I have the tiniest pages of javascript on my site, which is generated by server side code which grabs price information from a lot of different webservers. The strategy however is to store this information for up to a day, and hence not have to ask for the information from other webservers again until this period has elapsed . The problem is, how? I can write something at the application layer, i.e. store this data in a database. But better yet get Apache to do it hurrah, Which begs the question, how?
Read Apache's mod_cache documentation if you want further insight. The rest of this document outlines the steps to caching all the pages on my website which begin with
www.mydomain.com/dir/
installation
Check mod_cache is installed on your apache server. Open http.conf and you should find mod_cache written e.g...
httpd.conf
...
LoadModule cache_module modules/mod_cache.so
...
# Additionally
...
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
...
Set cache variables in httpd.conf
I am running various Virtual Hosts on my webserver. If you are familiar with these then this should not look to strange.
httpd.conf
...
### Virtual Hosts
<VirtualHost *>
ServerName www.mysite.co.uk
DocumentRoot /var/www/mysite/www
...
<Directory "/var/www/mysite/www">
...
</Directory>
...
# Cache directives here (below), Must go at the end of the VirtualHost.
<IfModule mod_cache.c>
<IfModule mod_disk_cache.c>
CacheRoot "/var/lib/httpdcache"
# Cache size in KBytes, 50mb
CacheSize 50000
# Enable caching for all files of all child directories of dir/
CacheEnable disk dir/
CacheDirLevels 2
CacheDirLength 1
# store for one Day
CacheDefaultExpire 86400
# override http headers cache control
CacheIgnoreCacheControl On
# dont send set-Cookie in headers
CacheIgnoreHeaders Set-Cookie
# max expiry set to one day
CacheMaxExpire 86400
</IfModule>
</IfModule>
</VirtualHost>
...
Make the cache directory
/var/lib/httpdcache
shell
mkdir /var/lib/httpdcache
chmod 777 /var/lib/httpdcache
chown nobody /var/lib/httpdcache
Restart httpd server
shell
# Works from roots directory, 'su -'
service httpd restart
Now define headers, which the server will read to determine whether to use the cached page or not. Open up and edit the individual file placing headers.
pricerunner.php
/**
* Date in the future
*/
header("Expires: Mon, 26 Jul 2006 05:00:00 GMT");
/**
* Last Modified
*/
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
/**
* HTTP 1.1
*/
header("Cache-Control: ");