]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <hno@squid-cache.org>
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 8 Jan 2011 06:23:27 +0000 (19:23 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 8 Jan 2011 06:23:27 +0000 (19:23 +1300)
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.

doc/release-notes/release-3.2.sgml
src/cache_cf.cc
src/cf.data.pre
src/refresh.cc
src/structs.h

index 6fe616b4f9c172c4582c595b7c6f316a66d1e9bc..d63229f643877705d57a1f0381b5983cc27c74fc 100644 (file)
@@ -398,6 +398,9 @@ This section gives a thorough account of those changes in three categories:
        <p>The else part is optional. The keywords <em>if</em>, <em>else</em> and <em>endif</em> 
        must be typed on their own lines, as if they were regular configuration directives.
 
+       <tag>max_stale</tag>
+       <p>Places an upper limit on how stale content Squid will serve from the cache if cache validation fails
+
        <tag>memory_cache_mode</tag>
        <p>Controls which objects to keep in the memory cache (cache_mem)
        <verb>
@@ -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).
        <p><em>miss</em> 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.
 
+       <tag>refresh_pattern</tag>
+       <p>New option <em>max-stale=</em> to provide a maximum staleness factor. Squid won't
+          serve objects more stale than this even if it failed to validate the object.
+
        <tag>tcp_outgoing_mark</tag>
        <p>New configuration parameter <em>tcp_outgoing_mark</em>
        <p>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:
        <tag>logformat</tag>
        <p><em>%oa</em> tag not yet ported from 2.7
 
-       <tag>max_stale</tag>
-       <p>Not yet ported from 2.7
-
        <tag>refresh_pattern</tag>
        <p><em>stale-while-revalidate=</em> not yet ported from 2.7
        <p><em>ignore-stale-while-revalidate=</em> not yet ported from 2.7
-       <p><em>max-stale=</em> not yet ported from 2.7
        <p><em>negative-ttl=</em> not yet ported from 2.7
 
        <tag>refresh_stale_hit</tag>
index 179cfb469bafb0679aa65a449c02403071518ae3..0c72ed1a4b0999e69efdf864adfd1b2f0bd1f0c8 100644 (file)
@@ -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)
index 74a98a4c428191df33a05b05defae38f1fc55cc4..2e24a9f5cb6a646ae012a2866d5624e3ab301ae8 100644 (file)
@@ -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
index 6d8c160d2774abb0851ce863683bae3733788265..4617102a8e30750df539ae643d5cc3430ff0a602 100644 (file)
@@ -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
 
index badbc3ad84543ca5a0cee3c51ace626ecbf134dd..f3b7d0cf0ebe355b26a593be2b8faadd349edd0b 100644 (file)
@@ -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;
 };
 
 /*