This ports the max_stale directive and refresh_pattern max-stale option from 2.7.

It has not yet been tested. But the code is simple enough that pending typos it should work as-is.

Amos
--
Please be using
  Current Stable Squid 2.7.STABLE9 or 3.1.10
  Beta testers wanted for 3.2.0.4
=== modified file 'doc/release-notes/release-3.2.sgml'
--- doc/release-notes/release-3.2.sgml	2010-12-22 03:14:21 +0000
+++ doc/release-notes/release-3.2.sgml	2010-12-26 13:48:15 +0000
@@ -398,6 +398,9 @@
 	<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 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 @@
 	<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>

=== modified file 'src/cache_cf.cc'
--- src/cache_cf.cc	2010-12-20 23:52:52 +0000
+++ src/cache_cf.cc	2010-12-26 13:04:10 +0000
@@ -2651,6 +2651,9 @@
                           (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 @@
     time_t max = 0;
     int refresh_ims = 0;
     int store_stale = 0;
+    int max_stale = -1;
 
 #if USE_HTTP_VIOLATIONS
 
@@ -2782,6 +2786,8 @@
             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 @@
 #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 @@
     if (store_stale)
         t->flags.store_stale = 1;
 
+    t->max_stale = max_stale;
+
 #if USE_HTTP_VIOLATIONS
 
     if (override_expire)

=== modified file 'src/cf.data.pre'
--- src/cf.data.pre	2010-12-15 10:12:22 +0000
+++ src/cf.data.pre	2010-12-26 13:43:30 +0000
@@ -3686,6 +3686,17 @@
 	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 @@
 		 ignore-must-revalidate
 		 ignore-private
 		 ignore-auth
+		 max-stale=NN
 		 refresh-ims
 		 store-stale
 
@@ -3783,6 +3795,10 @@
 		not cache such responses because they usually can't be
 		reused. Note that such responses will be stale by default.
 
+		max-stale=NN provided 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

=== modified file 'src/refresh.cc'
--- src/refresh.cc	2010-12-26 12:37:51 +0000
+++ src/refresh.cc	2010-12-26 13:35:39 +0000
@@ -86,6 +86,7 @@
     STALE_EXPIRES,
     STALE_MAX_RULE,
     STALE_LMFACTOR_RULE,
+    STALE_MAX_STALE,
     STALE_DEFAULT = 299
 };
 
@@ -388,7 +389,16 @@
     /*
      * 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
 

=== modified file 'src/structs.h'
--- src/structs.h	2010-12-26 12:37:51 +0000
+++ src/structs.h	2010-12-26 13:27:38 +0000
@@ -167,6 +167,7 @@
 #if USE_HTTP_VIOLATIONS
     time_t negativeTtl;
 #endif
+    time_t maxStale;
     time_t negativeDnsTtl;
     time_t positiveDnsTtl;
     time_t shutdownLifetime;
@@ -1107,6 +1108,7 @@
         unsigned int ignore_auth:1;
 #endif
     } flags;
+    int max_stale;
 };
 
 /*

Reply via email to