是否有人为Varnish 4工作了更新的命中未命中标题?
我找到的最后一个是版本3.
https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader#Varnish3.0
寻找这些:
set beresp.http.X-Cacheable = "NO:Not Cacheable"; "NO:Got Session";
"NO:Cache-Control=private"; "YES";
以及可能的其他有用的调试输出,以解释为什么错过请求。
答案 0 :(得分:11)
是的,I have:
sub vcl_deliver {
if (obj.hits > 0) { # Add debug header to see if it's a HIT/MISS and the number of hits, disable when not needed
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
# Please note that obj.hits behaviour changed in 4.0, now it counts per objecthead, not per object
# and obj.hits may not be reset in some cases where bans are in use. See bug 1492 for details.
# So take hits with a grain of salt
set resp.http.X-Cache-Hits = obj.hits;
}
将所请求标题的清漆3版本直接翻译为清漆4:
sub vcl_backend_response {
if (bereq.http.Cookie ~ "(UserID|_session)") {
set beresp.http.X-Cacheable = "NO:Got Session";
set beresp.uncacheable = true;
return (deliver);
} elsif (beresp.ttl <= 0s) {
# Varnish determined the object was not cacheable
set beresp.http.X-Cacheable = "NO:Not Cacheable";
} elsif (beresp.http.set-cookie) {
# You don't wish to cache content for logged in users
set beresp.http.X-Cacheable = "NO:Set-Cookie";
set beresp.uncacheable = true;
return (deliver);
} elsif (beresp.http.Cache-Control ~ "private") {
# You are respecting the Cache-Control=private header from the backend
set beresp.http.X-Cacheable = "NO:Cache-Control=private";
set beresp.uncacheable = true;
return (deliver);
} else {
# Varnish determined the object was cacheable
set beresp.http.X-Cacheable = "YES";
}
# ....
return(deliver);
}
有一些关于upgrading to Varnish 4的文档涵盖了这些内容:
vcl_fetch现在是vcl_backend_response
使用beresp.uncacheable 创建hit_for_pass对象
req。*在vcl_backend_response
中不可用req。*以前在vcl_fetch中可用,但在功能拆分后,您只有bereq。*&#39;在vcl_backend_response。