From: Amos Jeffries Date: Thu, 5 Jun 2008 12:01:09 +0000 (+1200) Subject: Policy change for negative_ttl X-Git-Tag: SQUID_3_1_0_1~49^2~213 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac9cc05326e01c793e8ae429768c9563267c2ca2;p=thirdparty%2Fsquid.git Policy change for negative_ttl 1) wraps all negative_ttl code to now require --enable-http-violations 2) Makes negative_ttl when used, only apply to cached objects without explicit neg-TTL information. 3) Changes default value to 0, from the previous setting at 5 minutes. 4) Alters negative_ttl documentation to cover the above behavior changes --- diff --git a/src/cf.data.pre b/src/cf.data.pre index c94f0ee4c7..3bf9a20f16 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2876,16 +2876,20 @@ DOC_START DOC_END NAME: negative_ttl +IFDEF: HTTP_VIOLATIONS COMMENT: time-units TYPE: time_t LOC: Config.negativeTtl -DEFAULT: 5 minutes +DEFAULT: 0 seconds DOC_START - Time-to-Live (TTL) for failed requests. Certain types of - failures (such as "connection refused" and "404 Not Found") are - negatively-cached for a configurable amount of time. The - default is 5 minutes. Note that this is different from - negative caching of DNS lookups. + Set the Default Time-to-Live (TTL) for failed requests. + Certain types of failures (such as "connection refused" and + "404 Not Found") are able to be negatively-cached for a short time. + Modern web servers should provide Expires: header, however if they + do not this can provide a minimum TTL. + The default is not to cache errors with unknown expiry details. + + Note that this is different from negative caching of DNS lookups. WARNING: Doing this VIOLATES the HTTP standard. Enabling this feature could make you liable for problems which it diff --git a/src/http.cc b/src/http.cc index e1581445f8..844f323b2d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -828,9 +828,11 @@ HttpStateData::haveParsedReplyHeaders() case -1: +#if HTTP_VIOLATIONS if (Config.negativeTtl > 0) entry->cacheNegatively(); else +#endif entry->makePrivate(); break; diff --git a/src/store.cc b/src/store.cc index b3128915ee..72fcc92cd1 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1086,9 +1086,7 @@ StoreEntry::abort() assert(mem_obj != NULL); debugs(20, 6, "storeAbort: " << getMD5Text()); - lock() - - ; /* lock while aborting */ + lock(); /* lock while aborting */ negativeCache(); releaseRequest(); @@ -1452,10 +1450,21 @@ StoreEntry::checkNegativeHit() const return 1; } +/** + * Set object for negative caching. + * Preserves any expiry information given by the server. + * In absence of proper expiry info it will set to expire immediately, + * or with HTTP-violations enabled the configured negative-TTL is observed + */ void StoreEntry::negativeCache() { - expires = squid_curtime + Config.negativeTtl; + if(expires == 0) +#if HTTP_VIOLATIONS + expires = squid_curtime + Config.negativeTtl; +#else + expires = squid_curtime; +#endif EBIT_SET(flags, ENTRY_NEGCACHED); } diff --git a/src/structs.h b/src/structs.h index 9c1352dc06..bfb24f0f8a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -161,7 +161,9 @@ struct SquidConfig int64_t readAheadGap; RemovalPolicySettings *replPolicy; RemovalPolicySettings *memPolicy; +#if HTTP_VIOLATIONS time_t negativeTtl; +#endif time_t negativeDnsTtl; time_t positiveDnsTtl; time_t shutdownLifetime;