From 4646017c8a168291df486785d09a43a1015fc86a Mon Sep 17 00:00:00 2001
From: Graham Leggett CacheIgnoreQueryString
CacheIgnoreURLSessionIdentifiers
CacheLastModifiedFactor
CacheLock
CacheLockMaxAge
CacheLockPath
CacheMaxExpire
CacheStoreNoStore
CacheStorePrivate
See also
When a cached entry becomes stale, mod_cache
will submit
+ a conditional request to the backend, which is expected to confirm whether the
+ cached entry is still fresh, and send an updated entity if not.
A small but finite amount of time exists between the time the cached entity + becomes stale, and the time the stale entity is fully refreshed. On a busy + server, a significant number of requests might arrive during this time, and + cause a thundering herd of requests to strike the backend + suddenly and unpredicably.
+To keep the thundering herd at bay, the CacheLock
+ directive can be used to define a directory in which locks are created for
+ URLs in flight. The lock is used as a hint
+ by other requests to either suppress an attempt to cache (someone else has
+ gone to fetch the entity), or to indicate that a stale entry is being refreshed
+ (stale content will be returned in the mean time).
+
When an entity is cached for the first time, a lock will be created for the + entity until the response has been fully cached. During the lifetime of the + lock, the cache will suppress the second and subsequent attempt to cache the + same entity. While this doesn't hold back the thundering herd, it does stop + the cache attempting to cache the same entity multiple times simultaneously. +
+ +When an entity reaches its freshness lifetime and becomes stale, a lock + will be created for the entity until the response has either been confirmed as + still fresh, or replaced by the backend. During the lifetime of the lock, the + second and subsequent incoming request will cause stale data to be returned, + and the thundering herd is kept at bay.
+ +Locks are used as a hint only to enable the cache to be + more gentle on backend servers, however the lock can be overridden if necessary. + If the client sends a request with a Cache-Control header forcing a reload, any + lock that may be present will be ignored, and the client's request will be + honoured immediately and the cached entry refreshed.
+As a further safety mechanism, locks have a configurable maximum age.
+ Once this age has been reached, the lock is removed, and a new request is
+ given the opportunity to create a new lock. This maximum age can be set using
+ the CacheLockMaxAge
directive, and defaults to 5
+ seconds.
+
+ #
+ # Enable the cache lock
+ #
+ <IfModule mod_cache.c>
+
+ CacheLock on
+ CacheLockPath /tmp/mod_cache-lock
+ CacheLockMaxAge 5
+
+ </IfModule>
+
Description: | Enable the thundering herd lock. |
---|---|
Syntax: | CacheLock on|off |
Default: | CacheLock off |
Context: | server config, virtual host |
Status: | Extension |
Module: | mod_cache |
The CacheLock
directive enables the thundering herd lock
+ for the given URL space.
In a minimal configuration the following directive is all that is needed to + enable the thundering herd lock in the default system temp directory.
+ +
+ # Enable chache lock
+ CacheLock on
+
Description: | Set the maximum possible age of a cache lock. |
---|---|
Syntax: | CacheLockMaxAge integer |
Default: | CacheLockMaxAge 5 |
Context: | server config, virtual host |
Status: | Extension |
Module: | mod_cache |
The CacheLockMaxAge
directive specifies the maximum
+ age of any cache lock.
A lock older than this value in seconds will be ignored, and the next + incoming request will be given the opportunity to re-establish the lock. + This mechanism prevents a slow client taking an excessively long time to refresh + an entity.
+ + +Description: | Set the lock path directory. |
---|---|
Syntax: | CacheLockPath directory |
Default: | CacheLockPath /tmp/mod_cache-lock |
Context: | server config, virtual host |
Status: | Extension |
Module: | mod_cache |
The CacheLockPath
directive allows you to specify the
+ directory in which the locks are created. By default, the system's temporary
+ folder is used. Locks consist of empty files that only exist for stale URLs
+ in flight, so is significantly less resource intensive than the traditional
+ disk cache.