2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
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
14 http://www.apache.org/licenses/LICENSE-2.0
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.
23 <modulesynopsis metafile="mod_cache.xml.meta">
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>
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
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>
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>
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
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>
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>
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>
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>
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>
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>
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>
117 <p>Further details, discussion, and examples, are provided in the
118 <a href="../caching.html">Caching Guide</a>.</p>
120 <seealso><a href="../caching.html">Caching Guide</a></seealso>
122 <section id="related"><title>Related Modules and Directives</title>
125 <module>mod_cache_disk</module>
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>
137 <section id="sampleconf"><title>Sample Configuration</title>
138 <example><title>Sample httpd.conf</title>
140 # Sample Cache Configuration<br />
142 LoadModule cache_module modules/mod_cache.so<br />
144 <IfModule mod_cache.c><br />
146 LoadModule cache_disk_module modules/mod_cache_disk.so<br />
147 <IfModule mod_cache_disk.c><br />
149 CacheRoot c:/cacheroot<br />
150 CacheEnable disk /<br />
151 CacheDirLevels 5<br />
152 CacheDirLength 3<br />
154 </IfModule> <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 />
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).
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.
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>
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
211 <title>Example configuration</title>
212 <example><title>Enabling the cache lock</title>
214 # Enable the cache lock<br />
216 <IfModule mod_cache.c><br />
219 CacheLockPath /tmp/mod_cache-lock<br />
220 CacheLockMaxAge 5<br />
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>
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
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>
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>
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>
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>
257 # Cache content before optional compression<br />
258 CacheQuickHandler off<br />
259 AddOutputFilterByType CACHE;DEFLATE text/plain<br /><br />
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>
268 # Cache content before mod_include and mod_deflate<br />
269 CacheQuickHandler off<br />
270 AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html<br /><br />
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>
279 # Cache content between mod_include and mod_deflate<br />
280 CacheQuickHandler off<br />
281 AddOutputFilterByType INCLUDES;CACHE;DEFLATE text/html<br /><br />
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>
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
301 LogFormat "%{cache-status}e ..."
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>
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>
316 <p>This makes it possible to support conditional logging of cached requests
317 as per the following example:</p>
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 />
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
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 <context>directory</context><context>.htaccess</context>
341 <p>The <directive>CacheEnable</directive> directive instructs
342 <module>mod_cache</module> to cache urls at or below
343 <var>url-string</var>. The cache storage manager is specified with the
344 <var>cache_type</var> argument. The <directive>CacheEnable</directive>
345 directive can alternatively be placed inside either
346 <directive type="section">Location</directive> or
347 <directive type="section">LocationMatch</directive> sections to indicate
348 the content is cacheable.
349 <var>cache_type</var> <code>disk</code> instructs
350 <module>mod_cache</module> to use the disk based storage manager
351 implemented by <module>mod_cache_disk</module>.</p>
352 <p>In the event that the URL space overlaps between different
353 <directive>CacheEnable</directive> directives (as in the example below),
354 each possible storage manager will be run until the first one that
355 actually processes the request. The order in which the storage managers are
356 run is determined by the order of the <directive>CacheEnable</directive>
357 directives in the configuration file. <directive>CacheEnable</directive>
358 directives within <directive type="section">Location</directive> or
359 <directive type="section">LocationMatch</directive> sections are processed
360 before globally defined <directive>CacheEnable</directive> directives.</p>
362 <p>When acting as a forward proxy server, <var>url-string</var> can
363 also be used to specify remote sites and proxy protocols which
364 caching should be enabled for.</p>
367 # Cache content<br />
368 <Location /foo><br />
370 CacheEnable disk<br />
372 </Location><br /><br />
374 <LocationMatch foo$><br />
376 CacheEnable disk<br />
378 </LocationMatch><br /><br />
379 # Cache proxied url's<br />
380 CacheEnable disk /<br /><br />
381 # Cache FTP-proxied url's<br />
382 CacheEnable disk ftp://<br /><br />
383 # Cache content from www.example.org<br />
384 CacheEnable disk http://www.example.org/<br />
387 <p>A hostname starting with a <strong>"*"</strong> matches all hostnames with
388 that suffix. A hostname starting with <strong>"."</strong> matches all
389 hostnames containing the domain components that follow.</p>
392 # Match www.example.org, and fooexample.org<br />
393 CacheEnable disk http://*example.org/<br />
394 # Match www.example.org, but not fooexample.org<br />
395 CacheEnable disk http://.example.org/<br />
398 <p> The <code>no-cache</code> environment variable can be set to
399 disable caching on a finer grained set of resources in versions
400 2.2.12 and later.</p>
403 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
407 <name>CacheDisable</name>
408 <description>Disable caching of specified URLs</description>
409 <syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
410 <contextlist><context>server config</context><context>virtual host</context>
411 <context>directory</context><context>.htaccess</context>
415 <p>The <directive>CacheDisable</directive> directive instructs
416 <module>mod_cache</module> to <em>not</em> cache urls at or below
417 <var>url-string</var>.</p>
419 <example><title>Example</title>
420 CacheDisable /local_files
423 <p>If used in a <directive type="section">Location</directive> directive,
424 the path needs to be specified below the Location, or if the word "on"
425 is used, caching for the whole location will be disabled.</p>
427 <example><title>Example</title>
428 <Location /foo><br />
430 CacheDisable on<br />
432 </Location><br />
435 <p>The <code>no-cache</code> environment variable can be set to
436 disable caching on a finer grained set of resources in versions
437 2.2.12 and later.</p>
440 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
443 <name>CacheMaxExpire</name>
444 <description>The maximum time in seconds to cache a document</description>
445 <syntax>CacheMaxExpire <var>seconds</var></syntax>
446 <default>CacheMaxExpire 86400 (one day)</default>
447 <contextlist><context>server config</context>
448 <context>virtual host</context>
449 <context>directory</context>
450 <context>.htaccess</context>
454 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
455 seconds for which cachable HTTP documents will be retained without checking the origin
456 server. Thus, documents will be out of date at most this number of seconds. This maximum
457 value is enforced even if an expiry date was supplied with the document.</p>
460 CacheMaxExpire 604800
466 <name>CacheMinExpire</name>
467 <description>The minimum time in seconds to cache a document</description>
468 <syntax>CacheMinExpire <var>seconds</var></syntax>
469 <default>CacheMinExpire 0</default>
470 <contextlist><context>server config</context>
471 <context>virtual host</context>
472 <context>directory</context>
473 <context>.htaccess</context>
477 <p>The <directive>CacheMinExpire</directive> directive specifies the minimum number of
478 seconds for which cachable HTTP documents will be retained without checking the origin
479 server. This is only used if no valid expire time was supplied with the document.</p>
489 <name>CacheDefaultExpire</name>
490 <description>The default duration to cache a document when no expiry date is specified.</description>
491 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
492 <default>CacheDefaultExpire 3600 (one hour)</default>
493 <contextlist><context>server config</context>
494 <context>virtual host</context>
495 <context>directory</context>
496 <context>.htaccess</context>
500 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
501 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
502 with the document. The value specified with the <directive>CacheMaxExpire</directive>
503 directive does <em>not</em> override this setting.</p>
506 CacheDefaultExpire 86400
512 <name>CacheIgnoreNoLastMod</name>
513 <description>Ignore the fact that a response has no Last Modified
514 header.</description>
515 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
516 <default>CacheIgnoreNoLastMod Off</default>
517 <contextlist><context>server config</context>
518 <context>virtual host</context>
519 <context>directory</context>
520 <context>.htaccess</context>
524 <p>Ordinarily, documents without a last-modified date are not cached.
525 Under some circumstances the last-modified date is removed (during
526 <module>mod_include</module> processing for example) or not provided
527 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
528 provides a way to specify that documents without last-modified dates
529 should be considered for caching, even without a last-modified date.
530 If neither a last-modified date nor an expiry date are provided with
531 the document then the value specified by the
532 <directive>CacheDefaultExpire</directive> directive will be used to
533 generate an expiration date.</p>
536 CacheIgnoreNoLastMod On
542 <name>CacheIgnoreCacheControl</name>
543 <description>Ignore request to not serve cached content to client</description>
544 <syntax>CacheIgnoreCacheControl On|Off</syntax>
545 <default>CacheIgnoreCacheControl Off</default>
546 <contextlist><context>server config</context><context>virtual host</context>
550 <p>Ordinarily, requests containing a Cache-Control: no-cache or
551 Pragma: no-cache header value will not be served from the cache. The
552 <directive>CacheIgnoreCacheControl</directive> directive allows this
553 behavior to be overridden. <directive>CacheIgnoreCacheControl On</directive>
554 tells the server to attempt to serve the resource from the cache even
555 if the request contains no-cache header values. Resources requiring
556 authorization will <em>never</em> be cached.</p>
559 CacheIgnoreCacheControl On
562 <note type="warning"><title>Warning:</title>
563 This directive will allow serving from the cache even if the client has
564 requested that the document not be served from the cache. This might
565 result in stale content being served.
568 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
569 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
573 <name>CacheIgnoreQueryString</name>
574 <description>Ignore query string when caching</description>
575 <syntax>CacheIgnoreQueryString On|Off</syntax>
576 <default>CacheIgnoreQueryString Off</default>
577 <contextlist><context>server config</context><context>virtual host</context>
581 <p>Ordinarily, requests with query string parameters are cached separately
582 for each unique query string. This is according to RFC 2616/13.9 done only
583 if an expiration time is specified. The
584 <directive>CacheIgnoreQueryString</directive> directive tells the cache to
585 cache requests even if no expiration time is specified, and to reply with
586 a cached reply even if the query string differs. From a caching point of
587 view the request is treated as if having no query string when this
588 directive is enabled.</p>
591 CacheIgnoreQueryString On
598 <name>CacheLastModifiedFactor</name>
599 <description>The factor used to compute an expiry date based on the
600 LastModified date.</description>
601 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
602 <default>CacheLastModifiedFactor 0.1</default>
603 <contextlist><context>server config</context>
604 <context>virtual host</context>
605 <context>directory</context>
606 <context>.htaccess</context>
610 <p>In the event that a document does not provide an expiry date but does
611 provide a last-modified date, an expiry date can be calculated based on
612 the time since the document was last modified. The
613 <directive>CacheLastModifiedFactor</directive> directive specifies a
614 <var>factor</var> to be used in the generation of this expiry date
615 according to the following formula:
617 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
618 expiry-date = current-date + expiry-period</code>
620 For example, if the document was last modified 10 hours ago, and
621 <var>factor</var> is 0.1 then the expiry-period will be set to
622 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
623 expiry-date would be 3:00pm + 1hour = 4:00pm.
625 If the expiry-period would be longer than that set by
626 <directive>CacheMaxExpire</directive>, then the latter takes
630 CacheLastModifiedFactor 0.5
636 <name>CacheIgnoreHeaders</name>
637 <description>Do not store the given HTTP header(s) in the cache.
639 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
640 <default>CacheIgnoreHeaders None</default>
641 <contextlist><context>server config</context><context>virtual host</context>
645 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
646 the cache. The following HTTP headers are hop-by-hop headers and thus
647 do not get stored in the cache in <em>any</em> case regardless of the
648 setting of <directive>CacheIgnoreHeaders</directive>:</p>
651 <li><code>Connection</code></li>
652 <li><code>Keep-Alive</code></li>
653 <li><code>Proxy-Authenticate</code></li>
654 <li><code>Proxy-Authorization</code></li>
655 <li><code>TE</code></li>
656 <li><code>Trailers</code></li>
657 <li><code>Transfer-Encoding</code></li>
658 <li><code>Upgrade</code></li>
661 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
662 headers that should not to be stored in the cache. For example, it makes
663 sense in some cases to prevent cookies from being stored in the cache.</p>
665 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
666 of HTTP headers that should not be stored in the cache. If only hop-by-hop
667 headers not should be stored in the cache (the RFC 2616 compliant
668 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
669 <code>None</code>.</p>
671 <example><title>Example 1</title>
672 CacheIgnoreHeaders Set-Cookie
675 <example><title>Example 2</title>
676 CacheIgnoreHeaders None
679 <note type="warning"><title>Warning:</title>
680 If headers like <code>Expires</code> which are needed for proper cache
681 management are not stored due to a
682 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
683 mod_cache is undefined.
689 <name>CacheIgnoreURLSessionIdentifiers</name>
690 <description>Ignore defined session identifiers encoded in the URL when caching
692 <syntax>CacheIgnoreURLSessionIdentifiers <var>identifier</var> [<var>identifier</var>] ...</syntax>
693 <default>CacheIgnoreURLSessionIdentifiers None</default>
694 <contextlist><context>server config</context><context>virtual host</context>
698 <p>Sometimes applications encode the session identifier into the URL like in the following
702 <li><code>/someapplication/image.gif;jsessionid=123456789</code></li>
703 <li><code>/someapplication/image.gif?PHPSESSIONID=12345678</code></li>
705 <p>This causes cachable resources to be stored separately for each session, which
706 is often not desired. <directive>CacheIgnoreURLSessionIdentifiers</directive> lets
707 define a list of identifiers that are removed from the key that is used to identify
708 an entity in the cache, such that cachable resources are not stored separately for
711 <p><code>CacheIgnoreURLSessionIdentifiers None</code> clears the list of ignored
712 identifiers. Otherwise, each identifier is added to the list.</p>
714 <example><title>Example 1</title>
715 CacheIgnoreURLSessionIdentifiers jsessionid
718 <example><title>Example 2</title>
719 CacheIgnoreURLSessionIdentifiers None
726 <name>CacheStoreExpired</name>
727 <description>Attempt to cache responses that the server reports as expired</description>
728 <syntax>CacheStoreExpired On|Off</syntax>
729 <default>CacheStoreExpired Off</default>
730 <contextlist><context>server config</context>
731 <context>virtual host</context>
732 <context>directory</context>
733 <context>.htaccess</context>
737 <p>Since httpd 2.2.4, responses which have already expired are not
738 stored in the cache. The <directive>CacheStoreExpired</directive>
739 directive allows this behavior to be overridden.
740 <directive>CacheStoreExpired</directive> On
741 tells the server to attempt to cache the resource if it is stale.
742 Subsequent requests would trigger an If-Modified-Since request of
743 the origin server, and the response may be fulfilled from cache
744 if the backend resource has not changed.</p>
753 <name>CacheStorePrivate</name>
754 <description>Attempt to cache responses that the server has marked as private</description>
755 <syntax>CacheStorePrivate On|Off</syntax>
756 <default>CacheStorePrivate Off</default>
757 <contextlist><context>server config</context>
758 <context>virtual host</context>
759 <context>directory</context>
760 <context>.htaccess</context>
764 <p>Ordinarily, responses with Cache-Control: private header values will not
765 be stored in the cache. The <directive>CacheStorePrivate</directive>
766 directive allows this behavior to be overridden.
767 <directive>CacheStorePrivate</directive> On
768 tells the server to attempt to cache the resource even if it contains
769 private header values. Resources requiring authorization will
770 <em>never</em> be cached.</p>
776 <note type="warning"><title>Warning:</title>
777 This directive will allow caching even if the upstream server has
778 requested that the resource not be cached. This directive is only
779 ideal for a 'private' cache.
782 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
783 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
787 <name>CacheStoreNoStore</name>
788 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
789 <syntax>CacheStoreNoStore On|Off</syntax>
790 <default>CacheStoreNoStore Off</default>
791 <contextlist><context>server config</context>
792 <context>virtual host</context>
793 <context>directory</context>
794 <context>.htaccess</context>
798 <p>Ordinarily, requests or responses with Cache-Control: no-store header
799 values will not be stored in the cache. The
800 <directive>CacheStoreNoCache</directive> directive allows this
801 behavior to be overridden. <directive>CacheStoreNoCache</directive> On
802 tells the server to attempt to cache the resource even if it contains
803 no-store header values. Resources requiring authorization will
804 <em>never</em> be cached.</p>
810 <note type="warning"><title>Warning:</title>
811 As described in RFC 2616, the no-store directive is intended to
812 "prevent the inadvertent release or retention of sensitive information
813 (for example, on backup tapes)." Enabling this option could store
814 sensitive information in the cache. You are hereby warned.
817 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
818 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
822 <name>CacheLock</name>
823 <description>Enable the thundering herd lock.</description>
824 <syntax>CacheLock <var>on|off</var></syntax>
825 <default>CacheLock off</default>
826 <contextlist><context>server config</context><context>virtual host</context>
828 <compatibility>Available in Apache 2.2.15 and later</compatibility>
831 <p>The <directive>CacheLock</directive> directive enables the thundering herd lock
832 for the given URL space.</p>
834 <p>In a minimal configuration the following directive is all that is needed to
835 enable the thundering herd lock in the default system temp directory.</p>
838 # Enable cache lock<br />
839 CacheLock on<br /><br />
846 <name>CacheLockPath</name>
847 <description>Set the lock path directory.</description>
848 <syntax>CacheLockPath <var>directory</var></syntax>
849 <default>CacheLockPath /tmp/mod_cache-lock</default>
850 <contextlist><context>server config</context><context>virtual host</context>
854 <p>The <directive>CacheLockPath</directive> directive allows you to specify the
855 directory in which the locks are created. By default, the system's temporary
856 folder is used. Locks consist of empty files that only exist for stale URLs
857 in flight, so is significantly less resource intensive than the traditional
864 <name>CacheLockMaxAge</name>
865 <description>Set the maximum possible age of a cache lock.</description>
866 <syntax>CacheLockMaxAge <var>integer</var></syntax>
867 <default>CacheLockMaxAge 5</default>
868 <contextlist><context>server config</context><context>virtual host</context>
872 <p>The <directive>CacheLockMaxAge</directive> directive specifies the maximum
873 age of any cache lock.</p>
875 <p>A lock older than this value in seconds will be ignored, and the next
876 incoming request will be given the opportunity to re-establish the lock.
877 This mechanism prevents a slow client taking an excessively long time to refresh
884 <name>CacheQuickHandler</name>
885 <description>Run the cache from the quick handler.</description>
886 <syntax>CacheQuickHandler <var>on|off</var></syntax>
887 <default>CacheQuickHandler on</default>
888 <contextlist><context>server config</context><context>virtual host</context>
890 <compatibility>Apache HTTP Server 2.3.3 and later</compatibility>
893 <p>The <directive module="mod_cache">CacheQuickHandler</directive> directive
894 controls the phase in which the cache is handled.</p>
896 <p>In the default enabled configuration, the cache operates within the quick
897 handler phase. This phase short circuits the majority of server processing,
898 and represents the most performant mode of operation for a typical server.
899 The cache <strong>bolts onto</strong> the front of the server, and the
900 majority of server processing is avoided.</p>
902 <p>When disabled, the cache operates as a normal handler, and is subject to
903 the full set of phases when handling a server request. While this mode is
904 slower than the default, it allows the cache to be used in cases where full
905 processing is required, such as when content is subject to authorisation.</p>
908 # Run cache as a normal handler<br />
909 CacheQuickHandler off<br /><br />
912 <p>It is also possible, when the quick handler is disabled, for the
913 administrator to choose the precise location within the filter chain where
914 caching is to be performed, by adding the <strong>CACHE</strong> filter to
918 # Cache content before mod_include and mod_deflate<br />
919 CacheQuickHandler off<br />
920 AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html<br /><br />
923 <p>If the CACHE filter is specified more than once, the last instance will
930 <name>CacheHeader</name>
931 <description>Add an X-Cache header to the response.</description>
932 <syntax>CacheHeader <var>on|off</var></syntax>
933 <default>CacheHeader off</default>
934 <contextlist><context>server config</context>
935 <context>virtual host</context>
936 <context>directory</context>
937 <context>.htaccess</context>
939 <compatibility>Available in Apache 2.3.9 and later</compatibility>
942 <p>When the <directive module="mod_cache">CacheHeader</directive> directive
943 is switched on, an <strong>X-Cache</strong> header will be added to the response
944 with the cache status of this response. If the normal handler is used, this
945 directive may appear within a <directive module="core"><Directory></directive>
946 or <directive module="core"><Location></directive> directive. If the quick
947 handler is used, this directive must appear within a server or virtual host
948 context, otherwise the setting will be ignored.</p>
951 <dt><strong>HIT</strong></dt><dd>The entity was fresh, and was served from
953 <dt><strong>REVALIDATE</strong></dt><dd>The entity was stale, was successfully
954 revalidated and was served from cache.</dd>
955 <dt><strong>MISS</strong></dt><dd>The entity was fetched from the upstream
956 server and was not served from cache.</dd>
960 # Enable the X-Cache header<br />
965 X-Cache: HIT from localhost<br />
972 <name>CacheDetailHeader</name>
973 <description>Add an X-Cache-Detail header to the response.</description>
974 <syntax>CacheDetailHeader <var>on|off</var></syntax>
975 <default>CacheDetailHeader off</default>
976 <contextlist><context>server config</context>
977 <context>virtual host</context>
978 <context>directory</context>
979 <context>.htaccess</context>
981 <compatibility>Available in Apache 2.3.9 and later</compatibility>
984 <p>When the <directive module="mod_cache">CacheDetailHeader</directive> directive
985 is switched on, an <strong>X-Cache-Detail</strong> header will be added to the response
986 containing the detailed reason for a particular caching decision.</p>
988 <p>It can be useful during development of cached RESTful services to have additional
989 information about the caching decision written to the response headers, so as to
990 confirm whether <code>Cache-Control</code> and other headers have been correctly
991 used by the service and client.</p>
993 <p>If the normal handler is used, this directive may appear within a
994 <directive module="core"><Directory></directive> or
995 <directive module="core"><Location></directive> directive. If the quick handler
996 is used, this directive must appear within a server or virtual host context, otherwise
997 the setting will be ignored.</p>
1000 # Enable the X-Cache-Detail header<br />
1001 CacheDetailHeader on<br />
1005 X-Cache-Detail: "conditional cache hit: entity refreshed" from localhost<br />
1009 </directivesynopsis>
1012 <name>CacheKeyBaseURL</name>
1013 <description>Override the base URL of reverse proxied cache keys.</description>
1014 <syntax>CacheKeyBaseURL <var>URL</var></syntax>
1015 <default>CacheKeyBaseURL http://example.com</default>
1016 <contextlist><context>server config</context>
1017 <context>virtual host</context>
1019 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1022 <p>When the <directive module="mod_cache">CacheKeyBaseURL</directive> directive
1023 is specified, the URL provided will be used as the base URL to calculate
1024 the URL of the cache keys in the reverse proxy configuration. When not specified,
1025 the scheme, hostname and port of the current virtual host is used to construct
1026 the cache key. When a cluster of machines is present, and all cached entries
1027 should be cached beneath the same cache key, a new base URL can be specified
1028 with this directive.</p>
1031 # Override the base URL of the cache key.<br />
1032 CacheKeyBaseURL http://www.example.com/<br />
1035 <note type="warning">Take care when setting this directive. If two separate virtual
1036 hosts are accidentally given the same base URL, entries from one virtual host
1037 will be served to the other.</note>
1040 </directivesynopsis>
1043 <name>CacheStaleOnError</name>
1044 <description>Serve stale content in place of 5xx responses.</description>
1045 <syntax>CacheStaleOnError <var>on|off</var></syntax>
1046 <default>CacheStaleOnError on</default>
1047 <contextlist><context>server config</context>
1048 <context>virtual host</context>
1049 <context>directory</context>
1050 <context>.htaccess</context>
1052 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1055 <p>When the <directive module="mod_cache">CacheStaleOnError</directive> directive
1056 is switched on, and when stale data is available in the cache, the cache will
1057 respond to 5xx responses from the backend by returning the stale data instead of
1058 the 5xx response. While the Cache-Control headers sent by clients will be respected,
1059 and the raw 5xx responses returned to the client on request, the 5xx response so
1060 returned to the client will not invalidate the content in the cache.</p>
1063 # Serve stale data on error.<br />
1064 CacheStaleOnError on<br />
1068 </directivesynopsis>