]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_cache.xml
Rebuild transformations.
[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>RFC 2616 compliant HTTP caching filter.</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, as when the
33     <directive module="mod_cache">CacheQuickHandler</directive> directive is
34     in its default value of <strong>on</strong>, the <directive 
35     module="mod_authz_host">Allow</directive> and <directive 
36     module="mod_authz_host">Deny</directive> directives will be circumvented.
37     You should not enable quick handler caching for any content to which you
38     wish to limit access by client host name, address or environment
39     variable.</note>  
40
41     <p><module>mod_cache</module> implements an <a
42     href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant
43     <strong>HTTP content caching filter</strong>, with support for the caching
44     of content negotiated responses containing the Vary header.</p>
45
46     <p>RFC 2616 compliant caching provides a mechanism to verify whether
47     stale or expired content is still fresh, and can represent a significant
48     performance boost when the origin server supports <strong>conditional
49     requests</strong> by honouring the
50     <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26">If-None-Match</a>
51     HTTP request header. Content is only regenerated from scratch when the content
52     has changed, and not when the cached entry expires.</p>
53
54     <p>As a filter, <module>mod_cache</module> can be placed in front of
55     content originating from any handler, including <strong>flat
56     files</strong> (served from a slow disk cached on a fast disk), the output
57     of a <strong>CGI script</strong> or <strong>dynamic content
58     generator</strong>, or content <strong>proxied from another
59     server</strong>.</p>
60
61     <p>In the default configuration, <module>mod_cache</module> inserts the
62     caching filter as far forward as possible within the filter stack,
63     utilising the <strong>quick handler</strong> to bypass all per request
64     processing when returning content to the client. In this mode of
65     operation, <module>mod_cache</module> may be thought of as a caching
66     proxy server bolted to the front of the webserver, while running within
67     the webserver itself.</p>
68
69     <p>When the quick handler is switched off using the
70     <directive module="mod_cache">CacheQuickHandler</directive> directive,
71     it becomes possible to insert the <strong>CACHE</strong> filter at a
72     point in the filter stack chosen by the administrator. This provides the
73     opportunity to cache content before that content is personalised by the
74     <module>mod_include</module> filter, or optionally compressed by the
75     <module>mod_deflate</module> filter.</p>
76
77     <p>Under normal operation, <module>mod_cache</module> will respond to
78     and can be controlled by the
79     <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9">Cache-Control</a>
80     and
81     <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32">Pragma</a>
82     headers sent from a client in a request, or from a
83     server within a response. Under exceptional circumstances,
84     <module>mod_cache</module> can be configured to override these headers
85     and force site specific behaviour, however such behaviour will be limited
86     to this cache only, and will not affect the operation of other caches
87     that may exist between the client and server, and as a result is not
88     recommended unless strictly necessary.</p>
89
90     <p>RFC 2616 allows for the cache to return stale data while the existing
91     stale entry is refreshed from the origin server, and this is supported
92     by <module>mod_cache</module> when the
93     <directive module="mod_cache">CacheLock</directive> directive is suitably
94     configured. Such responses will contain a
95     <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">Warning</a>
96     HTTP header with a 110 response code. RFC 2616 also allows a cache to return
97     stale data when the attempt made to refresh the stale data returns an
98     error 500 or above, and this behaviour is supported by default by
99     <module>mod_cache</module>. Such responses will contain a
100     <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.46">Warning</a>
101     HTTP header with a 111 response code.</p>
102
103     <p><module>mod_cache</module> requires the services of one or more
104     storage management modules. One storage management module is included in
105     the base Apache distribution:</p>
106     <dl>
107     <dt><module>mod_cache_disk</module></dt>
108     <dd>Implements a disk based storage manager. Headers and bodies are
109     stored separately on disk, in a directory structure derived from the
110     md5 hash of the cached URL. Multiple content negotiated responses can
111     be stored concurrently, however the caching of partial content is not
112     supported by this module. The <program>htcacheclean</program> tool is
113     provided to list cached URLs, remove cached URLs, or to maintain the size
114     of the disk cache within size and inode limits.</dd>
115     </dl>
116
117     <p>Further details, discussion, and examples, are provided in the
118     <a href="../caching.html">Caching Guide</a>.</p>
119 </summary>
120 <seealso><a href="../caching.html">Caching Guide</a></seealso>
121
122 <section id="related"><title>Related Modules and Directives</title>
123     <related>
124       <modulelist>
125         <module>mod_cache_disk</module>
126       </modulelist>
127       <directivelist>
128         <directive module="mod_cache_disk">CacheRoot</directive>
129         <directive module="mod_cache_disk">CacheDirLevels</directive>
130         <directive module="mod_cache_disk">CacheDirLength</directive>
131         <directive module="mod_cache_disk">CacheMinFileSize</directive>
132         <directive module="mod_cache_disk">CacheMaxFileSize</directive>
133       </directivelist>
134     </related>
135 </section>
136
137 <section id="sampleconf"><title>Sample Configuration</title>
138     <example><title>Sample httpd.conf</title>
139       #<br />
140       # Sample Cache Configuration<br />
141       #<br />
142       LoadModule cache_module modules/mod_cache.so<br />
143       <br />
144       &lt;IfModule mod_cache.c&gt;<br />
145       <indent>
146         LoadModule cache_disk_module modules/mod_cache_disk.so<br />
147         &lt;IfModule mod_cache_disk.c&gt;<br />
148         <indent>
149           CacheRoot c:/cacheroot<br />
150           CacheEnable disk  /<br />
151           CacheDirLevels 5<br />
152           CacheDirLength 3<br />
153         </indent>
154         &lt;/IfModule&gt; <br />
155         <br />
156         # When acting as a proxy, don't cache the list of security updates<br />
157         CacheDisable http://security.update.server/update-list/<br />
158       </indent>
159       &lt;/IfModule&gt;
160     </example>
161 </section>
162
163 <section id="thunderingherd"><title>Avoiding the Thundering Herd</title>
164   <p>When a cached entry becomes stale, <module>mod_cache</module> will submit
165   a conditional request to the backend, which is expected to confirm whether the
166   cached entry is still fresh, and send an updated entity if not.</p>
167   <p>A small but finite amount of time exists between the time the cached entity
168   becomes stale, and the time the stale entity is fully refreshed. On a busy
169   server, a significant number of requests might arrive during this time, and
170   cause a <strong>thundering herd</strong> of requests to strike the backend
171   suddenly and unpredicably.</p>
172   <p>To keep the thundering herd at bay, the <directive>CacheLock</directive>
173   directive can be used to define a directory in which locks are created for
174   URLs <strong>in flight</strong>. The lock is used as a <strong>hint</strong>
175   by other requests to either suppress an attempt to cache (someone else has
176   gone to fetch the entity), or to indicate that a stale entry is being refreshed
177   (stale content will be returned in the mean time).
178   </p>
179   <section>
180     <title>Initial caching of an entry</title>
181     <p>When an entity is cached for the first time, a lock will be created for the
182     entity until the response has been fully cached. During the lifetime of the
183     lock, the cache will suppress the second and subsequent attempt to cache the
184     same entity. While this doesn't hold back the thundering herd, it does stop
185     the cache attempting to cache the same entity multiple times simultaneously.
186     </p>
187   </section>
188   <section>
189     <title>Refreshment of a stale entry</title>
190     <p>When an entity reaches its freshness lifetime and becomes stale, a lock
191     will be created for the entity until the response has either been confirmed as
192     still fresh, or replaced by the backend. During the lifetime of the lock, the
193     second and subsequent incoming request will cause stale data to be returned,
194     and the thundering herd is kept at bay.</p>
195   </section>
196   <section>
197     <title>Locks and Cache-Control: no-cache</title>
198     <p>Locks are used as a <strong>hint only</strong> to enable the cache to be
199     more gentle on backend servers, however the lock can be overridden if necessary.
200     If the client sends a request with a Cache-Control header forcing a reload, any
201     lock that may be present will be ignored, and the client's request will be
202     honored immediately and the cached entry refreshed.</p>
203     <p>As a further safety mechanism, locks have a configurable maximum age.
204     Once this age has been reached, the lock is removed, and a new request is
205     given the opportunity to create a new lock. This maximum age can be set using
206     the <directive>CacheLockMaxAge</directive> directive, and defaults to 5
207     seconds.
208     </p>
209   </section>
210   <section>
211     <title>Example configuration</title>
212     <example><title>Enabling the cache lock</title>
213       #<br />
214       # Enable the cache lock<br />
215       #<br />
216       &lt;IfModule mod_cache.c&gt;<br />
217       <indent>
218         CacheLock on<br />
219         CacheLockPath /tmp/mod_cache-lock<br />
220         CacheLockMaxAge 5<br />
221       </indent>
222       &lt;/IfModule&gt;
223     </example>
224   </section>
225 </section>
226
227 <section id="finecontrol"><title>Fine Control with the CACHE Filter</title>
228   <p>Under the default mode of cache operation, the cache runs as a quick handler,
229   short circuiting the majority of server processing and offering the highest
230   cache performance available.</p>
231   
232   <p>In this mode, the cache <strong>bolts onto</strong> the front of the server,
233   acting as if a free standing RFC 2616 caching proxy had been placed in front of
234   the server.</p>
235   
236   <p>While this mode offers the best performance, the administrator may find that
237   under certain circumstances they may want to perform further processing on the
238   request after the request is cached, such as to inject personalisation into the
239   cached page, or to apply authorisation restrictions to the content. Under these
240   circumstances, an administrator is often forced to place independent reverse
241   proxy servers either behind or in front of the caching server to achieve this.</p>
242
243   <p>To solve this problem the <directive module="mod_cache">CacheQuickHandler
244   </directive> directive can be set to <strong>off</strong>, and the server will
245   process all phases normally handled by a non-cached request, including the
246   <strong>authentication and authorisation</strong> phases.</p>
247
248   <p>In addition, the administrator may optionally specify the <strong>precise point
249   within the filter chain</strong> where caching is to take place by adding the
250   <strong>CACHE</strong> filter to the output filter chain.</p>
251
252   <p>For example, to cache content before applying compression to the response,
253   place the <strong>CACHE</strong> filter before the <strong>DEFLATE</strong>
254   filter as in the example below:</p>
255
256   <example>
257     # Cache content before optional compression<br />
258     CacheQuickHandler off<br />
259     AddOutputFilterByType CACHE;DEFLATE text/plain<br /><br />
260   </example>
261
262   <p>Another option is to have content cached before personalisation is applied
263   by <module>mod_include</module> (or another content processing filter). In this
264   example templates containing tags understood by
265   <module>mod_include</module> are cached before being parsed:</p>
266
267   <example>
268     # Cache content before mod_include and mod_deflate<br />
269     CacheQuickHandler off<br />
270     AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html<br /><br />
271   </example>
272
273   <p>You may place the <strong>CACHE</strong> filter anywhere you wish within the
274   filter chain. In this example, content is cached after being parsed by
275   <module>mod_include</module>, but before being processed by
276   <module>mod_deflate</module>:</p>
277
278   <example>
279     # Cache content between mod_include and mod_deflate<br />
280     CacheQuickHandler off<br />
281     AddOutputFilterByType INCLUDES;CACHE;DEFLATE text/html<br /><br />
282   </example>
283
284   <note type="warning"><title>Warning:</title>If the location of the
285   <strong>CACHE</strong> filter in the filter chain is changed for any reason,
286   you may need to <strong>flush your cache</strong> to ensure that your data
287   served remains consistent. <module>mod_cache</module> is not in a position
288   to enforce this for you.</note>
289
290 </section>
291
292 <section id="status"><title>Cache Status and Logging</title>
293   <p>Once <module>mod_cache</module> has made a decision as to whether or not
294   an entity is to be served from cache, the detailed reason for the decision
295   is written to the subprocess environment within the request under the
296   <strong>cache-status</strong> key. This reason can be logged by the
297   <directive module="mod_log_config">LogFormat</directive> directive as
298   follows:</p>
299
300   <example>
301     LogFormat "%{cache-status}e ..."
302   </example>
303
304   <p>Based on the caching decision made, the reason is also written to the
305   subprocess environment under one the following four keys, as appropriate:</p>
306
307   <dl>
308     <dt>cache-hit</dt><dd>The response was served from cache.</dd>
309     <dt>cache-revalidate</dt><dd>The response was stale and was successfully
310       revalidated, then served from cache.</dd>
311     <dt>cache-miss</dt><dd>The response was served from the upstream server.</dd>
312     <dt>cache-invalidate</dt><dd>The cached entity was invalidated by a request
313       method other than GET or HEAD.</dd>
314   </dl>
315
316   <p>This makes it possible to support conditional logging of cached requests
317   as per the following example:</p>
318
319   <example>
320     CustomLog cached-requests.log common env=cache-hit<br />
321     CustomLog uncached-requests.log common env=cache-miss<br />
322     CustomLog revalidated-requests.log common env=cache-revalidate<br />
323     CustomLog invalidated-requests.log common env=cache-invalidate<br />
324   </example>
325
326   <p>For module authors, a hook called <var>cache_status</var> is available,
327   allowing modules to respond to the caching outcomes above in customised
328   ways.</p>
329 </section>
330
331 <directivesynopsis>
332 <name>CacheEnable</name>
333 <description>Enable caching of specified URLs using a specified storage
334 manager</description>
335 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
336 <contextlist><context>server config</context><context>virtual host</context>
337 </contextlist>
338
339 <usage>
340     <p>The <directive>CacheEnable</directive> directive instructs
341     <module>mod_cache</module> to cache urls at or below
342     <var>url-string</var>. The cache storage manager is specified with the
343     <var>cache_type</var> argument. If the <directive>CacheEnable</directive>
344     directive is placed inside a <directive type="section">Location</directive>
345     directive, the <var>url-string</var> becomes optional.
346     <var>cache_type</var> <code>disk</code> instructs
347     <module>mod_cache</module> to use the disk based storage manager
348     implemented by <module>mod_cache_disk</module>.</p>
349     <p>In the event that the URL space overlaps between different
350     <directive>CacheEnable</directive> directives (as in the example below),
351     each possible storage manager will be run until the first one that
352     actually processes the request. The order in which the storage managers are
353     run is determined by the order of the <directive>CacheEnable</directive>
354     directives in the configuration file.</p>
355
356     <p>When acting as a forward proxy server, <var>url-string</var> can
357     also be used to specify remote sites and proxy protocols which 
358     caching should be enabled for.</p>
359  
360     <example>
361       # Cache proxied url's<br />
362       CacheEnable  disk  /<br /><br />
363       # Cache FTP-proxied url's<br />
364       CacheEnable  disk  ftp://<br /><br />
365       # Cache content from www.example.org<br />
366       CacheEnable  disk  http://www.example.org/<br />
367     </example>
368
369     <p>A hostname starting with a <strong>"*"</strong> matches all hostnames with
370     that suffix. A hostname starting with <strong>"."</strong> matches all
371     hostnames containing the domain components that follow.</p>
372
373     <example>
374       # Match www.example.org, and fooexample.org<br />
375       CacheEnable  disk  http://*example.org/<br />
376       # Match www.example.org, but not fooexample.org<br />
377       CacheEnable  disk  http://.example.org/<br />
378     </example>
379
380     <p> The <code>no-cache</code> environment variable can be set to 
381     disable caching on a finer grained set of resources in versions
382     2.2.12 and later.</p>
383
384 </usage>
385 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
386 </directivesynopsis>
387
388 <directivesynopsis>
389 <name>CacheDisable</name>
390 <description>Disable caching of specified URLs</description>
391 <syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
392 <contextlist><context>server config</context><context>virtual host</context>
393 </contextlist>
394
395 <usage>
396     <p>The <directive>CacheDisable</directive> directive instructs
397     <module>mod_cache</module> to <em>not</em> cache urls at or below
398     <var>url-string</var>.</p>
399
400     <example><title>Example</title>
401       CacheDisable /local_files
402     </example>
403
404     <p>If used in a <directive type="section">Location</directive> directive,
405     the path needs to be specified below the Location, or if the word "on"
406     is used, caching for the whole location will be disabled.</p>
407
408     <example><title>Example</title>
409       &lt;Location /foo&gt;<br />
410         CacheDisable on<br />
411       &lt;/Location&gt;<br />
412     </example>
413
414     <p> The <code>no-cache</code> environment variable can be set to 
415     disable caching on a finer grained set of resources in versions
416     2.2.12 and later.</p>
417
418 </usage>
419 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
420 </directivesynopsis>
421 <directivesynopsis>
422 <name>CacheMaxExpire</name>
423 <description>The maximum time in seconds to cache a document</description>
424 <syntax>CacheMaxExpire <var>seconds</var></syntax>
425 <default>CacheMaxExpire 86400 (one day)</default>
426 <contextlist><context>server config</context>
427     <context>virtual host</context>
428     <context>directory</context>
429     <context>.htaccess</context>
430 </contextlist>
431
432 <usage>
433     <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
434     seconds for which cachable HTTP documents will be retained without checking the origin
435     server. Thus, documents will be out of date at most this number of seconds. This maximum
436     value is enforced even if an expiry date was supplied with the document.</p>
437
438     <example>
439       CacheMaxExpire 604800
440     </example>
441 </usage>
442 </directivesynopsis>
443
444 <directivesynopsis>
445 <name>CacheMinExpire</name>
446 <description>The minimum time in seconds to cache a document</description>
447 <syntax>CacheMinExpire <var>seconds</var></syntax>
448 <default>CacheMinExpire 0</default>
449 <contextlist><context>server config</context>
450   <context>virtual host</context>
451   <context>directory</context>
452   <context>.htaccess</context>
453 </contextlist>
454
455 <usage>
456     <p>The <directive>CacheMinExpire</directive> directive specifies the minimum number of
457     seconds for which cachable HTTP documents will be retained without checking the origin
458     server. This is only used if no valid expire time was supplied with the document.</p>
459
460
461     <example>
462       CacheMinExpire 3600
463     </example>
464 </usage>
465 </directivesynopsis>
466
467 <directivesynopsis>
468 <name>CacheDefaultExpire</name>
469 <description>The default duration to cache a document when no expiry date is specified.</description>
470 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
471 <default>CacheDefaultExpire 3600 (one hour)</default>
472 <contextlist><context>server config</context>
473   <context>virtual host</context>
474   <context>directory</context>
475   <context>.htaccess</context>
476 </contextlist>
477
478 <usage>
479     <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
480     in seconds, to cache a document if neither an expiry date nor last-modified date are provided
481     with the document. The value specified with the <directive>CacheMaxExpire</directive>
482     directive does <em>not</em> override this setting.</p>
483
484     <example>
485       CacheDefaultExpire 86400
486     </example>
487 </usage>
488 </directivesynopsis>
489
490 <directivesynopsis>
491 <name>CacheIgnoreNoLastMod</name>
492 <description>Ignore the fact that a response has no Last Modified
493 header.</description>
494 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
495 <default>CacheIgnoreNoLastMod Off</default>
496 <contextlist><context>server config</context>
497   <context>virtual host</context>
498   <context>directory</context>
499   <context>.htaccess</context>
500 </contextlist>
501     
502 <usage>
503     <p>Ordinarily, documents without a last-modified date are not cached.
504     Under some circumstances the last-modified date is removed (during
505     <module>mod_include</module> processing for example) or not provided
506     at all. The <directive>CacheIgnoreNoLastMod</directive> directive
507     provides a way to specify that documents without last-modified dates
508     should be considered for caching, even without a last-modified date.
509     If neither a last-modified date nor an expiry date are provided with
510     the document then the value specified by the
511     <directive>CacheDefaultExpire</directive> directive will be used to
512     generate an expiration date.</p>
513
514     <example>
515       CacheIgnoreNoLastMod On
516     </example>
517 </usage>
518 </directivesynopsis>
519
520 <directivesynopsis>
521 <name>CacheIgnoreCacheControl</name>
522 <description>Ignore request to not serve cached content to client</description>
523 <syntax>CacheIgnoreCacheControl On|Off</syntax>
524 <default>CacheIgnoreCacheControl Off</default>
525 <contextlist><context>server config</context><context>virtual host</context>
526 </contextlist>
527
528 <usage>
529     <p>Ordinarily, requests containing a Cache-Control: no-cache or
530     Pragma: no-cache header value will not be served from the cache.  The
531     <directive>CacheIgnoreCacheControl</directive> directive allows this
532     behavior to be overridden.  <directive>CacheIgnoreCacheControl On</directive>
533     tells the server to attempt to serve the resource from the cache even
534     if the request contains no-cache header values.  Resources requiring
535     authorization will <em>never</em> be cached.</p>
536
537     <example>
538       CacheIgnoreCacheControl On
539     </example>
540
541     <note type="warning"><title>Warning:</title>
542        This directive will allow serving from the cache even if the client has
543        requested that the document not be served from the cache.  This might
544        result in stale content being served.
545     </note>
546 </usage>
547 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
548 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
549 </directivesynopsis>
550
551 <directivesynopsis>
552 <name>CacheIgnoreQueryString</name>
553 <description>Ignore query string when caching</description>
554 <syntax>CacheIgnoreQueryString On|Off</syntax>
555 <default>CacheIgnoreQueryString Off</default>
556 <contextlist><context>server config</context><context>virtual host</context>
557 </contextlist>
558
559 <usage>
560     <p>Ordinarily, requests with query string parameters are cached separately
561     for each unique query string. This is according to RFC 2616/13.9 done only
562     if an expiration time is specified. The 
563     <directive>CacheIgnoreQueryString</directive> directive tells the cache to
564     cache requests even if no expiration time is specified, and to reply with 
565     a cached reply even if the query string differs. From a caching point of
566     view the request is treated as if having no query string when this 
567     directive is enabled.</p>
568
569     <example>
570       CacheIgnoreQueryString On
571     </example>
572
573 </usage>
574 </directivesynopsis>
575
576 <directivesynopsis>
577 <name>CacheLastModifiedFactor</name>
578 <description>The factor used to compute an expiry date based on the
579 LastModified date.</description>
580 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
581 <default>CacheLastModifiedFactor 0.1</default>
582 <contextlist><context>server config</context>
583   <context>virtual host</context>
584   <context>directory</context>
585   <context>.htaccess</context>
586 </contextlist>
587     
588 <usage>
589     <p>In the event that a document does not provide an expiry date but does
590     provide a last-modified date, an expiry date can be calculated based on
591     the time since the document was last modified. The
592     <directive>CacheLastModifiedFactor</directive> directive specifies a
593     <var>factor</var> to be used in the generation of this expiry date
594     according to the following formula:
595
596     <code>expiry-period = time-since-last-modified-date * <var>factor</var>
597     expiry-date = current-date + expiry-period</code>
598
599     For example, if the document was last modified 10 hours ago, and
600     <var>factor</var> is 0.1 then the expiry-period will be set to
601     10*0.1 = 1 hour. If the current time was 3:00pm then the computed
602     expiry-date would be 3:00pm + 1hour = 4:00pm.
603
604     If the expiry-period would be longer than that set by
605     <directive>CacheMaxExpire</directive>, then the latter takes
606     precedence.</p>
607
608     <example>
609       CacheLastModifiedFactor 0.5
610     </example>
611 </usage>
612 </directivesynopsis>
613
614 <directivesynopsis>
615 <name>CacheIgnoreHeaders</name>
616 <description>Do not store the given HTTP header(s) in the cache.
617 </description>
618 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
619 <default>CacheIgnoreHeaders None</default>
620 <contextlist><context>server config</context><context>virtual host</context>
621 </contextlist>
622
623 <usage>
624     <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
625     the cache.  The following HTTP headers are hop-by-hop headers and thus
626     do not get stored in the cache in <em>any</em> case regardless of the
627     setting of <directive>CacheIgnoreHeaders</directive>:</p>
628
629     <ul>
630       <li><code>Connection</code></li>
631       <li><code>Keep-Alive</code></li>
632       <li><code>Proxy-Authenticate</code></li>
633       <li><code>Proxy-Authorization</code></li>
634       <li><code>TE</code></li>
635       <li><code>Trailers</code></li>
636       <li><code>Transfer-Encoding</code></li>
637       <li><code>Upgrade</code></li>
638     </ul>
639
640     <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
641     headers that should not to be stored in the cache.  For example, it makes
642     sense in some cases to prevent cookies from being stored in the cache.</p>
643
644     <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
645     of HTTP headers that should not be stored in the cache. If only hop-by-hop
646     headers not should be stored in the cache (the RFC 2616 compliant
647     behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
648     <code>None</code>.</p>
649
650     <example><title>Example 1</title>
651       CacheIgnoreHeaders Set-Cookie
652     </example>
653
654     <example><title>Example 2</title>
655       CacheIgnoreHeaders None
656     </example>
657
658     <note type="warning"><title>Warning:</title>
659       If headers like <code>Expires</code> which are needed for proper cache
660       management are not stored due to a
661       <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
662       mod_cache is undefined.
663     </note>
664 </usage>
665 </directivesynopsis>
666
667 <directivesynopsis>
668 <name>CacheIgnoreURLSessionIdentifiers</name>
669 <description>Ignore defined session identifiers encoded in the URL when caching
670 </description>
671 <syntax>CacheIgnoreURLSessionIdentifiers <var>identifier</var> [<var>identifier</var>] ...</syntax>
672 <default>CacheIgnoreURLSessionIdentifiers None</default>
673 <contextlist><context>server config</context><context>virtual host</context>
674 </contextlist>
675
676 <usage>
677     <p>Sometimes applications encode the session identifier into the URL like in the following
678     Examples:
679     </p>
680     <ul>
681       <li><code>/someapplication/image.gif;jsessionid=123456789</code></li>
682       <li><code>/someapplication/image.gif?PHPSESSIONID=12345678</code></li>
683     </ul>
684     <p>This causes cachable resources to be stored separately for each session, which
685     is often not desired. <directive>CacheIgnoreURLSessionIdentifiers</directive> lets
686     define a list of identifiers that are removed from the key that is used to identify
687     an entity in the cache, such that cachable resources are not stored separately for
688     each session.
689     </p>
690     <p><code>CacheIgnoreURLSessionIdentifiers None</code> clears the list of ignored
691     identifiers. Otherwise, each identifier is added to the list.</p>
692
693     <example><title>Example 1</title>
694       CacheIgnoreURLSessionIdentifiers jsessionid
695     </example>
696
697     <example><title>Example 2</title>
698       CacheIgnoreURLSessionIdentifiers None
699     </example>
700
701 </usage>
702 </directivesynopsis>
703
704 <directivesynopsis>
705 <name>CacheStoreExpired</name>
706 <description>Attempt to cache responses that the server reports as expired</description>
707 <syntax>CacheStoreExpired On|Off</syntax>
708 <default>CacheStoreExpired Off</default>
709 <contextlist><context>server config</context>
710   <context>virtual host</context>
711   <context>directory</context>
712   <context>.htaccess</context>
713 </contextlist>
714
715 <usage>
716     <p>Since httpd 2.2.4, responses which have already expired are not
717        stored in the cache.  The <directive>CacheStoreExpired</directive>
718        directive allows this behavior to be overridden.
719        <directive>CacheStoreExpired</directive> On
720        tells the server to attempt to cache the resource if it is stale.
721        Subsequent requests would trigger an If-Modified-Since request of
722        the origin server, and the response may be fulfilled from cache
723        if the backend resource has not changed.</p>
724
725     <example>
726       CacheStoreExpired On
727     </example>
728 </usage>
729 </directivesynopsis>
730
731 <directivesynopsis>
732 <name>CacheStorePrivate</name>
733 <description>Attempt to cache responses that the server has marked as private</description>
734 <syntax>CacheStorePrivate On|Off</syntax>
735 <default>CacheStorePrivate Off</default>
736 <contextlist><context>server config</context>
737   <context>virtual host</context>
738   <context>directory</context>
739   <context>.htaccess</context>
740 </contextlist>
741
742 <usage>
743     <p>Ordinarily, responses with Cache-Control: private header values will not
744        be stored in the cache.  The <directive>CacheStorePrivate</directive>
745        directive allows this behavior to be overridden.
746        <directive>CacheStorePrivate</directive> On
747        tells the server to attempt to cache the resource even if it contains
748        private header values.  Resources requiring authorization will
749        <em>never</em> be cached.</p>
750
751     <example>
752       CacheStorePrivate On
753     </example>
754
755     <note type="warning"><title>Warning:</title>
756        This directive will allow caching even if the upstream server has
757        requested that the resource not be cached.  This directive is only
758        ideal for a 'private' cache.
759     </note>
760 </usage>
761 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
762 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
763 </directivesynopsis>
764
765 <directivesynopsis>
766 <name>CacheStoreNoStore</name>
767 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
768 <syntax>CacheStoreNoStore On|Off</syntax>
769 <default>CacheStoreNoStore Off</default>
770 <contextlist><context>server config</context>
771   <context>virtual host</context>
772   <context>directory</context>
773   <context>.htaccess</context>
774 </contextlist>
775
776 <usage>
777     <p>Ordinarily, requests or responses with Cache-Control: no-store header
778        values will not be stored in the cache.  The
779        <directive>CacheStoreNoCache</directive> directive allows this
780        behavior to be overridden.  <directive>CacheStoreNoCache</directive> On
781        tells the server to attempt to cache the resource even if it contains
782        no-store header values.  Resources requiring authorization will
783        <em>never</em> be cached.</p>
784
785     <example>
786       CacheStoreNoStore On
787     </example>
788
789     <note type="warning"><title>Warning:</title>
790        As described in RFC 2616, the no-store directive is intended to
791        "prevent the inadvertent release or retention of sensitive information
792        (for example, on backup tapes)."  Enabling this option could store
793        sensitive information in the cache.  You are hereby warned.
794     </note>
795 </usage>
796 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
797 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
798 </directivesynopsis>
799
800 <directivesynopsis>
801 <name>CacheLock</name>
802 <description>Enable the thundering herd lock.</description>
803 <syntax>CacheLock <var>on|off</var></syntax>
804 <default>CacheLock off</default>
805 <contextlist><context>server config</context><context>virtual host</context>
806 </contextlist>
807 <compatibility>Available in Apache 2.2.15 and later</compatibility>
808
809 <usage>
810   <p>The <directive>CacheLock</directive> directive enables the thundering herd lock
811   for the given URL space.</p>
812   
813   <p>In a minimal configuration the following directive is all that is needed to
814   enable the thundering herd lock in the default system temp directory.</p>
815
816   <example>
817     # Enable cache lock<br />
818     CacheLock on<br /><br />
819   </example>
820
821 </usage>
822 </directivesynopsis>
823
824 <directivesynopsis>
825 <name>CacheLockPath</name>
826 <description>Set the lock path directory.</description>
827 <syntax>CacheLockPath <var>directory</var></syntax>
828 <default>CacheLockPath /tmp/mod_cache-lock</default>
829 <contextlist><context>server config</context><context>virtual host</context>
830 </contextlist>
831     
832 <usage>
833   <p>The <directive>CacheLockPath</directive> directive allows you to specify the
834   directory in which the locks are created. By default, the system's temporary
835   folder is used. Locks consist of empty files that only exist for stale URLs
836   in flight, so is significantly less resource intensive than the traditional
837   disk cache.</p>
838
839 </usage>
840 </directivesynopsis>
841
842 <directivesynopsis>
843 <name>CacheLockMaxAge</name>
844 <description>Set the maximum possible age of a cache lock.</description>
845 <syntax>CacheLockMaxAge <var>integer</var></syntax>
846 <default>CacheLockMaxAge 5</default>
847 <contextlist><context>server config</context><context>virtual host</context>
848 </contextlist>
849     
850 <usage>
851   <p>The <directive>CacheLockMaxAge</directive> directive specifies the maximum
852   age of any cache lock.</p>
853   
854   <p>A lock older than this value in seconds will be ignored, and the next
855   incoming request will be given the opportunity to re-establish the lock.
856   This mechanism prevents a slow client taking an excessively long time to refresh
857   an entity.</p>
858   
859 </usage>
860 </directivesynopsis>
861
862 <directivesynopsis>
863   <name>CacheQuickHandler</name>
864   <description>Run the cache from the quick handler.</description>
865   <syntax>CacheQuickHandler <var>on|off</var></syntax>
866   <default>CacheQuickHandler on</default>
867   <contextlist><context>server config</context><context>virtual host</context>
868   </contextlist>
869
870   <usage>
871     <p>The <directive module="mod_cache">CacheQuickHandler</directive> directive
872     controls the phase in which the cache is handled.</p>
873
874     <p>In the default enabled configuration, the cache operates within the quick
875     handler phase. This phase short circuits the majority of server processing,
876     and represents the most performant mode of operation for a typical server.
877     The cache <strong>bolts onto</strong> the front of the server, and the
878     majority of server processing is avoided.</p>
879
880     <p>When disabled, the cache operates as a normal handler, and is subject to
881     the full set of phases when handling a server request. While this mode is
882     slower than the default, it allows the cache to be used in cases where full
883     processing is required, such as when content is subject to authorisation.</p>
884
885     <example>
886       # Run cache as a normal handler<br />
887       CacheQuickHandler off<br /><br />
888     </example>
889
890     <p>It is also possible, when the quick handler is disabled, for the
891     administrator to choose the precise location within the filter chain where
892     caching is to be performed, by adding the <strong>CACHE</strong> filter to
893     the chain.</p>
894
895     <example>
896       # Cache content before mod_include and mod_deflate<br />
897       CacheQuickHandler off<br />
898       AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html<br /><br />
899     </example>
900
901     <p>If the CACHE filter is specified more than once, the last instance will
902     apply.</p>
903
904   </usage>
905 </directivesynopsis>
906
907 <directivesynopsis>
908 <name>CacheHeader</name>
909 <description>Add an X-Cache header to the response.</description>
910 <syntax>CacheHeader <var>on|off</var></syntax>
911 <default>CacheHeader off</default>
912 <contextlist><context>server config</context>
913     <context>virtual host</context>
914     <context>directory</context>
915     <context>.htaccess</context>
916 </contextlist>
917 <compatibility>Available in Apache 2.3.9 and later</compatibility>
918   
919 <usage>
920   <p>When the <directive module="mod_cache">CacheHeader</directive> directive
921   is switched on, an <strong>X-Cache</strong> header will be added to the response
922   with the cache status of this response. If the normal handler is used, this
923   directive may appear within a <directive module="core">&lt;Directory&gt;</directive>
924   or <directive module="core">&lt;Location&gt;</directive> directive. If the quick
925   handler is used, this directive must appear within a server or virtual host
926   context, otherwise the setting will be ignored.</p>
927
928   <dl>
929     <dt><strong>HIT</strong></dt><dd>The entity was fresh, and was served from
930     cache.</dd>
931     <dt><strong>REVALIDATE</strong></dt><dd>The entity was stale, was successfully
932     revalidated and was served from cache.</dd>
933     <dt><strong>MISS</strong></dt><dd>The entity was fetched from the upstream
934       server and was not served from cache.</dd>
935   </dl>
936
937   <example>
938     # Enable the X-Cache header<br />
939     CacheHeader on<br />
940   </example>
941
942   <example>
943     X-Cache: HIT from localhost<br />
944   </example>
945
946 </usage>
947 </directivesynopsis>
948
949 <directivesynopsis>
950 <name>CacheDetailHeader</name>
951 <description>Add an X-Cache-Detail header to the response.</description>
952 <syntax>CacheDetailHeader <var>on|off</var></syntax>
953 <default>CacheDetailHeader off</default>
954 <contextlist><context>server config</context>
955       <context>virtual host</context>
956       <context>directory</context>
957       <context>.htaccess</context>
958 </contextlist>
959 <compatibility>Available in Apache 2.3.9 and later</compatibility>
960     
961 <usage>
962   <p>When the <directive module="mod_cache">CacheDetailHeader</directive> directive
963   is switched on, an <strong>X-Cache-Detail</strong> header will be added to the response
964   containing the detailed reason for a particular caching decision.</p>
965   
966   <p>It can be useful during development of cached RESTful services to have additional
967   information about the caching decision written to the response headers, so as to
968   confirm whether <code>Cache-Control</code> and other headers have been correctly
969   used by the service and client.</p>
970   
971   <p>If the normal handler is used, this directive may appear within a
972   <directive module="core">&lt;Directory&gt;</directive> or
973   <directive module="core">&lt;Location&gt;</directive> directive. If the quick handler
974   is used, this directive must appear within a server or virtual host context, otherwise
975   the setting will be ignored.</p>
976
977   <example>
978     # Enable the X-Cache-Detail header<br />
979     CacheDetailHeader on<br />
980   </example>
981
982   <example>
983     X-Cache-Detail: "conditional cache hit: entity refreshed" from localhost<br />
984   </example>
985
986 </usage>
987 </directivesynopsis>
988
989 <directivesynopsis>
990 <name>CacheKeyBaseURL</name>
991 <description>Override the base URL of reverse proxied cache keys.</description>
992 <syntax>CacheKeyBaseURL <var>URL</var></syntax>
993 <default>CacheKeyBaseURL http://example.com</default>
994 <contextlist><context>server config</context>
995 <context>virtual host</context>
996 </contextlist>
997 <compatibility>Available in Apache 2.3.9 and later</compatibility>
998
999 <usage>
1000   <p>When the <directive module="mod_cache">CacheKeyBaseURL</directive> directive
1001   is specified, the URL provided will be used as the base URL to calculate
1002   the URL of the cache keys in the reverse proxy configuration. When not specified,
1003   the scheme, hostname and port of the current virtual host is used to construct
1004   the cache key. When a cluster of machines is present, and all cached entries
1005   should be cached beneath the same cache key, a new base URL can be specified
1006   with this directive.</p>
1007
1008   <example>
1009     # Override the base URL of the cache key.<br />
1010     CacheKeyBaseURL http://www.example.com/<br />
1011   </example>
1012
1013   <note type="warning">Take care when setting this directive. If two separate virtual
1014   hosts are accidentally given the same base URL, entries from one virtual host
1015   will be served to the other.</note>
1016
1017 </usage>
1018 </directivesynopsis>
1019
1020 <directivesynopsis>
1021 <name>CacheStaleOnError</name>
1022 <description>Serve stale content in place of 5xx responses.</description>
1023 <syntax>CacheStaleOnError <var>on|off</var></syntax>
1024 <default>CacheStaleOnError on</default>
1025 <contextlist><context>server config</context>
1026     <context>virtual host</context>
1027     <context>directory</context>
1028     <context>.htaccess</context>
1029 </contextlist>
1030 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1031
1032 <usage>
1033   <p>When the <directive module="mod_cache">CacheStaleOnError</directive> directive
1034   is switched on, and when stale data is available in the cache, the cache will
1035   respond to 5xx responses from the backend by returning the stale data instead of
1036   the 5xx response. While the Cache-Control headers sent by clients will be respected,
1037   and the raw 5xx responses returned to the client on request, the 5xx response so
1038   returned to the client will not invalidate the content in the cache.</p>
1039
1040   <example>
1041     # Serve stale data on error.<br />
1042     CacheStaleOnError on<br />
1043   </example>
1044
1045 </usage>
1046 </directivesynopsis>
1047
1048 </modulesynopsis>