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>Content cache keyed to URIs.</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 and
33 can be used to circumvent <directive
34 module="mod_authz_host">Allow</directive> and <directive
35 module="mod_authz_host">Deny</directive> directives. You
36 should not enable caching for any content to which you wish
37 to limit access by client host name, address or environment
40 <p><module>mod_cache</module> implements an <a
41 href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616</a> compliant HTTP
42 content cache that can be used to cache either local or proxied content.
43 <module>mod_cache</module> requires the services of one or more storage
44 management modules. One storage management module is included in
45 the base Apache distribution:</p>
47 <dt><module>mod_disk_cache</module></dt>
48 <dd>implements a disk based storage manager.</dd>
51 <p>Content is stored in and retrieved from the cache using URI based keys. Content with
52 access protection is not cached.</p>
53 <p>Further details, discussion, and examples, are provided in the
54 <a href="../caching.html">Caching Guide</a>.</p>
56 <seealso><a href="../caching.html">Caching Guide</a></seealso>
58 <section id="related"><title>Related Modules and Directives</title>
61 <module>mod_disk_cache</module>
64 <directive module="mod_disk_cache">CacheRoot</directive>
65 <directive module="mod_disk_cache">CacheDirLevels</directive>
66 <directive module="mod_disk_cache">CacheDirLength</directive>
67 <directive module="mod_disk_cache">CacheMinFileSize</directive>
68 <directive module="mod_disk_cache">CacheMaxFileSize</directive>
73 <section id="sampleconf"><title>Sample Configuration</title>
74 <example><title>Sample httpd.conf</title>
76 # Sample Cache Configuration<br />
78 LoadModule cache_module modules/mod_cache.so<br />
80 <IfModule mod_cache.c><br />
82 LoadModule disk_cache_module modules/mod_disk_cache.so<br />
83 <IfModule mod_disk_cache.c><br />
85 CacheRoot c:/cacheroot<br />
86 CacheEnable disk /<br />
87 CacheDirLevels 5<br />
88 CacheDirLength 3<br />
90 </IfModule> <br />
92 # When acting as a proxy, don't cache the list of security updates<br />
93 CacheDisable http://security.update.server/update-list/<br />
99 <section id="thunderingherd"><title>Avoiding the Thundering Herd</title>
100 <p>When a cached entry becomes stale, <module>mod_cache</module> will submit
101 a conditional request to the backend, which is expected to confirm whether the
102 cached entry is still fresh, and send an updated entity if not.</p>
103 <p>A small but finite amount of time exists between the time the cached entity
104 becomes stale, and the time the stale entity is fully refreshed. On a busy
105 server, a significant number of requests might arrive during this time, and
106 cause a <strong>thundering herd</strong> of requests to strike the backend
107 suddenly and unpredicably.</p>
108 <p>To keep the thundering herd at bay, the <directive>CacheLock</directive>
109 directive can be used to define a directory in which locks are created for
110 URLs <strong>in flight</strong>. The lock is used as a <strong>hint</strong>
111 by other requests to either suppress an attempt to cache (someone else has
112 gone to fetch the entity), or to indicate that a stale entry is being refreshed
113 (stale content will be returned in the mean time).
116 <title>Initial caching of an entry</title>
117 <p>When an entity is cached for the first time, a lock will be created for the
118 entity until the response has been fully cached. During the lifetime of the
119 lock, the cache will suppress the second and subsequent attempt to cache the
120 same entity. While this doesn't hold back the thundering herd, it does stop
121 the cache attempting to cache the same entity multiple times simultaneously.
125 <title>Refreshment of a stale entry</title>
126 <p>When an entity reaches its freshness lifetime and becomes stale, a lock
127 will be created for the entity until the response has either been confirmed as
128 still fresh, or replaced by the backend. During the lifetime of the lock, the
129 second and subsequent incoming request will cause stale data to be returned,
130 and the thundering herd is kept at bay.</p>
133 <title>Locks and Cache-Control: no-cache</title>
134 <p>Locks are used as a <strong>hint only</strong> to enable the cache to be
135 more gentle on backend servers, however the lock can be overridden if necessary.
136 If the client sends a request with a Cache-Control header forcing a reload, any
137 lock that may be present will be ignored, and the client's request will be
138 honoured immediately and the cached entry refreshed.</p>
139 <p>As a further safety mechanism, locks have a configurable maximum age.
140 Once this age has been reached, the lock is removed, and a new request is
141 given the opportunity to create a new lock. This maximum age can be set using
142 the <directive>CacheLockMaxAge</directive> directive, and defaults to 5
147 <title>Example configuration</title>
148 <example><title>Enabling the cache lock</title>
150 # Enable the cache lock<br />
152 <IfModule mod_cache.c><br />
155 CacheLockPath /tmp/mod_cache-lock<br />
156 CacheLockMaxAge 5<br />
164 <name>CacheEnable</name>
165 <description>Enable caching of specified URLs using a specified storage
166 manager</description>
167 <syntax>CacheEnable <var>cache_type</var> <var>url-string</var></syntax>
168 <contextlist><context>server config</context><context>virtual host</context>
172 <p>The <directive>CacheEnable</directive> directive instructs
173 <module>mod_cache</module> to cache urls at or below
174 <var>url-string</var>. The cache storage manager is specified with the
175 <var>cache_type</var> argument.
176 <var>cache_type</var> <code>disk</code> instructs
177 <module>mod_cache</module> to use the disk based storage manager
178 implemented by <module>mod_disk_cache</module>.</p>
179 <p>In the event that the URL space overlaps between different
180 <directive>CacheEnable</directive> directives (as in the example below),
181 each possible storage manager will be run until the first one that
182 actually processes the request. The order in which the storage managers are
183 run is determined by the order of the <directive>CacheEnable</directive>
184 directives in the configuration file.</p>
186 <p>When acting as a forward proxy server, <var>url-string</var> can
187 also be used to specify remote sites and proxy protocols which
188 caching should be enabled for.</p>
191 # Cache proxied url's<br />
192 CacheEnable disk /<br /><br />
193 # Cache FTP-proxied url's<br />
194 CacheEnable disk ftp://<br /><br />
195 # Cache content from www.apache.org<br />
196 CacheEnable disk http://www.apache.org/<br />
199 <p> The <code>no-cache</code> environment variable can be set to
200 disable caching on a finer grained set of resources in versions
201 2.2.12 and later.</p>
204 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
208 <name>CacheDisable</name>
209 <description>Disable caching of specified URLs</description>
210 <syntax>CacheDisable <var> url-string</var></syntax>
211 <contextlist><context>server config</context><context>virtual host</context>
215 <p>The <directive>CacheDisable</directive> directive instructs
216 <module>mod_cache</module> to <em>not</em> cache urls at or below
217 <var>url-string</var>.</p>
219 <example><title>Example</title>
220 CacheDisable /local_files
223 <p> The <code>no-cache</code> environment variable can be set to
224 disable caching on a finer grained set of resources in versions
225 2.2.12 and later.</p>
228 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
231 <name>CacheMaxExpire</name>
232 <description>The maximum time in seconds to cache a document</description>
233 <syntax>CacheMaxExpire <var>seconds</var></syntax>
234 <default>CacheMaxExpire 86400 (one day)</default>
235 <contextlist><context>server config</context><context>virtual host</context>
239 <p>The <directive>CacheMaxExpire</directive> directive specifies the maximum number of
240 seconds for which cachable HTTP documents will be retained without checking the origin
241 server. Thus, documents will be out of date at most this number of seconds. This maximum
242 value is enforced even if an expiry date was supplied with the document.</p>
245 CacheMaxExpire 604800
251 <name>CacheMinExpire</name>
252 <description>The minimum time in seconds to cache a document</description>
253 <syntax>CacheMinExpire <var>seconds</var></syntax>
254 <default>CacheMinExpire 0</default>
255 <contextlist><context>server config</context><context>virtual host</context>
259 <p>The <directive>CacheMinExpire</directive> directive specifies the minimum number of
260 seconds for which cachable HTTP documents will be retained without checking the origin
261 server. This is only used if no valid expire time was supplied with the document.</p>
271 <name>CacheDefaultExpire</name>
272 <description>The default duration to cache a document when no expiry date is specified.</description>
273 <syntax>CacheDefaultExpire <var>seconds</var></syntax>
274 <default>CacheDefaultExpire 3600 (one hour)</default>
275 <contextlist><context>server config</context><context>virtual host</context>
279 <p>The <directive>CacheDefaultExpire</directive> directive specifies a default time,
280 in seconds, to cache a document if neither an expiry date nor last-modified date are provided
281 with the document. The value specified with the <directive>CacheMaxExpire</directive>
282 directive does <em>not</em> override this setting.</p>
285 CacheDefaultExpire 86400
291 <name>CacheIgnoreNoLastMod</name>
292 <description>Ignore the fact that a response has no Last Modified
293 header.</description>
294 <syntax>CacheIgnoreNoLastMod On|Off</syntax>
295 <default>CacheIgnoreNoLastMod Off</default>
296 <contextlist><context>server config</context><context>virtual host</context>
300 <p>Ordinarily, documents without a last-modified date are not cached.
301 Under some circumstances the last-modified date is removed (during
302 <module>mod_include</module> processing for example) or not provided
303 at all. The <directive>CacheIgnoreNoLastMod</directive> directive
304 provides a way to specify that documents without last-modified dates
305 should be considered for caching, even without a last-modified date.
306 If neither a last-modified date nor an expiry date are provided with
307 the document then the value specified by the
308 <directive>CacheDefaultExpire</directive> directive will be used to
309 generate an expiration date.</p>
312 CacheIgnoreNoLastMod On
318 <name>CacheIgnoreCacheControl</name>
319 <description>Ignore request to not serve cached content to client</description>
320 <syntax>CacheIgnoreCacheControl On|Off</syntax>
321 <default>CacheIgnoreCacheControl Off</default>
322 <contextlist><context>server config</context><context>virtual host</context>
326 <p>Ordinarily, requests containing a Cache-Control: no-cache or
327 Pragma: no-cache header value will not be served from the cache. The
328 <directive>CacheIgnoreCacheControl</directive> directive allows this
329 behavior to be overridden. <directive>CacheIgnoreCacheControl On</directive>
330 tells the server to attempt to serve the resource from the cache even
331 if the request contains no-cache header values. Resources requiring
332 authorization will <em>never</em> be cached.</p>
335 CacheIgnoreCacheControl On
338 <note type="warning"><title>Warning:</title>
339 This directive will allow serving from the cache even if the client has
340 requested that the document not be served from the cache. This might
341 result in stale content being served.
344 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
345 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
349 <name>CacheIgnoreQueryString</name>
350 <description>Ignore query string when caching</description>
351 <syntax>CacheIgnoreQueryString On|Off</syntax>
352 <default>CacheIgnoreQueryString Off</default>
353 <contextlist><context>server config</context><context>virtual host</context>
357 <p>Ordinarily, requests with query string parameters are cached separately
358 for each unique query string. This is according to RFC 2616/13.9 done only
359 if an expiration time is specified. The
360 <directive>CacheIgnoreQueryString</directive> directive tells the cache to
361 cache requests even if no expiration time is specified, and to reply with
362 a cached reply even if the query string differs. From a caching point of
363 view the request is treated as if having no query string when this
364 directive is enabled.</p>
367 CacheIgnoreQueryString On
374 <name>CacheLastModifiedFactor</name>
375 <description>The factor used to compute an expiry date based on the
376 LastModified date.</description>
377 <syntax>CacheLastModifiedFactor <var>float</var></syntax>
378 <default>CacheLastModifiedFactor 0.1</default>
379 <contextlist><context>server config</context><context>virtual host</context>
383 <p>In the event that a document does not provide an expiry date but does
384 provide a last-modified date, an expiry date can be calculated based on
385 the time since the document was last modified. The
386 <directive>CacheLastModifiedFactor</directive> directive specifies a
387 <var>factor</var> to be used in the generation of this expiry date
388 according to the following formula:
390 <code>expiry-period = time-since-last-modified-date * <var>factor</var>
391 expiry-date = current-date + expiry-period</code>
393 For example, if the document was last modified 10 hours ago, and
394 <var>factor</var> is 0.1 then the expiry-period will be set to
395 10*0.1 = 1 hour. If the current time was 3:00pm then the computed
396 expiry-date would be 3:00pm + 1hour = 4:00pm.
398 If the expiry-period would be longer than that set by
399 <directive>CacheMaxExpire</directive>, then the latter takes
403 CacheLastModifiedFactor 0.5
409 <name>CacheIgnoreHeaders</name>
410 <description>Do not store the given HTTP header(s) in the cache.
412 <syntax>CacheIgnoreHeaders <var>header-string</var> [<var>header-string</var>] ...</syntax>
413 <default>CacheIgnoreHeaders None</default>
414 <contextlist><context>server config</context><context>virtual host</context>
418 <p>According to RFC 2616, hop-by-hop HTTP headers are not stored in
419 the cache. The following HTTP headers are hop-by-hop headers and thus
420 do not get stored in the cache in <em>any</em> case regardless of the
421 setting of <directive>CacheIgnoreHeaders</directive>:</p>
424 <li><code>Connection</code></li>
425 <li><code>Keep-Alive</code></li>
426 <li><code>Proxy-Authenticate</code></li>
427 <li><code>Proxy-Authorization</code></li>
428 <li><code>TE</code></li>
429 <li><code>Trailers</code></li>
430 <li><code>Transfer-Encoding</code></li>
431 <li><code>Upgrade</code></li>
434 <p><directive>CacheIgnoreHeaders</directive> specifies additional HTTP
435 headers that should not to be stored in the cache. For example, it makes
436 sense in some cases to prevent cookies from being stored in the cache.</p>
438 <p><directive>CacheIgnoreHeaders</directive> takes a space separated list
439 of HTTP headers that should not be stored in the cache. If only hop-by-hop
440 headers not should be stored in the cache (the RFC 2616 compliant
441 behaviour), <directive>CacheIgnoreHeaders</directive> can be set to
442 <code>None</code>.</p>
444 <example><title>Example 1</title>
445 CacheIgnoreHeaders Set-Cookie
448 <example><title>Example 2</title>
449 CacheIgnoreHeaders None
452 <note type="warning"><title>Warning:</title>
453 If headers like <code>Expires</code> which are needed for proper cache
454 management are not stored due to a
455 <directive>CacheIgnoreHeaders</directive> setting, the behaviour of
456 mod_cache is undefined.
462 <name>CacheIgnoreURLSessionIdentifiers</name>
463 <description>Ignore defined session identifiers encoded in the URL when caching
465 <syntax>CacheIgnoreURLSessionIdentifiers <var>identifier</var> [<var>identifier</var>] ...</syntax>
466 <default>CacheIgnoreURLSessionIdentifiers None</default>
467 <contextlist><context>server config</context><context>virtual host</context>
471 <p>Sometimes applications encode the session identifier into the URL like in the following
475 <li><code>/someapplication/image.gif;jsessionid=123456789</code></li>
476 <li><code>/someapplication/image.gif?PHPSESSIONID=12345678</code></li>
478 <p>This causes cachable resources to be stored separately for each session, which
479 is often not desired. <directive>CacheIgnoreURLSessionIdentifiers</directive> lets
480 define a list of identifiers that are removed from the key that is used to identify
481 an entity in the cache, such that cachable resources are not stored separately for
484 <p><code>CacheIgnoreURLSessionIdentifiers None</code> clears the list of ignored
485 identifiers. Otherwise, each identifier is added to the list.</p>
487 <example><title>Example 1</title>
488 CacheIgnoreURLSessionIdentifiers jsessionid
491 <example><title>Example 2</title>
492 CacheIgnoreURLSessionIdentifiers None
499 <name>CacheStorePrivate</name>
500 <description>Attempt to cache responses that the server has marked as private</description>
501 <syntax>CacheStorePrivate On|Off</syntax>
502 <default>CacheStorePrivate Off</default>
503 <contextlist><context>server config</context><context>virtual host</context>
507 <p>Ordinarily, responses with Cache-Control: private header values will not
508 be stored in the cache. The <directive>CacheStorePrivate</directive>
509 directive allows this behavior to be overridden.
510 <directive>CacheStorePrivate</directive> On
511 tells the server to attempt to cache the resource even if it contains
512 private header values. Resources requiring authorization will
513 <em>never</em> be cached.</p>
519 <note type="warning"><title>Warning:</title>
520 This directive will allow caching even if the upstream server has
521 requested that the resource not be cached. This directive is only
522 ideal for a 'private' cache.
525 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
526 <seealso><directive module="mod_cache">CacheStoreNoStore</directive></seealso>
530 <name>CacheStoreNoStore</name>
531 <description>Attempt to cache requests or responses that have been marked as no-store.</description>
532 <syntax>CacheStoreNoStore On|Off</syntax>
533 <default>CacheStoreNoStore Off</default>
534 <contextlist><context>server config</context><context>virtual host</context>
538 <p>Ordinarily, requests or responses with Cache-Control: no-store header
539 values will not be stored in the cache. The
540 <directive>CacheStoreNoCache</directive> directive allows this
541 behavior to be overridden. <directive>CacheStoreNoCache</directive> On
542 tells the server to attempt to cache the resource even if it contains
543 no-store header values. Resources requiring authorization will
544 <em>never</em> be cached.</p>
550 <note type="warning"><title>Warning:</title>
551 As described in RFC 2616, the no-store directive is intended to
552 "prevent the inadvertent release or retention of sensitive information
553 (for example, on backup tapes)." Enabling this option could store
554 sensitive information in the cache. You are hereby warned.
557 <seealso><directive module="mod_cache">CacheIgnoreCacheControl</directive></seealso>
558 <seealso><directive module="mod_cache">CacheStorePrivate</directive></seealso>
562 <name>CacheLock</name>
563 <description>Enable the thundering herd lock.</description>
564 <syntax>CacheLock <var>on|off</var></syntax>
565 <default>CacheLock off</default>
566 <contextlist><context>server config</context><context>virtual host</context>
570 <p>The <directive>CacheLock</directive> directive enables the thundering herd lock
571 for the given URL space.</p>
573 <p>In a minimal configuration the following directive is all that is needed to
574 enable the thundering herd lock in the default system temp directory.</p>
577 # Enable cache lock<br />
578 CacheLock on<br /><br />
585 <name>CacheLockPath</name>
586 <description>Set the lock path directory.</description>
587 <syntax>CacheLockPath <var>directory</var></syntax>
588 <default>CacheLockPath /tmp/mod_cache-lock</default>
589 <contextlist><context>server config</context><context>virtual host</context>
593 <p>The <directive>CacheLockPath</directive> directive allows you to specify the
594 directory in which the locks are created. By default, the system's temporary
595 folder is used. Locks consist of empty files that only exist for stale URLs
596 in flight, so is significantly less resource intensive than the traditional
603 <name>CacheLockMaxAge</name>
604 <description>Set the maximum possible age of a cache lock.</description>
605 <syntax>CacheLockMaxAge <var>integer</var></syntax>
606 <default>CacheLockMaxAge 5</default>
607 <contextlist><context>server config</context><context>virtual host</context>
611 <p>The <directive>CacheLockMaxAge</directive> directive specifies the maximum
612 age of any cache lock.</p>
614 <p>A lock older than this value in seconds will be ignored, and the next
615 incoming request will be given the opportunity to re-establish the lock.
616 This mechanism prevents a slow client taking an excessively long time to refresh