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_access_compat">Allow</directive> and <directive
36 module="mod_access_compat">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>
115 <dt><module>mod_cache_socache</module></dt>
116 <dd>Implements a shared object cache based storage manager. Headers and
117 bodies are stored together beneath a single key based on the URL of the
118 response being cached. Multiple content negotiated responses can
119 be stored concurrently, however the caching of partial content is not
120 supported by this module.</dd>
123 <p>Further details, discussion, and examples, are provided in the
124 <a href="../caching.html">Caching Guide</a>.</p>
126 <seealso><a href="../caching.html">Caching Guide</a></seealso>
128 <section id="related"><title>Related Modules and Directives</title>
131 <module>mod_cache_disk</module>
132 <module>mod_cache_socache</module>
135 <directive module="mod_cache_disk">CacheRoot</directive>
136 <directive module="mod_cache_disk">CacheDirLevels</directive>
137 <directive module="mod_cache_disk">CacheDirLength</directive>
138 <directive module="mod_cache_disk">CacheMinFileSize</directive>
139 <directive module="mod_cache_disk">CacheMaxFileSize</directive>
140 <directive module="mod_cache_socache">CacheSocache</directive>
141 <directive module="mod_cache_socache">CacheSocacheMaxTime</directive>
142 <directive module="mod_cache_socache">CacheSocacheMinTime</directive>
143 <directive module="mod_cache_socache">CacheSocacheMaxSize</directive>
144 <directive module="mod_cache_socache">CacheSocacheReadSize</directive>
145 <directive module="mod_cache_socache">CacheSocacheReadTime</directive>
150 <section id="sampleconf"><title>Sample Configuration</title>
151 <example><title>Sample httpd.conf</title>
152 <highlight language="config">
154 # Sample Cache Configuration
156 LoadModule cache_module modules/mod_cache.so
157 <IfModule mod_cache.c>
158 LoadModule cache_disk_module modules/mod_cache_disk.so
159 <IfModule mod_cache_disk.c>
160 CacheRoot c:/cacheroot
166 # When acting as a proxy, don't cache the list of security updates
167 CacheDisable http://security.update.server/update-list/
173 <section id="thunderingherd"><title>Avoiding the Thundering Herd</title>
174 <p>When a cached entry becomes stale, <module>mod_cache</module> will submit
175 a conditional request to the backend, which is expected to confirm whether the
176 cached entry is still fresh, and send an updated entity if not.</p>
177 <p>A small but finite amount of time exists between the time the cached entity
178 becomes stale, and the time the stale entity is fully refreshed. On a busy
179 server, a significant number of requests might arrive during this time, and
180 cause a <strong>thundering herd</strong> of requests to strike the backend
181 suddenly and unpredictably.</p>
182 <p>To keep the thundering herd at bay, the <directive>CacheLock</directive>
183 directive can be used to define a directory in which locks are created for
184 URLs <strong>in flight</strong>. The lock is used as a <strong>hint</strong>
185 by other requests to either suppress an attempt to cache (someone else has
186 gone to fetch the entity), or to indicate that a stale entry is being refreshed
187 (stale content will be returned in the mean time).
190 <title>Initial caching of an entry</title>
191 <p>When an entity is cached for the first time, a lock will be created for the
192 entity until the response has been fully cached. During the lifetime of the
193 lock, the cache will suppress the second and subsequent attempt to cache the
194 same entity. While this doesn't hold back the thundering herd, it does stop
195 the cache attempting to cache the same entity multiple times simultaneously.
199 <title>Refreshment of a stale entry</title>
200 <p>When an entity reaches its freshness lifetime and becomes stale, a lock
201 will be created for the entity until the response has either been confirmed as
202 still fresh, or replaced by the backend. During the lifetime of the lock, the
203 second and subsequent incoming request will cause stale data to be returned,
204 and the thundering herd is kept at bay.</p>
207 <title>Locks and Cache-Control: no-cache</title>
208 <p>Locks are used as a <strong>hint only</strong> to enable the cache to be
209 more gentle on backend servers, however the lock can be overridden if necessary.
210 If the client sends a request with a Cache-Control header forcing a reload, any
211 lock that may be present will be ignored, and the client's request will be
212 honored immediately and the cached entry refreshed.</p>
213 <p>As a further safety mechanism, locks have a configurable maximum age.
214 Once this age has been reached, the lock is removed, and a new request is
215 given the opportunity to create a new lock. This maximum age can be set using
216 the <directive>CacheLockMaxAge</directive> directive, and defaults to 5
221 <title>Example configuration</title>
222 <example><title>Enabling the cache lock</title>
223 <highlight language="config">
225 # Enable the cache lock
227 <IfModule mod_cache.c>
229 CacheLockPath /tmp/mod_cache-lock
237 <section id="finecontrol"><title>Fine Control with the CACHE Filter</title>
238 <p>Under the default mode of cache operation, the cache runs as a quick handler,
239 short circuiting the majority of server processing and offering the highest
240 cache performance available.</p>
242 <p>In this mode, the cache <strong>bolts onto</strong> the front of the server,
243 acting as if a free standing RFC 2616 caching proxy had been placed in front of
246 <p>While this mode offers the best performance, the administrator may find that
247 under certain circumstances they may want to perform further processing on the
248 request after the request is cached, such as to inject personalisation into the
249 cached page, or to apply authorisation restrictions to the content. Under these
250 circumstances, an administrator is often forced to place independent reverse
251 proxy servers either behind or in front of the caching server to achieve this.</p>
253 <p>To solve this problem the <directive module="mod_cache">CacheQuickHandler
254 </directive> directive can be set to <strong>off</strong>, and the server will
255 process all phases normally handled by a non-cached request, including the
256 <strong>authentication and authorisation</strong> phases.</p>
258 <p>In addition, the administrator may optionally specify the <strong>precise point
259 within the filter chain</strong> where caching is to take place by adding the
260 <strong>CACHE</strong> filter to the output filter chain.</p>
262 <p>For example, to cache content before applying compression to the response,
263 place the <strong>CACHE</strong> filter before the <strong>DEFLATE</strong>
264 filter as in the example below:</p>
266 <highlight language="config">
267 # Cache content before optional compression
268 CacheQuickHandler off
269 AddOutputFilterByType CACHE;DEFLATE text/plain
272 <p>Another option is to have content cached before personalisation is applied
273 by <module>mod_include</module> (or another content processing filter). In this
274 example templates containing tags understood by
275 <module>mod_include</module> are cached before being parsed:</p>
277 <highlight language="config">
278 # Cache content before mod_include and mod_deflate
279 CacheQuickHandler off
280 AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html
283 <p>You may place the <strong>CACHE</strong> filter anywhere you wish within the
284 filter chain. In this example, content is cached after being parsed by
285 <module>mod_include</module>, but before being processed by
286 <module>mod_deflate</module>:</p>
288 <highlight language="config">
289 # Cache content between mod_include and mod_deflate
290 CacheQuickHandler off
291 AddOutputFilterByType INCLUDES;CACHE;DEFLATE text/html
294 <note type="warning"><title>Warning:</title>If the location of the
295 <strong>CACHE</strong> filter in the filter chain is changed for any reason,
296 you may need to <strong>flush your cache</strong> to ensure that your data
297 served remains consistent. <module>mod_cache</module> is not in a position
298 to enforce this for you.</note>
302 <section id="status"><title>Cache Status and Logging</title>
303 <p>Once <module>mod_cache</module> has made a decision as to whether or not
304 an entity is to be served from cache, the detailed reason for the decision
305 is written to the subprocess environment within the request under the
306 <strong>cache-status</strong> key. This reason can be logged by the
307 <directive module="mod_log_config">LogFormat</directive> directive as
310 <highlight language="config">
311 LogFormat "%{cache-status}e ..."
314 <p>Based on the caching decision made, the reason is also written to the
315 subprocess environment under one the following four keys, as appropriate:</p>
318 <dt>cache-hit</dt><dd>The response was served from cache.</dd>
319 <dt>cache-revalidate</dt><dd>The response was stale and was successfully
320 revalidated, then served from cache.</dd>
321 <dt>cache-miss</dt><dd>The response was served from the upstream server.</dd>
322 <dt>cache-invalidate</dt><dd>The cached entity was invalidated by a request
323 method other than GET or HEAD.</dd>
326 <p>This makes it possible to support conditional logging of cached requests
327 as per the following example:</p>
329 <highlight language="config">
330 CustomLog cached-requests.log common env=cache-hit
331 CustomLog uncached-requests.log common env=cache-miss
332 CustomLog revalidated-requests.log common env=cache-revalidate
333 CustomLog invalidated-requests.log common env=cache-invalidate
336 <p>For module authors, a hook called <var>cache_status</var> is available,
337 allowing modules to respond to the caching outcomes above in customised
342 <name>CacheEnable</name>
343 <description>Enable caching of specified URLs using a specified storage
344 manager</description>
345 <syntax>CacheEnable <var>cache_type</var> [<var>url-string</var>]</syntax>
346 <contextlist><context>server config</context><context>virtual host</context>
347 <context>directory</context><context>.htaccess</context>
351 <p>The <directive>CacheEnable</directive> directive instructs
352 <module>mod_cache</module> to cache urls at or below
353 <var>url-string</var>. The cache storage manager is specified with the
354 <var>cache_type</var> argument. The <directive>CacheEnable</directive>
355 directive can alternatively be placed inside either
356 <directive type="section">Location</directive> or
357 <directive type="section">LocationMatch</directive> sections to indicate
358 the content is cacheable.
359 <var>cache_type</var> <code>disk</code> instructs
360 <module>mod_cache</module> to use the disk based storage manager
361 implemented by <module>mod_cache_disk</module>. <var>cache_type</var>
362 <code>socache</code> instructs <module>mod_cache</module> to use the
363 shared object cache based storage manager implemented by
364 <module>mod_cache_socache</module>.</p>
365 <p>In the event that the URL space overlaps between different
366 <directive>CacheEnable</directive> directives (as in the example below),
367 each possible storage manager will be run until the first one that
368 actually processes the request. The order in which the storage managers are
369 run is determined by the order of the <directive>CacheEnable</directive>
370 directives in the configuration file. <directive>CacheEnable</directive>
371 directives within <directive type="section">Location</directive> or
372 <directive type="section">LocationMatch</directive> sections are processed
373 before globally defined <directive>CacheEnable</directive> directives.</p>
375 <p>When acting as a forward proxy server, <var>url-string</var> can
376 also be used to specify remote sites and proxy protocols which
377 caching should be enabled for.</p>
379 <highlight language="config">
380 # Cache content (normal handler only)
381 CacheQuickHandler off
382 <Location /foo>
386 # Cache regex (normal handler only)
387 CacheQuickHandler off
388 <LocationMatch foo$>
390 </LocationMatch>
392 # Cache proxied url's (normal or quick handler)
395 # Cache FTP-proxied url's (normal or quick handler)
396 CacheEnable disk ftp://
398 # Cache content from www.example.org (normal or quick handler)
399 CacheEnable disk http://www.example.org/
402 <p>A hostname starting with a <strong>"*"</strong> matches all hostnames with
403 that suffix. A hostname starting with <strong>"."</strong> matches all
404 hostnames containing the domain components that follow.</p>
406 <highlight language="config">
407 # Match www.example.org, and fooexample.org
408 CacheEnable disk http://*example.org/
409 # Match www.example.org, but not fooexample.org
410 CacheEnable disk http://.example.org/
413 <p> The <code>no-cache</code> environment variable can be set to
414 disable caching on a finer grained set of resources in versions
415 2.2.12 and later.</p>
418 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
422 <name>CacheDisable</name>
423 <description>Disable caching of specified URLs</description>
424 <syntax>CacheDisable <var>url-string</var> | <var>on</var></syntax>
425 <contextlist><context>server config</context><context>virtual host</context>
426 <context>directory</context><context>.htaccess</context>
430 <p>The <directive>CacheDisable</directive> directive instructs
431 <module>mod_cache</module> to <em>not</em> cache urls at or below
432 <var>url-string</var>.</p>
434 <example><title>Example</title>
435 <highlight language="config">
436 CacheDisable /local_files
440 <p>If used in a <directive type="section">Location</directive> directive,
441 the path needs to be specified below the Location, or if the word "on"
442 is used, caching for the whole location will be disabled.</p>
444 <example><title>Example</title>
445 <highlight language="config">
446 <Location /foo>
452 <p>The <code>no-cache</code> environment variable can be set to
453 disable caching on a finer grained set of resources in versions
454 2.2.12 and later.</p>
457 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
460 <name>CacheMaxExpire</name>
461 <description>The maximum time in seconds to cache a document</description>
462 <syntax>CacheMaxExpire <var>seconds</var></syntax>
463 <default>CacheMaxExpire 86400 (one day)</default>
464 <contextlist><context>server config</context>
465 <context>virtual host</context>
466 <context>directory</context>
467 <context>.htaccess</context>
471 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
472 seconds for which cachable HTTP documents will be retained without checking the origin
473 server. Thus, documents will be out of date at most this number of seconds. This maximum
474 value is enforced even if an expiry date was supplied with the document.</p>
476 <highlight language="config">
477 CacheMaxExpire 604800
483 <name>CacheMinExpire</name>
484 <description>The minimum time in seconds to cache a document</description>
485 <syntax>CacheMinExpire <var>seconds</var></syntax>
486 <default>CacheMinExpire 0</default>
487 <contextlist><context>server config</context>
488 <context>virtual host</context>
489 <context>directory</context>
490 <context>.htaccess</context>
494 <p>The <directive>CacheMinExpire</directive> directive specifies the minimum number of
495 seconds for which cachable HTTP documents will be retained without checking the origin
496 server. This is only used if no valid expire time was supplied with the document.</p>
499 <highlight language="config">
506 <name>CacheDefaultExpire</name>
507 <description>The default duration to cache a document when no expiry date is specified.</description>
508 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
509 <default>CacheDefaultExpire 3600 (one hour)</default>
510 <contextlist><context>server config</context>
511 <context>virtual host</context>
512 <context>directory</context>
513 <context>.htaccess</context>
517 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
518 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
519 with the document. The value specified with the <directive>CacheMaxExpire</directive>
520 directive does <em>not</em> override this setting.</p>
522 <highlight language="config">
523 CacheDefaultExpire 86400
529 <name>CacheIgnoreNoLastMod</name>
530 <description>Ignore the fact that a response has no Last Modified
531 header.</description>
532 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
533 <default>CacheIgnoreNoLastMod Off</default>
534 <contextlist><context>server config</context>
535 <context>virtual host</context>
536 <context>directory</context>
537 <context>.htaccess</context>
541 <p>Ordinarily, documents without a last-modified date are not cached.
542 Under some circumstances the last-modified date is removed (during
543 <module>mod_include</module> processing for example) or not provided
544 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
545 provides a way to specify that documents without last-modified dates
546 should be considered for caching, even without a last-modified date.
547 If neither a last-modified date nor an expiry date are provided with
548 the document then the value specified by the
549 <directive>CacheDefaultExpire</directive> directive will be used to
550 generate an expiration date.</p>
552 <highlight language="config">
553 CacheIgnoreNoLastMod On
559 <name>CacheIgnoreCacheControl</name>
560 <description>Ignore request to not serve cached content to client</description>
561 <syntax>CacheIgnoreCacheControl On|Off</syntax>
562 <default>CacheIgnoreCacheControl Off</default>
563 <contextlist><context>server config</context><context>virtual host</context>
567 <p>Ordinarily, requests containing a Cache-Control: no-cache or
568 Pragma: no-cache header value will not be served from the cache. The
569 <directive>CacheIgnoreCacheControl</directive> directive allows this
570 behavior to be overridden. <directive>CacheIgnoreCacheControl On</directive>
571 tells the server to attempt to serve the resource from the cache even
572 if the request contains no-cache header values. Resources requiring
573 authorization will <em>never</em> be cached.</p>
575 <highlight language="config">
576 CacheIgnoreCacheControl On
579 <note type="warning"><title>Warning:</title>
580 This directive will allow serving from the cache even if the client has
581 requested that the document not be served from the cache. This might
582 result in stale content being served.
585 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
586 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
590 <name>CacheIgnoreQueryString</name>
591 <description>Ignore query string when caching</description>
592 <syntax>CacheIgnoreQueryString On|Off</syntax>
593 <default>CacheIgnoreQueryString Off</default>
594 <contextlist><context>server config</context><context>virtual host</context>
598 <p>Ordinarily, requests with query string parameters are cached separately
599 for each unique query string. This is according to RFC 2616/13.9 done only
600 if an expiration time is specified. The
601 <directive>CacheIgnoreQueryString</directive> directive tells the cache to
602 cache requests even if no expiration time is specified, and to reply with
603 a cached reply even if the query string differs. From a caching point of
604 view the request is treated as if having no query string when this
605 directive is enabled.</p>
607 <highlight language="config">
608 CacheIgnoreQueryString On
615 <name>CacheLastModifiedFactor</name>
616 <description>The factor used to compute an expiry date based on the
617 LastModified date.</description>
618 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
619 <default>CacheLastModifiedFactor 0.1</default>
620 <contextlist><context>server config</context>
621 <context>virtual host</context>
622 <context>directory</context>
623 <context>.htaccess</context>
627 <p>In the event that a document does not provide an expiry date but does
628 provide a last-modified date, an expiry date can be calculated based on
629 the time since the document was last modified. The
630 <directive>CacheLastModifiedFactor</directive> directive specifies a
631 <var>factor</var> to be used in the generation of this expiry date
632 according to the following formula:
634 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
635 expiry-date = current-date + expiry-period</code>
637 For example, if the document was last modified 10 hours ago, and
638 <var>factor</var> is 0.1 then the expiry-period will be set to
639 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
640 expiry-date would be 3:00pm + 1hour = 4:00pm.
642 If the expiry-period would be longer than that set by
643 <directive>CacheMaxExpire</directive>, then the latter takes
646 <highlight language="config">
647 CacheLastModifiedFactor 0.5
653 <name>CacheIgnoreHeaders</name>
654 <description>Do not store the given HTTP header(s) in the cache.
656 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
657 <default>CacheIgnoreHeaders None</default>
658 <contextlist><context>server config</context><context>virtual host</context>
662 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
663 the cache. The following HTTP headers are hop-by-hop headers and thus
664 do not get stored in the cache in <em>any</em> case regardless of the
665 setting of <directive>CacheIgnoreHeaders</directive>:</p>
668 <li><code>Connection</code></li>
669 <li><code>Keep-Alive</code></li>
670 <li><code>Proxy-Authenticate</code></li>
671 <li><code>Proxy-Authorization</code></li>
672 <li><code>TE</code></li>
673 <li><code>Trailers</code></li>
674 <li><code>Transfer-Encoding</code></li>
675 <li><code>Upgrade</code></li>
678 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
679 headers that should not to be stored in the cache. For example, it makes
680 sense in some cases to prevent cookies from being stored in the cache.</p>
682 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
683 of HTTP headers that should not be stored in the cache. If only hop-by-hop
684 headers not should be stored in the cache (the RFC 2616 compliant
685 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
686 <code>None</code>.</p>
688 <example><title>Example 1</title>
689 <highlight language="config">
690 CacheIgnoreHeaders Set-Cookie
694 <example><title>Example 2</title>
695 <highlight language="config">
696 CacheIgnoreHeaders None
700 <note type="warning"><title>Warning:</title>
701 If headers like <code>Expires</code> which are needed for proper cache
702 management are not stored due to a
703 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
704 mod_cache is undefined.
710 <name>CacheIgnoreURLSessionIdentifiers</name>
711 <description>Ignore defined session identifiers encoded in the URL when caching
713 <syntax>CacheIgnoreURLSessionIdentifiers <var>identifier</var> [<var>identifier</var>] ...</syntax>
714 <default>CacheIgnoreURLSessionIdentifiers None</default>
715 <contextlist><context>server config</context><context>virtual host</context>
719 <p>Sometimes applications encode the session identifier into the URL like in the following
723 <li><code>/someapplication/image.gif;jsessionid=123456789</code></li>
724 <li><code>/someapplication/image.gif?PHPSESSIONID=12345678</code></li>
726 <p>This causes cachable resources to be stored separately for each session, which
727 is often not desired. <directive>CacheIgnoreURLSessionIdentifiers</directive> lets
728 define a list of identifiers that are removed from the key that is used to identify
729 an entity in the cache, such that cachable resources are not stored separately for
732 <p><code>CacheIgnoreURLSessionIdentifiers None</code> clears the list of ignored
733 identifiers. Otherwise, each identifier is added to the list.</p>
735 <example><title>Example 1</title>
736 <highlight language="config">
737 CacheIgnoreURLSessionIdentifiers jsessionid
741 <example><title>Example 2</title>
742 <highlight language="config">
743 CacheIgnoreURLSessionIdentifiers None
751 <name>CacheStoreExpired</name>
752 <description>Attempt to cache responses that the server reports as expired</description>
753 <syntax>CacheStoreExpired On|Off</syntax>
754 <default>CacheStoreExpired Off</default>
755 <contextlist><context>server config</context>
756 <context>virtual host</context>
757 <context>directory</context>
758 <context>.htaccess</context>
762 <p>Since httpd 2.2.4, responses which have already expired are not
763 stored in the cache. The <directive>CacheStoreExpired</directive>
764 directive allows this behavior to be overridden.
765 <directive>CacheStoreExpired</directive> On
766 tells the server to attempt to cache the resource if it is stale.
767 Subsequent requests would trigger an If-Modified-Since request of
768 the origin server, and the response may be fulfilled from cache
769 if the backend resource has not changed.</p>
771 <highlight language="config">
778 <name>CacheStorePrivate</name>
779 <description>Attempt to cache responses that the server has marked as private</description>
780 <syntax>CacheStorePrivate On|Off</syntax>
781 <default>CacheStorePrivate Off</default>
782 <contextlist><context>server config</context>
783 <context>virtual host</context>
784 <context>directory</context>
785 <context>.htaccess</context>
789 <p>Ordinarily, responses with Cache-Control: private header values will not
790 be stored in the cache. The <directive>CacheStorePrivate</directive>
791 directive allows this behavior to be overridden.
792 <directive>CacheStorePrivate</directive> On
793 tells the server to attempt to cache the resource even if it contains
794 private header values. Resources requiring authorization will
795 <em>never</em> be cached.</p>
797 <highlight language="config">
801 <note type="warning"><title>Warning:</title>
802 This directive will allow caching even if the upstream server has
803 requested that the resource not be cached. This directive is only
804 ideal for a 'private' cache.
807 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
808 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
812 <name>CacheStoreNoStore</name>
813 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
814 <syntax>CacheStoreNoStore On|Off</syntax>
815 <default>CacheStoreNoStore Off</default>
816 <contextlist><context>server config</context>
817 <context>virtual host</context>
818 <context>directory</context>
819 <context>.htaccess</context>
823 <p>Ordinarily, requests or responses with Cache-Control: no-store header
824 values will not be stored in the cache. The
825 <directive>CacheStoreNoStore</directive> directive allows this
826 behavior to be overridden. <directive>CacheStoreNoStore</directive> On
827 tells the server to attempt to cache the resource even if it contains
828 no-store header values. Resources requiring authorization will
829 <em>never</em> be cached.</p>
831 <highlight language="config">
835 <note type="warning"><title>Warning:</title>
836 As described in RFC 2616, the no-store directive is intended to
837 "prevent the inadvertent release or retention of sensitive information
838 (for example, on backup tapes)." Enabling this option could store
839 sensitive information in the cache. You are hereby warned.
842 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
843 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
847 <name>CacheLock</name>
848 <description>Enable the thundering herd lock.</description>
849 <syntax>CacheLock <var>on|off</var></syntax>
850 <default>CacheLock off</default>
851 <contextlist><context>server config</context><context>virtual host</context>
855 <p>The <directive>CacheLock</directive> directive enables the thundering herd lock
856 for the given URL space.</p>
858 <p>In a minimal configuration the following directive is all that is needed to
859 enable the thundering herd lock in the default run-time file directory.</p>
861 <highlight language="config">
866 <p>Locks consist of empty files that only exist for stale URLs in flight, so this
867 is significantly less resource intensive than the traditional disk cache.</p>
872 <name>CacheLockPath</name>
873 <description>Set the lock path directory.</description>
874 <syntax>CacheLockPath <var>directory</var></syntax>
875 <default>CacheLockPath mod_cache-lock</default>
876 <contextlist><context>server config</context><context>virtual host</context>
880 <p>The <directive>CacheLockPath</directive> directive allows you to specify the
881 directory in which the locks are created. If <var>directory</var> is not an absolute
882 path, the location specified will be relative to the value of
883 <directive module="core">DefaultRuntimeDir</directive>.</p>
888 <name>CacheLockMaxAge</name>
889 <description>Set the maximum possible age of a cache lock.</description>
890 <syntax>CacheLockMaxAge <var>integer</var></syntax>
891 <default>CacheLockMaxAge 5</default>
892 <contextlist><context>server config</context><context>virtual host</context>
896 <p>The <directive>CacheLockMaxAge</directive> directive specifies the maximum
897 age of any cache lock.</p>
899 <p>A lock older than this value in seconds will be ignored, and the next
900 incoming request will be given the opportunity to re-establish the lock.
901 This mechanism prevents a slow client taking an excessively long time to refresh
908 <name>CacheQuickHandler</name>
909 <description>Run the cache from the quick handler.</description>
910 <syntax>CacheQuickHandler <var>on|off</var></syntax>
911 <default>CacheQuickHandler on</default>
912 <contextlist><context>server config</context><context>virtual host</context>
914 <compatibility>Apache HTTP Server 2.3.3 and later</compatibility>
917 <p>The <directive module="mod_cache">CacheQuickHandler</directive> directive
918 controls the phase in which the cache is handled.</p>
920 <p>In the default enabled configuration, the cache operates within the quick
921 handler phase. This phase short circuits the majority of server processing,
922 and represents the most performant mode of operation for a typical server.
923 The cache <strong>bolts onto</strong> the front of the server, and the
924 majority of server processing is avoided.</p>
926 <p>When disabled, the cache operates as a normal handler, and is subject to
927 the full set of phases when handling a server request. While this mode is
928 slower than the default, it allows the cache to be used in cases where full
929 processing is required, such as when content is subject to authorisation.</p>
931 <highlight language="config">
932 # Run cache as a normal handler
933 CacheQuickHandler off
936 <p>It is also possible, when the quick handler is disabled, for the
937 administrator to choose the precise location within the filter chain where
938 caching is to be performed, by adding the <strong>CACHE</strong> filter to
941 <highlight language="config">
942 # Cache content before mod_include and mod_deflate
943 CacheQuickHandler off
944 AddOutputFilterByType CACHE;INCLUDES;DEFLATE text/html
947 <p>If the CACHE filter is specified more than once, the last instance will
954 <name>CacheHeader</name>
955 <description>Add an X-Cache header to the response.</description>
956 <syntax>CacheHeader <var>on|off</var></syntax>
957 <default>CacheHeader off</default>
958 <contextlist><context>server config</context>
959 <context>virtual host</context>
960 <context>directory</context>
961 <context>.htaccess</context>
963 <compatibility>Available in Apache 2.3.9 and later</compatibility>
966 <p>When the <directive module="mod_cache">CacheHeader</directive> directive
967 is switched on, an <strong>X-Cache</strong> header will be added to the response
968 with the cache status of this response. If the normal handler is used, this
969 directive may appear within a <directive module="core"><Directory></directive>
970 or <directive module="core"><Location></directive> directive. If the quick
971 handler is used, this directive must appear within a server or virtual host
972 context, otherwise the setting will be ignored.</p>
975 <dt><strong>HIT</strong></dt><dd>The entity was fresh, and was served from
977 <dt><strong>REVALIDATE</strong></dt><dd>The entity was stale, was successfully
978 revalidated and was served from cache.</dd>
979 <dt><strong>MISS</strong></dt><dd>The entity was fetched from the upstream
980 server and was not served from cache.</dd>
983 <highlight language="config">
984 # Enable the X-Cache header
988 <highlight language="config">
989 X-Cache: HIT from localhost
996 <name>CacheDetailHeader</name>
997 <description>Add an X-Cache-Detail header to the response.</description>
998 <syntax>CacheDetailHeader <var>on|off</var></syntax>
999 <default>CacheDetailHeader off</default>
1000 <contextlist><context>server config</context>
1001 <context>virtual host</context>
1002 <context>directory</context>
1003 <context>.htaccess</context>
1005 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1008 <p>When the <directive module="mod_cache">CacheDetailHeader</directive> directive
1009 is switched on, an <strong>X-Cache-Detail</strong> header will be added to the response
1010 containing the detailed reason for a particular caching decision.</p>
1012 <p>It can be useful during development of cached RESTful services to have additional
1013 information about the caching decision written to the response headers, so as to
1014 confirm whether <code>Cache-Control</code> and other headers have been correctly
1015 used by the service and client.</p>
1017 <p>If the normal handler is used, this directive may appear within a
1018 <directive module="core"><Directory></directive> or
1019 <directive module="core"><Location></directive> directive. If the quick handler
1020 is used, this directive must appear within a server or virtual host context, otherwise
1021 the setting will be ignored.</p>
1023 <highlight language="config">
1024 # Enable the X-Cache-Detail header
1025 CacheDetailHeader on
1029 X-Cache-Detail: "conditional cache hit: entity refreshed" from localhost<br />
1033 </directivesynopsis>
1036 <name>CacheKeyBaseURL</name>
1037 <description>Override the base URL of reverse proxied cache keys.</description>
1038 <syntax>CacheKeyBaseURL <var>URL</var></syntax>
1039 <default>CacheKeyBaseURL http://example.com</default>
1040 <contextlist><context>server config</context>
1041 <context>virtual host</context>
1043 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1046 <p>When the <directive module="mod_cache">CacheKeyBaseURL</directive> directive
1047 is specified, the URL provided will be used as the base URL to calculate
1048 the URL of the cache keys in the reverse proxy configuration. When not specified,
1049 the scheme, hostname and port of the current virtual host is used to construct
1050 the cache key. When a cluster of machines is present, and all cached entries
1051 should be cached beneath the same cache key, a new base URL can be specified
1052 with this directive.</p>
1054 <highlight language="config">
1055 # Override the base URL of the cache key.
1056 CacheKeyBaseURL http://www.example.com/
1059 <note type="warning">Take care when setting this directive. If two separate virtual
1060 hosts are accidentally given the same base URL, entries from one virtual host
1061 will be served to the other.</note>
1064 </directivesynopsis>
1067 <name>CacheStaleOnError</name>
1068 <description>Serve stale content in place of 5xx responses.</description>
1069 <syntax>CacheStaleOnError <var>on|off</var></syntax>
1070 <default>CacheStaleOnError on</default>
1071 <contextlist><context>server config</context>
1072 <context>virtual host</context>
1073 <context>directory</context>
1074 <context>.htaccess</context>
1076 <compatibility>Available in Apache 2.3.9 and later</compatibility>
1079 <p>When the <directive module="mod_cache">CacheStaleOnError</directive> directive
1080 is switched on, and when stale data is available in the cache, the cache will
1081 respond to 5xx responses from the backend by returning the stale data instead of
1082 the 5xx response. While the Cache-Control headers sent by clients will be respected,
1083 and the raw 5xx responses returned to the client on request, the 5xx response so
1084 returned to the client will not invalidate the content in the cache.</p>
1086 <highlight language="config">
1087 # Serve stale data on error.
1088 CacheStaleOnError on
1092 </directivesynopsis>