[Patch]让Squid对付Cache-Control no-store,must-revalidate

查看532次   共有1帖
SimenKing 1楼
发邮件 (杭州)   03:59 1月10日

网站需要使用Squid对天气数据和flickr图片搜索做缓存

碰到的问题是这些数据的HTTP头部带有
Cache-Control: no-store, must-revalidate
Cache-Control: no-cache, must-revalidate 缓存控制.

但是Squid对CC中的no-storemust-revalidate却无能为力

于是制作该补丁(for squid2.6STABLE),
给refresh_pattern增加两个参数ignore-no-store ignore-revalidate,使squid能对付这种情况

========================================
--- cache_cf_old.c Fri Jan 11 15:43:48 2008
+++ cache_cf.c Fri Jan 11 15:55:27 2008
@ -2144,6 +2144,10 @
        storeAppendPrintf(entry, " ignore-private");
if (head->flags.ignore_auth)
        storeAppendPrintf(entry, " ignore-auth");
+ if (head->flags.ignore_no_store)
+         storeAppendPrintf(entry, " ignore-no-store");
+ if (head->flags.ignore_revalidate)
+         storeAppendPrintf(entry, " ignore-revalidate");
#endif
storeAppendPrintf(entry, "\n");
head = head->next;
@ -2166,6 +2170,8 @
         int ignore_no_cache = 0;
         int ignore_private = 0;
         int ignore_auth = 0;
+        int ignore_no_store = 0;
+        int ignore_revalidate = 0;
#endif
         int i;
         refresh_t *t;
@ -2203,6 +2209,10 @
        ignore_private = 1;
else if (!strcmp(token, "ignore-auth"))
        ignore_auth = 1;
+ else if (!strcmp(token, "ignore-no-store"))
+         ignore_no_store = 1;
+ else if (!strcmp(token, "ignore-revalidate"))
+         ignore_revalidate = 1;
else if (!strcmp(token, "reload-into-ims")) {
        reload_into_ims = 1;
        refresh_nocache_hack = 1;
@ -2250,6 +2260,10 @
t->flags.ignore_private = 1;
         if (ignore_auth)
t->flags.ignore_auth = 1;
+        if (ignore_no_store)
+ t->flags.ignore_no_store = 1;
+        if (ignore_revalidate)
+ t->flags.ignore_revalidate = 1;
#endif
         t->next = NULL;
         while (*head)
--- structs_old.h Fri Jan 11 15:40:48 2008
+++ structs.h Fri Jan 11 15:41:57 2008
@ -1944,6 +1944,8 @
unsigned int ignore_no_cache:1;
unsigned int ignore_private:1;
unsigned int ignore_auth:1;
+ unsigned int ignore_no_store:1;
+ unsigned int ignore_revalidate:1;
#endif
         } flags;
};
--- http_old.c Thu Jan 10 03:27:25 2008
+++ http.c Fri Jan 11 17:17:15 2008
@ -241,7 +241,7 @
return 0;
         if (EBIT_TEST(cc_mask, CC_NO_CACHE) && !REFRESH_OVERRIDE(ignore_no_cache))
return 0;
-        if (EBIT_TEST(cc_mask, CC_NO_STORE))
+        if (EBIT_TEST(cc_mask, CC_NO_STORE) && !REFRESH_OVERRIDE(ignore_no_store))
return 0;
         if (httpState->request->flags.auth_sent) {
/*
--- refresh_old.c Thu Jan 10 03:27:40 2008
+++ refresh.c Fri Jan 11 17:17:43 2008
@ -229,6 +229,10 @
         else if (request)
uri = urlCanonical(request);

+#define REFRESH_OVERRIDE(flag) \
+                ((R = (R ? R : refreshLimits(entry->mem_obj->url))) , \
+                (R && R->flags.flag))
+
         debug(22, 3) ("refreshCheck: '%s'\n", uri ? uri : "<none>");

         if (delta > 0)
@ -248,7 +252,7 @
         debug(22, 3) ("\tcheck_time:\t%s\n", mkrfc1123(check_time));
         debug(22, 3) ("\tentry->timestamp:\t%s\n", mkrfc1123(entry->timestamp));

-        if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1) {
+        if ( !REFRESH_OVERRIDE(ignore_revalidate) && EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1) {
debug(22, 3) ("refreshCheck: YES: Must revalidate stale response\n");
return STALE_MUST_REVALIDATE;
         }

========================================

Patch下载地址: http://www.mipang.com/viewatt?attid=61578&disp=att&attkey=c3e9e7fa8a

加入群组开始回帖»