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