From: Amos Jeffries Date: Sat, 8 Jan 2011 06:23:27 +0000 (+1300) Subject: Author: Henrik Nordstrom X-Git-Tag: take00~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=570d3f7565f28594ee6fa7feebf493562215b317;p=thirdparty%2Fsquid.git Author: Henrik Nordstrom Port from 2.7: maximum staleness limits The default behaviour of Squid is to provide a stale copy (with Warnigng: header) until an actove response from the origin server causes the object to be updated or garbage collection causes its removal. The max_stale direcive and refresh_pattern max-stale=N option allow admin to set an upper limit on the objects age when serving stale responses. --- diff --git a/doc/release-notes/release-3.2.sgml b/doc/release-notes/release-3.2.sgml index 6fe616b4f9..d63229f643 100644 --- a/doc/release-notes/release-3.2.sgml +++ b/doc/release-notes/release-3.2.sgml @@ -398,6 +398,9 @@ This section gives a thorough account of those changes in three categories:

The else part is optional. The keywords if, else and endif must be typed on their own lines, as if they were regular configuration directives. + max_stale +

Places an upper limit on how stale content Squid will serve from the cache if cache validation fails + memory_cache_mode

Controls which objects to keep in the memory cache (cache_mem) @@ -514,6 +517,10 @@ This section gives a thorough account of those changes in three categories: This will be included by default if available (see the --without-netfilter-conntrack configure option for more details).

miss sets a value for a cache miss. It is available for both the tos and mark options and takes precedence over the preserve-miss feature. + refresh_pattern +

New option max-stale= to provide a maximum staleness factor. Squid won't + serve objects more stale than this even if it failed to validate the object. + tcp_outgoing_mark

New configuration parameter tcp_outgoing_mark

Allows packets leaving Squid on the server side to be marked with a Netfilter mark value in the same way as the existing tcp_outgoing_tos feature. @@ -867,13 +874,9 @@ This section gives an account of those changes in three categories: logformat

%oa tag not yet ported from 2.7 - max_stale -

Not yet ported from 2.7 - refresh_pattern

stale-while-revalidate= not yet ported from 2.7

ignore-stale-while-revalidate= not yet ported from 2.7 -

max-stale= not yet ported from 2.7

negative-ttl= not yet ported from 2.7 refresh_stale_hit diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 179cfb469b..0c72ed1a4b 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -2651,6 +2651,9 @@ dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) (int) (100.0 * head->pct + 0.5), (int) head->max / 60); + if (head->max_stale >= 0) + storeAppendPrintf(entry, " max-stale=%d", head->max_stale); + if (head->flags.refresh_ims) storeAppendPrintf(entry, " refresh-ims"); @@ -2704,6 +2707,7 @@ parse_refreshpattern(refresh_t ** head) time_t max = 0; int refresh_ims = 0; int store_stale = 0; + int max_stale = -1; #if USE_HTTP_VIOLATIONS @@ -2782,6 +2786,8 @@ parse_refreshpattern(refresh_t ** head) refresh_ims = 1; } else if (!strcmp(token, "store-stale")) { store_stale = 1; + } else if (!strncmp(token, "max-stale=", 10)) { + max_stale = atoi(token + 10); #if USE_HTTP_VIOLATIONS } else if (!strcmp(token, "override-expire")) @@ -2809,7 +2815,7 @@ parse_refreshpattern(refresh_t ** head) #endif } else - debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token); + debugs(22, 0, "refreshAddToList: Unknown option '" << pattern << "': " << token); } if ((errcode = regcomp(&comp, pattern, flags)) != 0) { @@ -2838,6 +2844,8 @@ parse_refreshpattern(refresh_t ** head) if (store_stale) t->flags.store_stale = 1; + t->max_stale = max_stale; + #if USE_HTTP_VIOLATIONS if (override_expire) diff --git a/src/cf.data.pre b/src/cf.data.pre index 74a98a4c42..2e24a9f5cb 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -3686,6 +3686,17 @@ DOC_START See http://wiki.squid-cache.org/SquidFaq/SquidAcl for details. DOC_END +NAME: max_stale +COMMENT: time-units +TYPE: time_t +LOC: Config.maxStale +DEFAULT: 1 week +DOC_START + This option puts an upper limit on how stale content Squid + will serve from the cache if cache validation fails. + Can be overriden by the refresh_pattern max-stale option. +DOC_END + NAME: refresh_pattern TYPE: refreshpattern LOC: Config.Refresh @@ -3718,6 +3729,7 @@ DOC_START ignore-must-revalidate ignore-private ignore-auth + max-stale=NN refresh-ims store-stale @@ -3783,6 +3795,10 @@ DOC_START not cache such responses because they usually can't be reused. Note that such responses will be stale by default. + max-stale=NN provide a maximum staleness factor. Squid won't + serve objects more stale than this even if it failed to + validate the object. Default: use the max_stale global limit. + Basically a cached object is: FRESH if expires < now, else STALE diff --git a/src/refresh.cc b/src/refresh.cc index 6d8c160d27..4617102a8e 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -86,6 +86,7 @@ enum { STALE_EXPIRES, STALE_MAX_RULE, STALE_LMFACTOR_RULE, + STALE_MAX_STALE, STALE_DEFAULT = 299 }; @@ -388,7 +389,16 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) /* * At this point the response is stale, unless one of * the override options kicks in. + * NOTE: max-stale config blocks the overrides. */ + int max_stale = (R->max_stale >= 0 ? R->max_stale : Config.maxStale); + if ( max_stale >= 0 && staleness < max_stale) { + debugs(22, 3, "refreshCheck: YES: max-stale limit"); + if (request) + request->flags.fail_on_validation_err = 1; + return STALE_MAX_STALE; + } + if (sf.expires) { #if USE_HTTP_VIOLATIONS diff --git a/src/structs.h b/src/structs.h index badbc3ad84..f3b7d0cf0e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -167,6 +167,7 @@ struct SquidConfig { #if USE_HTTP_VIOLATIONS time_t negativeTtl; #endif + time_t maxStale; time_t negativeDnsTtl; time_t positiveDnsTtl; time_t shutdownLifetime; @@ -1107,6 +1108,7 @@ struct _refresh_t { unsigned int ignore_auth:1; #endif } flags; + int max_stale; }; /*