Bug 2631: store-stale refresh_pattern option
RFC2616 allows almost anything to be cached*; most of the constraints are on
what can be used out of cache.
For example, this response:
HTTP/1.1 200 OK
Content-Type: text/html
Date: [date]
[ content ]
is cacheable as per HTTP; it just is considered stale as soon as it is cached.
However, Squid (and many others) don't cache all of these responses, at least
in part because doing so would decrease cache efficiency, and introduce more
load (e.g., on disk subsystems, etc.).
In particular, Squid won't cache a response unless it has either explicit
freshness (e.g., Expires, CC: max-age) or a validator (Last-Modified or ETag).
Nevertheless, doing so is desirable in some circumstances, because in some
deployments the client wants to be able to ask for a stale response. For
example;
GET /foo HTTP/1.1
Host: example.com
Cache-Control: max-age=3600, max-stale
Should retrieve the above response from cache, as long as it is less than an
hour old.
This patch adds a 'store-stale' refresh_pattern option that allows this.
if (head->flags.refresh_ims)
storeAppendPrintf(entry, " refresh-ims");
+ if (head->flags.store_stale)
+ storeAppendPrintf(entry, " store-stale");
+
#if HTTP_VIOLATIONS
if (head->flags.override_expire)
double pct = 0.0;
time_t max = 0;
int refresh_ims = 0;
+ int store_stale = 0;
+
#if HTTP_VIOLATIONS
int override_expire = 0;
while ((token = strtok(NULL, w_space)) != NULL) {
if (!strcmp(token, "refresh-ims")) {
refresh_ims = 1;
+ } else if (!strcmp(token, "store-stale")) {
+ store_stale = 1;
#if HTTP_VIOLATIONS
} else if (!strcmp(token, "override-expire"))
if (refresh_ims)
t->flags.refresh_ims = 1;
+ if (store_stale)
+ t->flags.store_stale = 1;
+
#if HTTP_VIOLATIONS
if (override_expire)
ignore-private
ignore-auth
refresh-ims
+ store-stale
override-expire enforces min age even if the server
sent an explicit expiry time (e.g., with the
ensures that the client will receive an updated version
if one is available.
+ store-stale stores responses even if they don't have explicit
+ freshness or a validator (i.e., Last-Modified or an ETag)
+ present, or if they're already stale. By default, Squid will
+ not cache such responses because they usually can't be
+ reused. Note that such responses will be stale by default.
+
Basically a cached object is:
FRESH if expires < now, else STALE
* unless we know how to refresh it.
*/
- if (!refreshIsCachable(entry)) {
+ if (!refreshIsCachable(entry) && !REFRESH_OVERRIDE(store_stale)) {
debugs(22, 3, "refreshIsCachable() returned non-cacheable..");
return 0;
}
struct {
unsigned int icase:1;
unsigned int refresh_ims:1;
+ unsigned int store_stale:1;
#if HTTP_VIOLATIONS
unsigned int override_expire:1;
unsigned int override_lastmod:1;