Project

General

Profile

Actions

Docs ModCache » History » Revision 3

« Previous | Revision 3/32 (diff) | Next »
moo, 2007-07-07 15:28


[[TracNav(DocsToc))] {{{
#!rst ======================
Web Accelerating Cache ======================

-----------------
Module: mod_cache
-----------------

.. meta::
:keywords: lighttpd, cache, squid

.. contents:: Table of Contents

Description ===========
mod_cache is a web accelerating plugin for lighttpd, which works like Squid with similar configuration. mod_cache have several advantages over squid:

  • Simple: mod_cache sets proper flags between lighttpd request handling stages. request is handled by mod_staticfile or mod_proxy or other modules.
  • Robust: mod_cache store caches as plain files instead memory, which makes mod_cache away from memory leaks/exhaustion.
  • Faster: various powerful backends from sendfile, writev to aio are provided by lighttpd
  • Powerful: mod_cache cooperates with other lighttpd plugins(except mod_deflate) very well

Installation ============
This module is a 3rd party module, is not included in the official distribution. You need to download it from here: * For lighttpd 1.4.13: [http://www.linux.com.cn/modcache/lighttpd-1.4.13.mod_cache.v1.2.patch] * For lighttpd 1.5.0.r1605: [http://www.linux.com.cn/modcache/lighttpd-1.5.0.r1605.modcache.v.1.3.2.patch]

PCRE library is needed to build mod_cache!

Options =======
See [http://www.linux.com.cn/modcache/]

cache.bases
directory arrays which want to save cache files.

e.g.: ::
cache.bases=("/data/cache", "/data2/cache")
Default: not set

cache.enable
enable or disable mod_cache.

e.g.: ::
cache.enable = "disable" 
$HTTP["host"] == "video.example.org" {
cache.enable = "enable"
}
Default: enable

cache.domains
domain pcre regex arrays which mod_cache will cache.

e.g.: ::
cache.domains = ("mydomain.com$")
Default: not set (means to cache every domains).

cache.support-queries
ignore '?' in request url or not.

e.g.: ::
cache.support-queries = "enable" # mod_cache treats "/uri?q1" or "/uri?q2" as "/uri".
Default: disable.

cache.debug
writes mod_cache debuging messages to error.log or not

Default: disable.

cache.purge-host
pcre regex hosts ip which are allowed to PURGE cache file

e.g.: ::
cache.purge-host = "^(192\.168\.|222\.120\.35\.)" # Allow PURGE from 192.168/16 and 222.120.35/24, plus hardcoded 10/8 and 127.0.0.1
Default: not set (10/8 and 127.0.0.1 are hardcoded to ip lists which allow to PURGE)

cache.ignore-hostname
don't include hostname in cache saving filename

Default: disable.

cache.refresh-pattern
arrays of "url_pcre_regex" => "minutes options". Zero minute means cache forever. multi options are allowed.

refresh-pattern options are: 
    * ignore-reload: do not update cache when browser sends 'Cache-Control: no-cache' header.
    * update-on-refresh: update cache when browser sends 'Cache-Control: no-cache' header. 
    * override-expire: ignore backend's 'Expire' header while determining whether to cache. 
    * ignore-cache-control-header: ignore backend's 'Cache-Control' headers while determining whether to cache. 
    * no-expire-header: do not set expires header on matched uri. without this options mod_cache set expire header based refresh-pattern rule. 
    * fetchall-for-range-request: download all content of file if browser sends 'Range: xxx-yyybytes' header. it is useful for multi-thread downloaders(such as flashget). 
    * nocache: do not cache matched url.

Examples ========

example for lighttpd 1.4.x series

e.g.: ::
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)(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, otherwise mod_proxy will not cooperate with mod-cache
proxy.worked-with-mod-cache = "enable"

example for lighttpd 1.5.0

e.g.: ::
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)(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, otherwise mod_proxy_core will not cooperate with mod-cache
proxy-core.worked-with-modcache = "enable"

}}}

Updated by moo over 17 years ago · 3 revisions