2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
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>Experimental</status>
27 <sourcefile>mod_cache.c</sourcefile>
28 <identifier>cache_module</identifier>
32 This module is experimental. Documentation is still under development...
35 <p><module>mod_cache</module> implements an <a
36 href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant HTTP
37 content cache that can be used to cache either local or proxied content.
38 <module>mod_cache</module> requires the services of one or more storage
39 management modules. Two storage management modules are included in
40 the base Apache distribution:</p>
42 <dt><module>mod_disk_cache</module></dt>
43 <dd>implements a disk based storage manager.</dd>
45 <dt><module>mod_mem_cache</module></dt>
46 <dd>implements a memory based storage manager.
47 <module>mod_mem_cache</module> can be configured to operate in two
48 modes: caching open file descriptors or caching objects in heap storage.
49 <module>mod_mem_cache</module> can be used to cache locally generated content
50 or to cache backend server content for <module>mod_proxy</module> when
51 configured using <directive module="mod_proxy">ProxyPass</directive>
52 (aka <dfn>reverse proxy</dfn>)</dd>
55 <p>Content is stored in and retrieved from the cache using URI based keys. Content with
56 access protection is not cached.</p>
59 <section id="related"><title>Related Modules and Directives</title>
62 <module>mod_disk_cache</module>
63 <module>mod_mem_cache</module>
66 <directive module="mod_disk_cache">CacheRoot</directive>
67 <directive module="mod_disk_cache">CacheSize</directive>
68 <directive module="mod_disk_cache">CacheGcInterval</directive>
69 <directive module="mod_disk_cache">CacheDirLevels</directive>
70 <directive module="mod_disk_cache">CacheDirLength</directive>
71 <directive module="mod_disk_cache">CacheExpiryCheck</directive>
72 <directive module="mod_disk_cache">CacheMinFileSize</directive>
73 <directive module="mod_disk_cache">CacheMaxFileSize</directive>
74 <directive module="mod_disk_cache">CacheTimeMargin</directive>
75 <directive module="mod_disk_cache">CacheGcDaily</directive>
76 <directive module="mod_disk_cache">CacheGcUnused</directive>
77 <directive module="mod_disk_cache">CacheGcClean</directive>
78 <directive module="mod_disk_cache">CacheGcMemUsage</directive>
79 <directive module="mod_mem_cache">MCacheSize</directive>
80 <directive module="mod_mem_cache">MCacheMaxObjectCount</directive>
81 <directive module="mod_mem_cache">MCacheMinObjectSize</directive>
82 <directive module="mod_mem_cache">MCacheMaxObjectSize</directive>
83 <directive module="mod_mem_cache">MCacheRemovalAlgorithm</directive>
84 <directive module="mod_mem_cache">MCacheMaxStreamingBuffer</directive>
89 <section id="sampleconf"><title>Sample Configuration</title>
90 <example><title>Sample httpd.conf</title>
92 # Sample Cache Configuration<br />
94 LoadModule cache_module modules/mod_cache.so<br />
96 <IfModule mod_cache.c><br />
98 #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
99 # If you want to use mod_disk_cache instead of mod_mem_cache,
100 # uncomment the line above and comment out the LoadModule line below.
101 <IfModule mod_disk_cache.c><br />
103 CacheRoot c:/cacheroot<br />
105 CacheEnable disk /<br />
106 CacheDirLevels 5<br />
107 CacheDirLength 3<br />
109 </IfModule> <br />
111 LoadModule mem_cache_module modules/mod_mem_cache.so<br />
112 <IfModule mod_mem_cache.c><br />
114 CacheEnable mem /<br />
115 MCacheSize 4096<br />
116 MCacheMaxObjectCount 100<br />
117 MCacheMinObjectSize 1<br />
118 MCacheMaxObjectSize 2048<br />
120 </IfModule><br />
127 <name>CacheEnable</name>
128 <description>Enable caching of specified URLs using a specified storage
129 manager</description>
130 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
131 <contextlist><context>server config</context><context>virtual host</context>
135 <p>The <directive>CacheEnable</directive> directive instructs
136 <module>mod_cache</module> to cache urls at or below
137 <var>url-string</var>. The cache storage manager is specified with the
138 <var>cache_type</var> argument. <var>cache_type</var> <code> mem</code>
139 instructs <module>mod_cache</module> to use the memory based storage
140 manager implemented by <module>mod_mem_cache</module>.
141 <var>cache_type</var> <code>disk</code> instructs
142 <module>mod_cache</module> to use the disk based storage manager
143 implemented by <module>mod_disk_cache</module>.
144 <var>cache_type</var> <code>fd</code> instructs
145 <module>mod_cache</module> to use the file descriptor cache implemented
146 by <module>mod_mem_cache</module>.</p>
147 <p>In the event that the URL space overlaps between different
148 <directive>CacheEnable</directive> directives (as in the example below),
149 each possible storage manager will be run until the first one that
150 actually processes the request. The order in which the storage managers are
151 run is determined by the order of the <directive>CacheEnable</directive>
152 directives in the configuration file.</p>
155 CacheEnable mem /manual<br />
156 CacheEnable fd /images<br />
157 CacheEnable disk /<br />
163 <name>CacheDisable</name>
164 <description>Disable caching of specified URLs</description>
165 <syntax>CacheDisable <var> url-string</var></syntax>
166 <contextlist><context>server config</context><context>virtual host</context>
170 <p>The <directive>CacheDisable</directive> directive instructs
171 <module>mod_cache</module> to <em>not</em> cache urls at or below
172 <var>url-string</var>.</p>
174 <example><title>Example</title>
175 CacheDisable /local_files
181 <name>CacheMaxExpire</name>
182 <description>The maximum time in seconds to cache a document</description>
183 <syntax>CacheMaxExpire <var>seconds</var></syntax>
184 <default>CacheMaxExpire 86400 (one day)</default>
185 <contextlist><context>server config</context><context>virtual host</context>
189 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
190 seconds for which cachable HTTP documents will be retained without checking the origin
191 server. Thus, documents will be out of date at most this number of seconds. This maximum
192 value is enforced even if an expiry date was supplied with the document.</p>
195 CacheMaxExpire 604800
201 <name>CacheDefaultExpire</name>
202 <description>The default duration to cache a document when no expiry date is specified.</description>
203 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
204 <default>CacheDefaultExpire 3600 (one hour)</default>
205 <contextlist><context>server config</context><context>virtual host</context>
209 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
210 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
211 with the document. The value specified with the <directive>CacheMaxExpire</directive>
212 directive does <em>not</em> override this setting.</p>
215 CacheDefaultExpire 86400
221 <name>CacheIgnoreNoLastMod</name>
222 <description>Ignore the fact that a response has no Last Modified
223 header.</description>
224 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
225 <default>CacheIgnoreNoLastMod Off</default>
226 <contextlist><context>server config</context><context>virtual host</context>
230 <p>Ordinarily, documents without a last-modified date are not cached.
231 Under some circumstances the last-modified date is removed (during
232 <module>mod_include</module> processing for example) or not provided
233 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
234 provides a way to specify that documents without last-modified dates
235 should be considered for caching, even without a last-modified date.
236 If neither a last-modified date nor an expiry date are provided with
237 the document then the value specified by the
238 <directive>CacheDefaultExpire</directive> directive will be used to
239 generate an expiration date.</p>
242 CacheIgnoreNoLastMod On
248 <name>CacheIgnoreCacheControl</name>
249 <description>Ignore the fact that the client requested the content not be
250 cached.</description>
251 <syntax>CacheIgnoreCacheControl On|Off</syntax>
252 <default>CacheIgnoreCacheControl Off</default>
253 <contextlist><context>server config</context><context>virtual host</context>
257 <p>Ordinarily, documents with no-cache or no-store header values will not be stored in the cache.
258 The <directive>CacheIgnoreCacheControl</directive> directive allows this behavior to be overridden.
259 <directive>CacheIgnoreCacheControl</directive> On tells the server to attempt to cache the document
260 even if it contains no-cache or no-store header values. Documents requiring authorization will
261 <em>never</em> be cached.</p>
264 CacheIgnoreCacheControl On
270 <name>CacheLastModifiedFactor</name>
271 <description>The factor used to compute an expiry date based on the
272 LastModified date.</description>
273 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
274 <default>CacheLastModifiedFactor 0.1</default>
275 <contextlist><context>server config</context><context>virtual host</context>
279 <p>In the event that a document does not provide an expiry date but does
280 provide a last-modified date, an expiry date can be calculated based on
281 the time since the document was last modified. The
282 <directive>CacheLastModifiedFactor</directive> directive specifies a
283 <var>factor</var> to be used in the generation of this expiry date
284 according to the following formula:
286 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
287 expiry-date = current-date + expiry-period</code>
289 For example, if the document was last modified 10 hours ago, and
290 <var>factor</var> is 0.1 then the expiry-period will be set to
291 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
292 expiry-date would be 3:00pm + 1hour = 4:00pm.
294 If the expiry-period would be longer than that set by
295 <directive>CacheMaxExpire</directive>, then the latter takes
299 CacheLastModifiedFactor 0.5
305 <name>CacheForceCompletion</name>
306 <description>Percentage of document served, after which the server
307 will complete caching the file even if the request is cancelled.</description>
308 <syntax>CacheForceCompletion <var>Percentage</var></syntax>
309 <default>CacheForceCompletion 60</default>
310 <contextlist><context>server config</context><context>virtual host</context>
314 <p>Ordinarily, if a request is cancelled while the response is being
315 cached and delivered to the client the processing of the response will
316 stop and the cache entry will be removed. The
317 <directive>CacheForceCompletion</directive> directive specifies a
318 threshold beyond which the document will continue to be cached to
319 completion, even if the request is cancelled.</p>
321 <p>The threshold is a percentage specified as a value between
322 <code>1</code> and <code>100</code>. A value of <code>0</code>
323 specifies that the default be used. A value of <code>100</code>
324 will only cache documents that are served in their entirety. A value
325 between 60 and 90 is recommended.</p>
328 CacheForceCompletion 80
331 <note type="warning"><title>Note:</title>
332 This feature is currently <em>not</em> implemented.
338 <name>CacheIgnoreHeaders</name>
339 <description>Do not store the given HTTP header(s) in the cache.
341 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
342 <default>CacheIgnoreHeaders None</default>
343 <contextlist><context>server config</context><context>virtual host</context>
347 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
348 the cache. The following HTTP headers are hop-by-hop headers and thus
349 do not get stored in the cache in <em>any</em> case regardless of the
350 setting of <directive>CacheIgnoreHeaders</directive>:</p>
353 <li><code>Connection</code></li>
354 <li><code>Keep-Alive</code></li>
355 <li><code>Proxy-Authenticate</code></li>
356 <li><code>Proxy-Authorization</code></li>
357 <li><code>TE</code></li>
358 <li><code>Trailers</code></li>
359 <li><code>Transfer-Encoding</code></li>
360 <li><code>Upgrade</code></li>
363 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
364 headers that should not to be stored in the cache. For example, it makes
365 sense in some cases to prevent cookies from being stored in the cache.</p>
367 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
368 of HTTP headers that should not be stored in the cache. If only hop-by-hop
369 headers not should be stored in the cache (the RFC 2616 compliant
370 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
371 <code>None</code>.</p>
373 <example><title>Example 1</title>
374 CacheIgnoreHeaders Set-Cookie
377 <example><title>Example 2</title>
378 CacheIgnoreHeaders None
381 <note type="warning"><title>Warning:</title>
382 If headers like <code>Expires</code> which are needed for proper cache
383 management are not stored due to a
384 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
385 mod_cache is undefined.