2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Copyright 2002-2005 The Apache Software Foundation or its licensors,
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_cache.xml.meta">
25 <name>mod_cache</name>
26 <description>Content cache keyed to URIs.</description>
27 <status>Extension</status>
28 <sourcefile>mod_cache.c</sourcefile>
29 <identifier>cache_module</identifier>
32 <p><module>mod_cache</module> implements an <a
33 href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant HTTP
34 content cache that can be used to cache either local or proxied content.
35 <module>mod_cache</module> requires the services of one or more storage
36 management modules. Two storage management modules are included in
37 the base Apache distribution:</p>
39 <dt><module>mod_disk_cache</module></dt>
40 <dd>implements a disk based storage manager.</dd>
42 <dt><module>mod_mem_cache</module></dt>
43 <dd>implements a memory based storage manager.
44 <module>mod_mem_cache</module> can be configured to operate in two
45 modes: caching open file descriptors or caching objects in heap storage.
46 <module>mod_mem_cache</module> can be used to cache locally generated content
47 or to cache backend server content for <module>mod_proxy</module> when
48 configured using <directive module="mod_proxy">ProxyPass</directive>
49 (aka <dfn>reverse proxy</dfn>)</dd>
52 <p>Content is stored in and retrieved from the cache using URI based keys. Content with
53 access protection is not cached.</p>
56 <section id="related"><title>Related Modules and Directives</title>
59 <module>mod_disk_cache</module>
60 <module>mod_mem_cache</module>
63 <directive module="mod_disk_cache">CacheRoot</directive>
64 <directive module="mod_disk_cache">CacheSize</directive>
65 <directive module="mod_disk_cache">CacheDirLevels</directive>
66 <directive module="mod_disk_cache">CacheDirLength</directive>
67 <directive module="mod_disk_cache">CacheMinFileSize</directive>
68 <directive module="mod_disk_cache">CacheMaxFileSize</directive>
69 <directive module="mod_mem_cache">MCacheSize</directive>
70 <directive module="mod_mem_cache">MCacheMaxObjectCount</directive>
71 <directive module="mod_mem_cache">MCacheMinObjectSize</directive>
72 <directive module="mod_mem_cache">MCacheMaxObjectSize</directive>
73 <directive module="mod_mem_cache">MCacheRemovalAlgorithm</directive>
74 <directive module="mod_mem_cache">MCacheMaxStreamingBuffer</directive>
79 <section id="sampleconf"><title>Sample Configuration</title>
80 <example><title>Sample httpd.conf</title>
82 # Sample Cache Configuration<br />
84 LoadModule cache_module modules/mod_cache.so<br />
86 <IfModule mod_cache.c><br />
88 #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
89 # If you want to use mod_disk_cache instead of mod_mem_cache,
90 # uncomment the line above and comment out the LoadModule line below.
91 <IfModule mod_disk_cache.c><br />
93 CacheRoot c:/cacheroot<br />
94 CacheEnable disk /<br />
95 CacheDirLevels 5<br />
96 CacheDirLength 3<br />
98 </IfModule> <br />
100 LoadModule mem_cache_module modules/mod_mem_cache.so<br />
101 <IfModule mod_mem_cache.c><br />
103 CacheEnable mem /<br />
104 MCacheSize 4096<br />
105 MCacheMaxObjectCount 100<br />
106 MCacheMinObjectSize 1<br />
107 MCacheMaxObjectSize 2048<br />
109 </IfModule><br />
116 <name>CacheEnable</name>
117 <description>Enable caching of specified URLs using a specified storage
118 manager</description>
119 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
120 <contextlist><context>server config</context><context>virtual host</context>
124 <p>The <directive>CacheEnable</directive> directive instructs
125 <module>mod_cache</module> to cache urls at or below
126 <var>url-string</var>. The cache storage manager is specified with the
127 <var>cache_type</var> argument. <var>cache_type</var> <code> mem</code>
128 instructs <module>mod_cache</module> to use the memory based storage
129 manager implemented by <module>mod_mem_cache</module>.
130 <var>cache_type</var> <code>disk</code> instructs
131 <module>mod_cache</module> to use the disk based storage manager
132 implemented by <module>mod_disk_cache</module>.
133 <var>cache_type</var> <code>fd</code> instructs
134 <module>mod_cache</module> to use the file descriptor cache implemented
135 by <module>mod_mem_cache</module>.</p>
136 <p>In the event that the URL space overlaps between different
137 <directive>CacheEnable</directive> directives (as in the example below),
138 each possible storage manager will be run until the first one that
139 actually processes the request. The order in which the storage managers are
140 run is determined by the order of the <directive>CacheEnable</directive>
141 directives in the configuration file.</p>
144 CacheEnable mem /manual<br />
145 CacheEnable fd /images<br />
146 CacheEnable disk /<br />
152 <name>CacheDisable</name>
153 <description>Disable caching of specified URLs</description>
154 <syntax>CacheDisable <var> url-string</var></syntax>
155 <contextlist><context>server config</context><context>virtual host</context>
159 <p>The <directive>CacheDisable</directive> directive instructs
160 <module>mod_cache</module> to <em>not</em> cache urls at or below
161 <var>url-string</var>.</p>
163 <example><title>Example</title>
164 CacheDisable /local_files
170 <name>CacheMaxExpire</name>
171 <description>The maximum time in seconds to cache a document</description>
172 <syntax>CacheMaxExpire <var>seconds</var></syntax>
173 <default>CacheMaxExpire 86400 (one day)</default>
174 <contextlist><context>server config</context><context>virtual host</context>
178 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
179 seconds for which cachable HTTP documents will be retained without checking the origin
180 server. Thus, documents will be out of date at most this number of seconds. This maximum
181 value is enforced even if an expiry date was supplied with the document.</p>
184 CacheMaxExpire 604800
190 <name>CacheDefaultExpire</name>
191 <description>The default duration to cache a document when no expiry date is specified.</description>
192 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
193 <default>CacheDefaultExpire 3600 (one hour)</default>
194 <contextlist><context>server config</context><context>virtual host</context>
198 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
199 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
200 with the document. The value specified with the <directive>CacheMaxExpire</directive>
201 directive does <em>not</em> override this setting.</p>
204 CacheDefaultExpire 86400
210 <name>CacheIgnoreNoLastMod</name>
211 <description>Ignore the fact that a response has no Last Modified
212 header.</description>
213 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
214 <default>CacheIgnoreNoLastMod Off</default>
215 <contextlist><context>server config</context><context>virtual host</context>
219 <p>Ordinarily, documents without a last-modified date are not cached.
220 Under some circumstances the last-modified date is removed (during
221 <module>mod_include</module> processing for example) or not provided
222 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
223 provides a way to specify that documents without last-modified dates
224 should be considered for caching, even without a last-modified date.
225 If neither a last-modified date nor an expiry date are provided with
226 the document then the value specified by the
227 <directive>CacheDefaultExpire</directive> directive will be used to
228 generate an expiration date.</p>
231 CacheIgnoreNoLastMod On
237 <name>CacheIgnoreCacheControl</name>
238 <description>Ignore the fact that the client requested the content not be
239 cached.</description>
240 <syntax>CacheIgnoreCacheControl On|Off</syntax>
241 <default>CacheIgnoreCacheControl Off</default>
242 <contextlist><context>server config</context><context>virtual host</context>
246 <p>Ordinarily, documents with no-cache or no-store header values will not be stored in the cache.
247 The <directive>CacheIgnoreCacheControl</directive> directive allows this behavior to be overridden.
248 <directive>CacheIgnoreCacheControl</directive> On tells the server to attempt to cache the document
249 even if it contains no-cache or no-store header values. Documents requiring authorization will
250 <em>never</em> be cached.</p>
253 CacheIgnoreCacheControl On
259 <name>CacheLastModifiedFactor</name>
260 <description>The factor used to compute an expiry date based on the
261 LastModified date.</description>
262 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
263 <default>CacheLastModifiedFactor 0.1</default>
264 <contextlist><context>server config</context><context>virtual host</context>
268 <p>In the event that a document does not provide an expiry date but does
269 provide a last-modified date, an expiry date can be calculated based on
270 the time since the document was last modified. The
271 <directive>CacheLastModifiedFactor</directive> directive specifies a
272 <var>factor</var> to be used in the generation of this expiry date
273 according to the following formula:
275 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
276 expiry-date = current-date + expiry-period</code>
278 For example, if the document was last modified 10 hours ago, and
279 <var>factor</var> is 0.1 then the expiry-period will be set to
280 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
281 expiry-date would be 3:00pm + 1hour = 4:00pm.
283 If the expiry-period would be longer than that set by
284 <directive>CacheMaxExpire</directive>, then the latter takes
288 CacheLastModifiedFactor 0.5
294 <name>CacheIgnoreHeaders</name>
295 <description>Do not store the given HTTP header(s) in the cache.
297 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
298 <default>CacheIgnoreHeaders None</default>
299 <contextlist><context>server config</context><context>virtual host</context>
303 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
304 the cache. The following HTTP headers are hop-by-hop headers and thus
305 do not get stored in the cache in <em>any</em> case regardless of the
306 setting of <directive>CacheIgnoreHeaders</directive>:</p>
309 <li><code>Connection</code></li>
310 <li><code>Keep-Alive</code></li>
311 <li><code>Proxy-Authenticate</code></li>
312 <li><code>Proxy-Authorization</code></li>
313 <li><code>TE</code></li>
314 <li><code>Trailers</code></li>
315 <li><code>Transfer-Encoding</code></li>
316 <li><code>Upgrade</code></li>
319 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
320 headers that should not to be stored in the cache. For example, it makes
321 sense in some cases to prevent cookies from being stored in the cache.</p>
323 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
324 of HTTP headers that should not be stored in the cache. If only hop-by-hop
325 headers not should be stored in the cache (the RFC 2616 compliant
326 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
327 <code>None</code>.</p>
329 <example><title>Example 1</title>
330 CacheIgnoreHeaders Set-Cookie
333 <example><title>Example 2</title>
334 CacheIgnoreHeaders None
337 <note type="warning"><title>Warning:</title>
338 If headers like <code>Expires</code> which are needed for proper cache
339 management are not stored due to a
340 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
341 mod_cache is undefined.