blog.quehy.com freshmeat squid

What is ModCache

Mod-Cache is a cache accelerator plugin for lighttpd, which works like Squid with similar configuration. However mod_cache is faster and more effective than Squid because of powerful Lighttpd.

Mod-Cache has following advantages over Squid:

How to use Mod-Cache

Mod-Cache provides following options:

Refresh Patterns

cache.refresh-pattern likes squid's refresh-pattern. cache.refresh-pattern format is "url_pcre_regex" => "minutes options". Note: zero 'minutes' means cache forever and minutes option is mandatory.
Available refresh-pattern options are: Mod-Cache don't cache urls without refresh-pattern rules matched.

How Mod-Cache works

Mod-Cache implements as below: (use http://host/uri as url example)

Step 1: mod_cache_uri_handler.
   checks cache.domains, cache.refresh-pattern orderly for whether to use cache or not; if OK, then checks file 'cache.bases/host/uri' existness and it's expire time; if OK again, set con->use_cache_file to 1;
Step 2: mod_cache_docroot_handler.
   If con->use_cache_file was 1, set con->physical.doc_root to cache.bases and con->physical.rel_path to '/host/uri'; otherwise just returns.
Step 3: mod_proxy.
   If con->use_cache_file was 0, mod_proxy will set con->write_cache_file to 1; otherwise mod_proxy just returns.
Step 4: Actual request handle. request handled by mod_staticfile mod_compress or mod_proxy depend on lighttpd configuration.
Step 5: mod_cache_handle_response.
   If con->write_cache_file was 1, mod_cache will try to save response content to 'cache.bases/host/uri', some useful response's headers to 'cache.bases/host/uri.cachehd'; otherwise mod_cache fills current response headers with cached headers.
Step 6: mod_cache_cleanup.
   If con->write_cache_file was 1 and everything went ok, mod_cache closes fd of cached file.

Config example for lighttpd 1.4 series

Cache for static web page server:

cache.support-queries = "enable" #ignore '?' in url
cache.bases = ("/data/cache") #write cached files in /data/cache directory
cache.refresh-pattern = (
	"/$" => "5 update-on-refresh no-expire-header", # update homepage every 5 minutes and on refresh requests without setting expire headers
	"\.(?i)(flv)$" => "0 fetchall-for-range-request flv-streaming", # to work with mod_flv_streaming for flv files
	"\.(?i)(js|css|xml)$" => "240", # update js/css/xml every 4 hours and on refresh requests
	"\.(?i)(htm|html|shtml)$" => "30", # update html/htm/shtml every 30 minutes and on refresh requests
	"\.(?i)(jpg|bmp|jpeg|gif|png)$" => "2880", # update graphics files every 2 days
	"\.(?i)(rar|zip|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb|flv)$" => "0 fetchall-for-range-request", # cache media file forever
	"." => "30 update-on-refresh" # default to update every 30 minutes and on refresh requests
)
#mod_proxy setting, config your backend servers here
proxy.server  = ( "/" =>
        (
                ( "host" => "x.x.x.x", "port" => 80 ) # real backend http server ip and port
        )
)
#it's important to enable proxy.worked-with-modcache, 
#  or mod_proxy will not cooperate with mod-cache
proxy.worked-with-mod-cache = "enable"

Config example for lighttpd 1.5 series

Cache for static web page server:

cache.support-queries = "enable" #ignore '?' in url
cache.bases = ("/data/cache") #write cached files in /data/cache directory
cache.refresh-pattern = (
	"/$" => "5 update-on-refresh no-expire-header", # update homepage every 5 minutes and on refresh requests without setting expire headers
	"\.(?i)(flv)$" => "0 fetchall-for-range-request flv-streaming", # to work with mod_flv_streaming for flv files
	"\.(?i)(js|css|xml)$" => "240", # update js/css/xml every 4 hours and on refresh requests
	"\.(?i)(htm|html|shtml)$" => "30", # update html/htm/shtml every 30 minutes and on refresh requests
	"\.(?i)(jpg|bmp|jpeg|gif|png)$" => "2880", # update graphics files every 2 days
	"\.(?i)(rar|zip|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb|flv)$" => "0 fetchall-for-range-request", # cache media file forever
	"." => "30 update-on-refresh" # default to update every 30 minutes and on refresh requests
)
#mod_proxy_core setting, config your backend servers here
proxy-core.backends = ( "x.x.x.x:80", "y.y.y.y:80")
proxy-core.balancer = "round-robin" # or "sqf" or "carp"
proxy-core.protocol = "http"
#it's important to enable proxy-core.worked-with-modcache, 
#  or mod_proxy_core will not cooperate with mod-cache
proxy-core.worked-with-modcache = "enable"

Downloads

Stable version 1.4.4 for lighttpd 1.4.19, released on Apr 9, 2008

Stable version 1.4.2/1.4.3, released on Feb 29, 2008

Stable version 1.4.1, released on Sep 23, 2007

Stable version 1.4, released on May 03, 2007

Stable version 1.3.2, released on Feb 08, 2007

Stable version 1.2, released on Nov 28, 2006

Stable version 1.1, released on Nov 17, 2006

Stable version 1.0, released on Oct 27, 2006

Changelog

Stable Version 1.4.4

Stable Version 1.4.2/1.4.3

Stable Version 1.4.1

Stable Version 1.4

Stable Version 1.3.2

Stable Version 1.3.1

Stable Version 1.3

Stable Version 1.2

Stable Version 1.1

Stable Version 1.0

TODO

Discussion Group

Please visit Mod-Cache group hosted on google-groups. Feedback are welcomed!

Mod-Cache released under BSD License, Copyright (c) 2006, 2008 QUE Hongyu