我試圖繞過一個後端服務器,它會不時地開始用200 OK響應來提供空白頁面,讓Varnish繼續提供這些頁面的舊緩存版本(又名。寬限模式)。如何在Varnish緩存中的對象長度爲零時使其失效?
首先,我試着檢查vcl_fetch
中的響應,但據我所知,無法找出vcl_fetch
中的內容長度。然後,我嘗試在vcl_deliver
(其中Content-Length標頭可用)處完成這項工作。這確實有效,但我無法弄清楚如何清除壞的緩存對象(帶有空白頁的那個對象),所以這似乎是不可行的。
有人建議我設置obj.grace和obj.ttl在vcl_deliver
,這是我當前的代碼:
sub vcl_deliver {
# If the front page is blank, invalidate this cached object, in hope
# that we'll get a new one.
if (req.url == "/" && std.integer(resp.http.content-length, 0) < 1000) {
set obj.grace = 0m;
set obj.ttl = 0m;
return(restart);
}
}
然而,光油不喜歡這一點,讓我當我嘗試這個錯誤加載VCL:
Message from VCC-compiler:
'obj.grace': cannot be set in method 'vcl_deliver'.
At: ('input' Line 146 Pos 9)
set obj.grace = 0m;
--------#########------
我得到同樣的錯誤obj.ttl
如果刪除obj.grace
一行 - 既不似乎是寫在vcl_deliver
,即使the docs say otherwise。這是在光油3.0.2。
的問題是,我不能想出一個辦法弄清楚,如果我們得到了'vcl_fetch'空的響應。 – mikl 2012-04-07 18:54:50
你可以。只需檢查「beresp.http.content-length」而不是「resp」,以便檢查從後端接收的內容,而不是將發送到客戶端的內容。 – 2012-04-19 12:38:55
我認爲你建議的是這樣的: if(!beresp.http.content-length){obj.grace = 5m; } 但這仍然是我的失敗。 – 2013-04-05 20:29:54