]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_cache.xml
Update the copyright year in all .c, .h and .xml files
[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-2006 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">CacheDirLevels</directive>
73         <directive module="mod_disk_cache">CacheDirLength</directive>
74         <directive module="mod_disk_cache">CacheMinFileSize</directive>
75         <directive module="mod_disk_cache">CacheMaxFileSize</directive>
76         <directive module="mod_mem_cache">MCacheSize</directive>
77         <directive module="mod_mem_cache">MCacheMaxObjectCount</directive>
78         <directive module="mod_mem_cache">MCacheMinObjectSize</directive>
79         <directive module="mod_mem_cache">MCacheMaxObjectSize</directive>
80         <directive module="mod_mem_cache">MCacheRemovalAlgorithm</directive>
81         <directive module="mod_mem_cache">MCacheMaxStreamingBuffer</directive>
82       </directivelist>
83     </related>
84 </section>
85
86 <section id="sampleconf"><title>Sample Configuration</title>
87     <example><title>Sample httpd.conf</title>
88       #<br />
89       # Sample Cache Configuration<br />
90       #<br />
91       LoadModule cache_module modules/mod_cache.so<br />
92       <br />
93       &lt;IfModule mod_cache.c&gt;<br />
94       <indent>
95         #LoadModule disk_cache_module modules/mod_disk_cache.so<br />
96         # If you want to use mod_disk_cache instead of mod_mem_cache,<br />
97         # uncomment the line above and comment out the LoadModule line below.<br />
98         &lt;IfModule mod_disk_cache.c&gt;<br />
99         <indent>
100           CacheRoot c:/cacheroot<br />
101           CacheEnable disk  /<br />
102           CacheDirLevels 5<br />
103           CacheDirLength 3<br />
104         </indent>
105         &lt;/IfModule&gt; <br />
106         <br />
107         LoadModule mem_cache_module modules/mod_mem_cache.so<br />
108         &lt;IfModule mod_mem_cache.c&gt;<br />
109         <indent>
110           CacheEnable mem  /<br />
111           MCacheSize 4096<br />
112           MCacheMaxObjectCount 100<br />
113           MCacheMinObjectSize 1<br />
114           MCacheMaxObjectSize 2048<br />
115         </indent>
116         &lt;/IfModule&gt;<br />
117         <br />
118         # When acting as a proxy, don't cache the list of security updates<br />
119         CacheDisable http://security.update.server/update-list/<br />
120       </indent>
121       &lt;/IfModule&gt;
122     </example>
123 </section>
124
125 <directivesynopsis>
126 <name>CacheEnable</name>
127 <description>Enable caching of specified URLs using a specified storage
128 manager</description>
129 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
130 <contextlist><context>server config</context><context>virtual host</context>
131 </contextlist>
132
133 <usage>
134     <p>The <directive>CacheEnable</directive> directive instructs
135     <module>mod_cache</module> to cache urls at or below
136     <var>url-string</var>. The cache storage manager is specified with the
137     <var>cache_type</var> argument. <var>cache_type</var> <code> mem</code>
138     instructs <module>mod_cache</module> to use the memory based storage
139     manager implemented by <module>mod_mem_cache</module>. 
140     <var>cache_type</var> <code>disk</code> instructs
141     <module>mod_cache</module> to use the disk based storage manager
142     implemented by <module>mod_disk_cache</module>.
143     <var>cache_type</var> <code>fd</code> instructs
144     <module>mod_cache</module> to use the file descriptor cache implemented
145     by <module>mod_mem_cache</module>.</p>
146     <p>In the event that the URL space overlaps between different
147     <directive>CacheEnable</directive> directives (as in the example below),
148     each possible storage manager will be run until the first one that
149     actually processes the request. The order in which the storage managers are
150     run is determined by the order of the <directive>CacheEnable</directive>
151     directives in the configuration file.</p>
152
153     <example>
154       CacheEnable  mem   /manual<br />
155       CacheEnable  fd    /images<br />
156       CacheEnable  disk  /<br />
157     </example>
158
159     <p>When acting as a forward proxy server, <var>url-string</var> can
160     also be used to specify remote sites and proxy protocols which 
161     caching should be enabled for.</p>
162  
163     <example>
164       # Cache proxied url's<br />
165       CacheEnable  disk  /<br /><br />
166       # Cache FTP-proxied url's<br />
167       CacheEnable  disk  ftp://<br /><br />
168       # Cache content from www.apache.org<br />
169       CacheEnable  disk  http://www.apache.org/<br />
170     </example>
171
172 </usage>
173 </directivesynopsis>
174
175 <directivesynopsis>
176 <name>CacheDisable</name>
177 <description>Disable caching of specified URLs</description>
178 <syntax>CacheDisable <var> url-string</var></syntax>
179 <contextlist><context>server config</context><context>virtual host</context>
180 </contextlist>
181
182 <usage>
183     <p>The <directive>CacheDisable</directive> directive instructs
184     <module>mod_cache</module> to <em>not</em> cache urls at or below
185     <var>url-string</var>.</p>
186
187     <example><title>Example</title>
188       CacheDisable /local_files
189     </example>
190 </usage>
191
192 </directivesynopsis>
193 <directivesynopsis>
194 <name>CacheMaxExpire</name>
195 <description>The maximum time in seconds to cache a document</description>
196 <syntax>CacheMaxExpire <var>seconds</var></syntax>
197 <default>CacheMaxExpire 86400 (one day)</default>
198 <contextlist><context>server config</context><context>virtual host</context>
199 </contextlist>
200
201 <usage>
202     <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
203     seconds for which cachable HTTP documents will be retained without checking the origin
204     server. Thus, documents will be out of date at most this number of seconds. This maximum
205     value is enforced even if an expiry date was supplied with the document.</p>
206
207     <example>
208       CacheMaxExpire 604800
209     </example>
210 </usage>
211 </directivesynopsis>
212
213 <directivesynopsis>
214 <name>CacheMinExpire</name>
215 <description>The minimum time in seconds to cache a document</description>
216 <syntax>CacheMinExpire <var>seconds</var></syntax>
217 <default>CacheMinExpire 0</default>
218 <contextlist><context>server config</context><context>virtual host</context>
219 </contextlist>
220
221 <usage>
222     <p>The <directive>CacheMinExpire</directive> directive specifies the minimum number of
223     seconds for which cachable HTTP documents will be retained without checking the origin
224     server. This is only used if no valid expire time was supplied with the document.</p>
225
226
227     <example>
228       CacheMinExpire 3600
229     </example>
230 </usage>
231 </directivesynopsis>
232
233 <directivesynopsis>
234 <name>CacheDefaultExpire</name>
235 <description>The default duration to cache a document when no expiry date is specified.</description>
236 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
237 <default>CacheDefaultExpire 3600 (one hour)</default>
238 <contextlist><context>server config</context><context>virtual host</context>
239 </contextlist>
240
241 <usage>
242     <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
243     in seconds, to cache a document if neither an expiry date nor last-modified date are provided
244     with the document. The value specified with the <directive>CacheMaxExpire</directive>
245     directive does <em>not</em> override this setting.</p>
246
247     <example>
248       CacheDefaultExpire 86400
249     </example>
250 </usage>
251 </directivesynopsis>
252
253 <directivesynopsis>
254 <name>CacheIgnoreNoLastMod</name>
255 <description>Ignore the fact that a response has no Last Modified
256 header.</description>
257 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
258 <default>CacheIgnoreNoLastMod Off</default>
259 <contextlist><context>server config</context><context>virtual host</context>
260 </contextlist>
261
262 <usage>
263     <p>Ordinarily, documents without a last-modified date are not cached.
264     Under some circumstances the last-modified date is removed (during
265     <module>mod_include</module> processing for example) or not provided
266     at all. The <directive>CacheIgnoreNoLastMod</directive> directive
267     provides a way to specify that documents without last-modified dates
268     should be considered for caching, even without a last-modified date.
269     If neither a last-modified date nor an expiry date are provided with
270     the document then the value specified by the
271     <directive>CacheDefaultExpire</directive> directive will be used to
272     generate an expiration date.</p>
273
274     <example>
275       CacheIgnoreNoLastMod On
276     </example>
277 </usage>
278 </directivesynopsis>
279
280 <directivesynopsis>
281 <name>CacheIgnoreCacheControl</name>
282 <description>Ignore request to not serve cached content to client</description>
283 <syntax>CacheIgnoreCacheControl On|Off</syntax>
284 <default>CacheIgnoreCacheControl Off</default>
285 <contextlist><context>server config</context><context>virtual host</context>
286 </contextlist>
287
288 <usage>
289     <p>Ordinarily, requests containing a Cache-Control: no-cache or
290     Pragma: no-cache header value will not be served from the cache.  The
291     <directive>CacheIgnoreCacheControl</directive> directive allows this
292     behavior to be overridden.  <directive>CacheIgnoreCacheControl</directive>
293     On tells the server to attempt to serve the resource from the cache even
294     if the request contains no-cache header values.  Resources requiring
295     authorization will <em>never</em> be cached.</p>
296
297     <example>
298       CacheIgnoreCacheControl On
299     </example>
300
301     <note type="warning"><title>Warning:</title>
302        This directive will allow serving from the cache even if the client has
303        requested that the document not be served from the cache.  This might
304        result in stale content being served.
305     </note>
306 </usage>
307 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
308 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
309 </directivesynopsis>
310
311 <directivesynopsis>
312 <name>CacheLastModifiedFactor</name>
313 <description>The factor used to compute an expiry date based on the
314 LastModified date.</description>
315 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
316 <default>CacheLastModifiedFactor 0.1</default>
317 <contextlist><context>server config</context><context>virtual host</context>
318 </contextlist>
319
320 <usage>
321     <p>In the event that a document does not provide an expiry date but does
322     provide a last-modified date, an expiry date can be calculated based on
323     the time since the document was last modified. The
324     <directive>CacheLastModifiedFactor</directive> directive specifies a
325     <var>factor</var> to be used in the generation of this expiry date
326     according to the following formula:
327
328     <code>expiry-period = time-since-last-modified-date * <var>factor</var>
329     expiry-date = current-date + expiry-period</code>
330
331     For example, if the document was last modified 10 hours ago, and
332     <var>factor</var> is 0.1 then the expiry-period will be set to
333     10*0.1 = 1 hour. If the current time was 3:00pm then the computed
334     expiry-date would be 3:00pm + 1hour = 4:00pm.
335
336     If the expiry-period would be longer than that set by
337     <directive>CacheMaxExpire</directive>, then the latter takes
338     precedence.</p>
339
340     <example>
341       CacheLastModifiedFactor 0.5
342     </example>
343 </usage>
344 </directivesynopsis>
345
346 <directivesynopsis>
347 <name>CacheIgnoreHeaders</name>
348 <description>Do not store the given HTTP header(s) in the cache.
349 </description>
350 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
351 <default>CacheIgnoreHeaders None</default>
352 <contextlist><context>server config</context><context>virtual host</context>
353 </contextlist>
354
355 <usage>
356     <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
357     the cache.  The following HTTP headers are hop-by-hop headers and thus
358     do not get stored in the cache in <em>any</em> case regardless of the
359     setting of <directive>CacheIgnoreHeaders</directive>:</p>
360
361     <ul>
362       <li><code>Connection</code></li>
363       <li><code>Keep-Alive</code></li>
364       <li><code>Proxy-Authenticate</code></li>
365       <li><code>Proxy-Authorization</code></li>
366       <li><code>TE</code></li>
367       <li><code>Trailers</code></li>
368       <li><code>Transfer-Encoding</code></li>
369       <li><code>Upgrade</code></li>
370     </ul>
371
372     <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
373     headers that should not to be stored in the cache.  For example, it makes
374     sense in some cases to prevent cookies from being stored in the cache.</p>
375
376     <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
377     of HTTP headers that should not be stored in the cache. If only hop-by-hop
378     headers not should be stored in the cache (the RFC 2616 compliant
379     behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
380     <code>None</code>.</p>
381
382     <example><title>Example 1</title>
383       CacheIgnoreHeaders Set-Cookie
384     </example>
385
386     <example><title>Example 2</title>
387       CacheIgnoreHeaders None
388     </example>
389
390     <note type="warning"><title>Warning:</title>
391       If headers like <code>Expires</code> which are needed for proper cache
392       management are not stored due to a
393       <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
394       mod_cache is undefined.
395     </note>
396 </usage>
397 </directivesynopsis>
398
399 <directivesynopsis>
400 <name>CacheStorePrivate</name>
401 <description>Attempt to cache responses that the server has marked as private</description>
402 <syntax>CacheStorePrivate On|Off</syntax>
403 <default>CacheStorePrivate Off</default>
404 <contextlist><context>server config</context><context>virtual host</context>
405 </contextlist>
406
407 <usage>
408     <p>Ordinarily, responses with Cache-Control: private header values will not
409        be stored in the cache.  The <directive>CacheStorePrivate</directive>
410        directive allows this behavior to be overridden.
411        <directive>CacheStorePrivate</directive> On
412        tells the server to attempt to cache the resource even if it contains
413        private header values.  Resources requiring authorization will
414        <em>never</em> be cached.</p>
415
416     <example>
417       CacheStorePrivate On
418     </example>
419
420     <note type="warning"><title>Warning:</title>
421        This directive will allow caching even if the upstream server has
422        requested that the resource not be cached.  This directive is only
423        ideal for a 'private' cache.
424     </note>
425 </usage>
426 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
427 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
428 </directivesynopsis>
429
430 <directivesynopsis>
431 <name>CacheStoreNoStore</name>
432 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
433 <syntax>CacheStoreNoStore On|Off</syntax>
434 <default>CacheStoreNoStore Off</default>
435 <contextlist><context>server config</context><context>virtual host</context>
436 </contextlist>
437
438 <usage>
439     <p>Ordinarily, requests or responses with Cache-Control: no-store header
440        values will not be stored in the cache.  The
441        <directive>CacheStoreNoCache</directive> directive allows this
442        behavior to be overridden.  <directive>CacheStoreNoCache</directive> On
443        tells the server to attempt to cache the resource even if it contains
444        no-store header values.  Resources requiring authorization will
445        <em>never</em> be cached.</p>
446
447     <example>
448       CacheStoreNoStore On
449     </example>
450
451     <note type="warning"><title>Warning:</title>
452        As described in RFC 2616, the no-store directive is intended to
453        "prevent the inadvertent release or retention of sensitive information
454        (for example, on backup tapes)."  Enabling this option could store
455        sensitive information in the cache.  You are hereby warned.
456     </note>
457 </usage>
458 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
459 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
460 </directivesynopsis>
461 </modulesynopsis>