2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Copyright 2002-2004 The Apache Software Foundation
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
13 http://www.apache.org/licenses/LICENSE-2.0
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
22 <modulesynopsis metafile="mod_cache.xml.meta">
24 <name>mod_cache</name>
25 <description>Content cache keyed to URIs.</description>
26 <status>Extension</status>
27 <sourcefile>mod_cache.c</sourcefile>
28 <identifier>cache_module</identifier>
31 <p><module>mod_cache</module> implements an <a
32 href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant HTTP
33 content cache that can be used to cache either local or proxied content.
34 <module>mod_cache</module> requires the services of one or more storage
35 management modules. Two storage management modules are included in
36 the base Apache distribution:</p>
38 <dt><module>mod_disk_cache</module></dt>
39 <dd>implements a disk based storage manager.</dd>
41 <dt><module>mod_mem_cache</module></dt>
42 <dd>implements a memory based storage manager.
43 <module>mod_mem_cache</module> can be configured to operate in two
44 modes: caching open file descriptors or caching objects in heap storage.
45 <module>mod_mem_cache</module> can be used to cache locally generated content
46 or to cache backend server content for <module>mod_proxy</module> when
47 configured using <directive module="mod_proxy">ProxyPass</directive>
48 (aka <dfn>reverse proxy</dfn>)</dd>
51 <p>Content is stored in and retrieved from the cache using URI based keys. Content with
52 access protection is not cached.</p>
55 <section id="related"><title>Related Modules and Directives</title>
58 <module>mod_disk_cache</module>
59 <module>mod_mem_cache</module>
62 <directive module="mod_disk_cache">CacheRoot</directive>
63 <directive module="mod_disk_cache">CacheSize</directive>
64 <directive module="mod_disk_cache">CacheDirLevels</directive>
65 <directive module="mod_disk_cache">CacheDirLength</directive>
66 <directive module="mod_disk_cache">CacheMinFileSize</directive>
67 <directive module="mod_disk_cache">CacheMaxFileSize</directive>
68 <directive module="mod_mem_cache">MCacheSize</directive>
69 <directive module="mod_mem_cache">MCacheMaxObjectCount</directive>
70 <directive module="mod_mem_cache">MCacheMinObjectSize</directive>
71 <directive module="mod_mem_cache">MCacheMaxObjectSize</directive>
72 <directive module="mod_mem_cache">MCacheRemovalAlgorithm</directive>
73 <directive module="mod_mem_cache">MCacheMaxStreamingBuffer</directive>
78 <section id="sampleconf"><title>Sample Configuration</title>
79 <example><title>Sample httpd.conf</title>
81 # Sample Cache Configuration<br />
83 LoadModule cache_module modules/mod_cache.so<br />
85 <IfModule mod_cache.c><br />
87 #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
88 # If you want to use mod_disk_cache instead of mod_mem_cache,
89 # uncomment the line above and comment out the LoadModule line below.
90 <IfModule mod_disk_cache.c><br />
92 CacheRoot c:/cacheroot<br />
93 CacheEnable disk /<br />
94 CacheDirLevels 5<br />
95 CacheDirLength 3<br />
97 </IfModule> <br />
99 LoadModule mem_cache_module modules/mod_mem_cache.so<br />
100 <IfModule mod_mem_cache.c><br />
102 CacheEnable mem /<br />
103 MCacheSize 4096<br />
104 MCacheMaxObjectCount 100<br />
105 MCacheMinObjectSize 1<br />
106 MCacheMaxObjectSize 2048<br />
108 </IfModule><br />
115 <name>CacheEnable</name>
116 <description>Enable caching of specified URLs using a specified storage
117 manager</description>
118 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
119 <contextlist><context>server config</context><context>virtual host</context>
123 <p>The <directive>CacheEnable</directive> directive instructs
124 <module>mod_cache</module> to cache urls at or below
125 <var>url-string</var>. The cache storage manager is specified with the
126 <var>cache_type</var> argument. <var>cache_type</var> <code> mem</code>
127 instructs <module>mod_cache</module> to use the memory based storage
128 manager implemented by <module>mod_mem_cache</module>.
129 <var>cache_type</var> <code>disk</code> instructs
130 <module>mod_cache</module> to use the disk based storage manager
131 implemented by <module>mod_disk_cache</module>.
132 <var>cache_type</var> <code>fd</code> instructs
133 <module>mod_cache</module> to use the file descriptor cache implemented
134 by <module>mod_mem_cache</module>.</p>
135 <p>In the event that the URL space overlaps between different
136 <directive>CacheEnable</directive> directives (as in the example below),
137 each possible storage manager will be run until the first one that
138 actually processes the request. The order in which the storage managers are
139 run is determined by the order of the <directive>CacheEnable</directive>
140 directives in the configuration file.</p>
143 CacheEnable mem /manual<br />
144 CacheEnable fd /images<br />
145 CacheEnable disk /<br />
151 <name>CacheDisable</name>
152 <description>Disable caching of specified URLs</description>
153 <syntax>CacheDisable <var> url-string</var></syntax>
154 <contextlist><context>server config</context><context>virtual host</context>
158 <p>The <directive>CacheDisable</directive> directive instructs
159 <module>mod_cache</module> to <em>not</em> cache urls at or below
160 <var>url-string</var>.</p>
162 <example><title>Example</title>
163 CacheDisable /local_files
169 <name>CacheMaxExpire</name>
170 <description>The maximum time in seconds to cache a document</description>
171 <syntax>CacheMaxExpire <var>seconds</var></syntax>
172 <default>CacheMaxExpire 86400 (one day)</default>
173 <contextlist><context>server config</context><context>virtual host</context>
177 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
178 seconds for which cachable HTTP documents will be retained without checking the origin
179 server. Thus, documents will be out of date at most this number of seconds. This maximum
180 value is enforced even if an expiry date was supplied with the document.</p>
183 CacheMaxExpire 604800
189 <name>CacheDefaultExpire</name>
190 <description>The default duration to cache a document when no expiry date is specified.</description>
191 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
192 <default>CacheDefaultExpire 3600 (one hour)</default>
193 <contextlist><context>server config</context><context>virtual host</context>
197 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
198 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
199 with the document. The value specified with the <directive>CacheMaxExpire</directive>
200 directive does <em>not</em> override this setting.</p>
203 CacheDefaultExpire 86400
209 <name>CacheIgnoreNoLastMod</name>
210 <description>Ignore the fact that a response has no Last Modified
211 header.</description>
212 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
213 <default>CacheIgnoreNoLastMod Off</default>
214 <contextlist><context>server config</context><context>virtual host</context>
218 <p>Ordinarily, documents without a last-modified date are not cached.
219 Under some circumstances the last-modified date is removed (during
220 <module>mod_include</module> processing for example) or not provided
221 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
222 provides a way to specify that documents without last-modified dates
223 should be considered for caching, even without a last-modified date.
224 If neither a last-modified date nor an expiry date are provided with
225 the document then the value specified by the
226 <directive>CacheDefaultExpire</directive> directive will be used to
227 generate an expiration date.</p>
230 CacheIgnoreNoLastMod On
236 <name>CacheIgnoreCacheControl</name>
237 <description>Ignore the fact that the client requested the content not be
238 cached.</description>
239 <syntax>CacheIgnoreCacheControl On|Off</syntax>
240 <default>CacheIgnoreCacheControl Off</default>
241 <contextlist><context>server config</context><context>virtual host</context>
245 <p>Ordinarily, documents with no-cache or no-store header values will not be stored in the cache.
246 The <directive>CacheIgnoreCacheControl</directive> directive allows this behavior to be overridden.
247 <directive>CacheIgnoreCacheControl</directive> On tells the server to attempt to cache the document
248 even if it contains no-cache or no-store header values. Documents requiring authorization will
249 <em>never</em> be cached.</p>
252 CacheIgnoreCacheControl On
258 <name>CacheLastModifiedFactor</name>
259 <description>The factor used to compute an expiry date based on the
260 LastModified date.</description>
261 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
262 <default>CacheLastModifiedFactor 0.1</default>
263 <contextlist><context>server config</context><context>virtual host</context>
267 <p>In the event that a document does not provide an expiry date but does
268 provide a last-modified date, an expiry date can be calculated based on
269 the time since the document was last modified. The
270 <directive>CacheLastModifiedFactor</directive> directive specifies a
271 <var>factor</var> to be used in the generation of this expiry date
272 according to the following formula:
274 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
275 expiry-date = current-date + expiry-period</code>
277 For example, if the document was last modified 10 hours ago, and
278 <var>factor</var> is 0.1 then the expiry-period will be set to
279 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
280 expiry-date would be 3:00pm + 1hour = 4:00pm.
282 If the expiry-period would be longer than that set by
283 <directive>CacheMaxExpire</directive>, then the latter takes
287 CacheLastModifiedFactor 0.5
293 <name>CacheForceCompletion</name>
294 <description>Percentage of document served, after which the server
295 will complete caching the file even if the request is cancelled.</description>
296 <syntax>CacheForceCompletion <var>Percentage</var></syntax>
297 <default>CacheForceCompletion 60</default>
298 <contextlist><context>server config</context><context>virtual host</context>
302 <p>Ordinarily, if a request is cancelled while the response is being
303 cached and delivered to the client the processing of the response will
304 stop and the cache entry will be removed. The
305 <directive>CacheForceCompletion</directive> directive specifies a
306 threshold beyond which the document will continue to be cached to
307 completion, even if the request is cancelled.</p>
309 <p>The threshold is a percentage specified as a value between
310 <code>1</code> and <code>100</code>. A value of <code>0</code>
311 specifies that the default be used. A value of <code>100</code>
312 will only cache documents that are served in their entirety. A value
313 between 60 and 90 is recommended.</p>
316 CacheForceCompletion 80
319 <note type="warning"><title>Note:</title>
320 This feature is currently <em>not</em> implemented.
326 <name>CacheIgnoreHeaders</name>
327 <description>Do not store the given HTTP header(s) in the cache.
329 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
330 <default>CacheIgnoreHeaders None</default>
331 <contextlist><context>server config</context><context>virtual host</context>
335 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
336 the cache. The following HTTP headers are hop-by-hop headers and thus
337 do not get stored in the cache in <em>any</em> case regardless of the
338 setting of <directive>CacheIgnoreHeaders</directive>:</p>
341 <li><code>Connection</code></li>
342 <li><code>Keep-Alive</code></li>
343 <li><code>Proxy-Authenticate</code></li>
344 <li><code>Proxy-Authorization</code></li>
345 <li><code>TE</code></li>
346 <li><code>Trailers</code></li>
347 <li><code>Transfer-Encoding</code></li>
348 <li><code>Upgrade</code></li>
351 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
352 headers that should not to be stored in the cache. For example, it makes
353 sense in some cases to prevent cookies from being stored in the cache.</p>
355 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
356 of HTTP headers that should not be stored in the cache. If only hop-by-hop
357 headers not should be stored in the cache (the RFC 2616 compliant
358 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
359 <code>None</code>.</p>
361 <example><title>Example 1</title>
362 CacheIgnoreHeaders Set-Cookie
365 <example><title>Example 2</title>
366 CacheIgnoreHeaders None
369 <note type="warning"><title>Warning:</title>
370 If headers like <code>Expires</code> which are needed for proper cache
371 management are not stored due to a
372 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
373 mod_cache is undefined.