]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_cache.xml
Adding updated mod_ssl HOWTO to the website
[apache] / docs / manual / mod / mod_cache.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Copyright 2002-2005 The Apache Software Foundation or its licensors, as
8  applicable.
9
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_cache.xml.meta">
24
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>
30
31 <summary>
32     <note type="warning">This module should be used with care and
33     can be used to circumvent <directive 
34     module="mod_authz_host">Allow</directive> and <directive 
35     module="mod_authz_host">Deny</directive> directives. You 
36     should not enable caching for any content to which you wish
37     to limit access by client host name, address or environment
38     variable.</note>  
39
40     <p><module>mod_cache</module> implements an <a
41     href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant HTTP
42     content cache that can be used to cache either local or proxied content.
43     <module>mod_cache</module> requires the services of one or more storage
44     management modules. Two storage management modules are included in
45     the base Apache distribution:</p>
46     <dl>
47     <dt><module>mod_disk_cache</module></dt>
48     <dd>implements a disk based storage manager.</dd>
49
50     <dt><module>mod_mem_cache</module></dt>
51     <dd>implements a memory based storage manager. 
52     <module>mod_mem_cache</module> can be configured to operate in two
53     modes: caching open file descriptors or caching objects in heap storage.
54     <module>mod_mem_cache</module> can be used to cache locally generated content
55     or to cache backend server content for <module>mod_proxy</module> when
56     configured using <directive module="mod_proxy">ProxyPass</directive>
57     (aka <dfn>reverse proxy</dfn>)</dd>
58     </dl>
59
60     <p>Content is stored in and retrieved from the cache using URI based keys. Content with
61     access protection is not cached.</p>
62 </summary>
63
64 <section id="related"><title>Related Modules and Directives</title>
65     <related>
66       <modulelist>
67         <module>mod_disk_cache</module>
68         <module>mod_mem_cache</module>
69       </modulelist>
70       <directivelist>
71         <directive module="mod_disk_cache">CacheRoot</directive>
72         <directive module="mod_disk_cache">CacheSize</directive>
73         <directive module="mod_disk_cache">CacheDirLevels</directive>
74         <directive module="mod_disk_cache">CacheDirLength</directive>
75         <directive module="mod_disk_cache">CacheMinFileSize</directive>
76         <directive module="mod_disk_cache">CacheMaxFileSize</directive>
77         <directive module="mod_mem_cache">MCacheSize</directive>
78         <directive module="mod_mem_cache">MCacheMaxObjectCount</directive>
79         <directive module="mod_mem_cache">MCacheMinObjectSize</directive>
80         <directive module="mod_mem_cache">MCacheMaxObjectSize</directive>
81         <directive module="mod_mem_cache">MCacheRemovalAlgorithm</directive>
82         <directive module="mod_mem_cache">MCacheMaxStreamingBuffer</directive>
83       </directivelist>
84     </related>
85 </section>
86
87 <section id="sampleconf"><title>Sample Configuration</title>
88     <example><title>Sample httpd.conf</title>
89       #<br />
90       # Sample Cache Configuration<br />
91       #<br />
92       LoadModule cache_module modules/mod_cache.so<br />
93       <br />
94       &lt;IfModule mod_cache.c&gt;<br />
95       <indent>
96         #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
97         # If you want to use mod_disk_cache instead of mod_mem_cache,<br />
98         # uncomment the line above and comment out the LoadModule line below.<br />
99         &lt;IfModule mod_disk_cache.c&gt;<br />
100         <indent>
101           CacheRoot c:/cacheroot<br />
102           CacheEnable disk  /<br />
103           CacheDirLevels 5<br />
104           CacheDirLength 3<br />
105         </indent>
106         &lt;/IfModule&gt; <br />
107         <br />
108         LoadModule mem_cache_module modules/mod_mem_cache.so<br />
109         &lt;IfModule mod_mem_cache.c&gt;<br />
110         <indent>
111           CacheEnable mem  /<br />
112           MCacheSize 4096<br />
113           MCacheMaxObjectCount 100<br />
114           MCacheMinObjectSize 1<br />
115           MCacheMaxObjectSize 2048<br />
116         </indent>
117         &lt;/IfModule&gt;<br />
118         <br />
119         # When acting as a proxy, don't cache the list of security updates<br />
120         CacheDisable http://security.update.server/update-list/<br />
121       </indent>
122       &lt;/IfModule&gt;
123     </example>
124 </section>
125
126 <directivesynopsis>
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>
132 </contextlist>
133
134 <usage>
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>
153
154     <example>
155       CacheEnable  mem   /manual<br />
156       CacheEnable  fd    /images<br />
157       CacheEnable  disk  /<br />
158     </example>
159
160     <p>When acting as a forward proxy server, <var>url-string</var> can
161     also be used to specify remote sites and proxy protocols which 
162     caching should be enabled for.</p>
163  
164     <example>
165       # Cache proxied url's<br />
166       CacheEnable  disk  /<br /><br />
167       # Cache FTP-proxied url's<br />
168       CacheEnable  disk  ftp://<br /><br />
169       # Cache content from www.apache.org<br />
170       CacheEnable  disk  http://www.apache.org/<br />
171     </example>
172
173 </usage>
174 </directivesynopsis>
175
176 <directivesynopsis>
177 <name>CacheDisable</name>
178 <description>Disable caching of specified URLs</description>
179 <syntax>CacheDisable <var> url-string</var></syntax>
180 <contextlist><context>server config</context><context>virtual host</context>
181 </contextlist>
182
183 <usage>
184     <p>The <directive>CacheDisable</directive> directive instructs
185     <module>mod_cache</module> to <em>not</em> cache urls at or below
186     <var>url-string</var>.</p>
187
188     <example><title>Example</title>
189       CacheDisable /local_files
190     </example>
191 </usage>
192
193 </directivesynopsis>
194 <directivesynopsis>
195 <name>CacheMaxExpire</name>
196 <description>The maximum time in seconds to cache a document</description>
197 <syntax>CacheMaxExpire <var>seconds</var></syntax>
198 <default>CacheMaxExpire 86400 (one day)</default>
199 <contextlist><context>server config</context><context>virtual host</context>
200 </contextlist>
201
202 <usage>
203     <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
204     seconds for which cachable HTTP documents will be retained without checking the origin
205     server. Thus, documents will be out of date at most this number of seconds. This maximum
206     value is enforced even if an expiry date was supplied with the document.</p>
207
208     <example>
209       CacheMaxExpire 604800
210     </example>
211 </usage>
212 </directivesynopsis>
213
214 <directivesynopsis>
215 <name>CacheDefaultExpire</name>
216 <description>The default duration to cache a document when no expiry date is specified.</description>
217 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
218 <default>CacheDefaultExpire 3600 (one hour)</default>
219 <contextlist><context>server config</context><context>virtual host</context>
220 </contextlist>
221
222 <usage>
223     <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
224     in seconds, to cache a document if neither an expiry date nor last-modified date are provided
225     with the document. The value specified with the <directive>CacheMaxExpire</directive>
226     directive does <em>not</em> override this setting.</p>
227
228     <example>
229       CacheDefaultExpire 86400
230     </example>
231 </usage>
232 </directivesynopsis>
233
234 <directivesynopsis>
235 <name>CacheIgnoreNoLastMod</name>
236 <description>Ignore the fact that a response has no Last Modified
237 header.</description>
238 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
239 <default>CacheIgnoreNoLastMod Off</default>
240 <contextlist><context>server config</context><context>virtual host</context>
241 </contextlist>
242
243 <usage>
244     <p>Ordinarily, documents without a last-modified date are not cached.
245     Under some circumstances the last-modified date is removed (during
246     <module>mod_include</module> processing for example) or not provided
247     at all. The <directive>CacheIgnoreNoLastMod</directive> directive
248     provides a way to specify that documents without last-modified dates
249     should be considered for caching, even without a last-modified date.
250     If neither a last-modified date nor an expiry date are provided with
251     the document then the value specified by the
252     <directive>CacheDefaultExpire</directive> directive will be used to
253     generate an expiration date.</p>
254
255     <example>
256       CacheIgnoreNoLastMod On
257     </example>
258 </usage>
259 </directivesynopsis>
260
261 <directivesynopsis>
262 <name>CacheIgnoreCacheControl</name>
263 <description>Ignore request to not serve cached content to client</description>
264 <syntax>CacheIgnoreCacheControl On|Off</syntax>
265 <default>CacheIgnoreCacheControl Off</default>
266 <contextlist><context>server config</context><context>virtual host</context>
267 </contextlist>
268
269 <usage>
270     <p>Ordinarily, requests containing a Cache-Control: no-cache or
271     Pragma: no-cache header value will not be served from the cache.  The
272     <directive>CacheIgnoreCacheControl</directive> directive allows this
273     behavior to be overridden.  <directive>CacheIgnoreCacheControl</directive>
274     On tells the server to attempt to serve the resource from the cache even
275     if the request contains no-cache header values.  Resources requiring
276     authorization will <em>never</em> be cached.</p>
277
278     <example>
279       CacheIgnoreCacheControl On
280     </example>
281
282     <note type="warning"><title>Warning:</title>
283        This directive will allow serving from the cache even if the client has
284        requested that the document not be served from the cache.  This might
285        result in stale content being served.
286     </note>
287 </usage>
288 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
289 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
290 </directivesynopsis>
291
292 <directivesynopsis>
293 <name>CacheLastModifiedFactor</name>
294 <description>The factor used to compute an expiry date based on the
295 LastModified date.</description>
296 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
297 <default>CacheLastModifiedFactor 0.1</default>
298 <contextlist><context>server config</context><context>virtual host</context>
299 </contextlist>
300
301 <usage>
302     <p>In the event that a document does not provide an expiry date but does
303     provide a last-modified date, an expiry date can be calculated based on
304     the time since the document was last modified. The
305     <directive>CacheLastModifiedFactor</directive> directive specifies a
306     <var>factor</var> to be used in the generation of this expiry date
307     according to the following formula:
308
309     <code>expiry-period = time-since-last-modified-date * <var>factor</var>
310     expiry-date = current-date + expiry-period</code>
311
312     For example, if the document was last modified 10 hours ago, and
313     <var>factor</var> is 0.1 then the expiry-period will be set to
314     10*0.1 = 1 hour. If the current time was 3:00pm then the computed
315     expiry-date would be 3:00pm + 1hour = 4:00pm.
316
317     If the expiry-period would be longer than that set by
318     <directive>CacheMaxExpire</directive>, then the latter takes
319     precedence.</p>
320
321     <example>
322       CacheLastModifiedFactor 0.5
323     </example>
324 </usage>
325 </directivesynopsis>
326
327 <directivesynopsis>
328 <name>CacheIgnoreHeaders</name>
329 <description>Do not store the given HTTP header(s) in the cache.
330 </description>
331 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
332 <default>CacheIgnoreHeaders None</default>
333 <contextlist><context>server config</context><context>virtual host</context>
334 </contextlist>
335
336 <usage>
337     <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
338     the cache.  The following HTTP headers are hop-by-hop headers and thus
339     do not get stored in the cache in <em>any</em> case regardless of the
340     setting of <directive>CacheIgnoreHeaders</directive>:</p>
341
342     <ul>
343       <li><code>Connection</code></li>
344       <li><code>Keep-Alive</code></li>
345       <li><code>Proxy-Authenticate</code></li>
346       <li><code>Proxy-Authorization</code></li>
347       <li><code>TE</code></li>
348       <li><code>Trailers</code></li>
349       <li><code>Transfer-Encoding</code></li>
350       <li><code>Upgrade</code></li>
351     </ul>
352
353     <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
354     headers that should not to be stored in the cache.  For example, it makes
355     sense in some cases to prevent cookies from being stored in the cache.</p>
356
357     <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
358     of HTTP headers that should not be stored in the cache. If only hop-by-hop
359     headers not should be stored in the cache (the RFC 2616 compliant
360     behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
361     <code>None</code>.</p>
362
363     <example><title>Example 1</title>
364       CacheIgnoreHeaders Set-Cookie
365     </example>
366
367     <example><title>Example 2</title>
368       CacheIgnoreHeaders None
369     </example>
370
371     <note type="warning"><title>Warning:</title>
372       If headers like <code>Expires</code> which are needed for proper cache
373       management are not stored due to a
374       <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
375       mod_cache is undefined.
376     </note>
377 </usage>
378 </directivesynopsis>
379
380 <directivesynopsis>
381 <name>CacheStorePrivate</name>
382 <description>Attempt to cache responses that the server has marked as private</description>
383 <syntax>CacheStorePrivate On|Off</syntax>
384 <default>CacheStorePrivate Off</default>
385 <contextlist><context>server config</context><context>virtual host</context>
386 </contextlist>
387
388 <usage>
389     <p>Ordinarily, responses with Cache-Control: private header values will not
390        be stored in the cache.  The <directive>CacheStorePrivate</directive>
391        directive allows this behavior to be overridden.
392        <directive>CacheStorePrivate</directive> On
393        tells the server to attempt to cache the resource even if it contains
394        private header values.  Resources requiring authorization will
395        <em>never</em> be cached.</p>
396
397     <example>
398       CacheStorePrivate On
399     </example>
400
401     <note type="warning"><title>Warning:</title>
402        This directive will allow caching even if the upstream server has
403        requested that the resource not be cached.  This directive is only
404        ideal for a 'private' cache.
405     </note>
406 </usage>
407 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
408 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
409 </directivesynopsis>
410
411 <directivesynopsis>
412 <name>CacheStoreNoStore</name>
413 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
414 <syntax>CacheStoreNoStore On|Off</syntax>
415 <default>CacheStoreNoStore Off</default>
416 <contextlist><context>server config</context><context>virtual host</context>
417 </contextlist>
418
419 <usage>
420     <p>Ordinarily, requests or responses with Cache-Control: no-store header
421        values will not be stored in the cache.  The
422        <directive>CacheStoreNoCache</directive> directive allows this
423        behavior to be overridden.  <directive>CacheStoreNoCache</directive> On
424        tells the server to attempt to cache the resource even if it contains
425        no-store header values.  Resources requiring authorization will
426        <em>never</em> be cached.</p>
427
428     <example>
429       CacheStoreNoStore On
430     </example>
431
432     <note type="warning"><title>Warning:</title>
433        As described in RFC 2616, the no-store directive is intended to
434        "prevent the inadvertent release or retention of sensitive information
435        (for example, on backup tapes)."  Enabling this option could store
436        sensitive information in the cache.  You are hereby warned.
437     </note>
438 </usage>
439 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
440 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
441 </directivesynopsis>
442 </modulesynopsis>