【发布时间】:2013-01-09 04:56:16
【问题描述】:
我有一个位于 Varnish 后面的 Plone 网站。一切正常,除了一件事。
这是一个动态网站,因此会不时出现新内容。场景如下:
我有一个显示项目列表的页面。此页面已被缓存。所以我通过某种形式添加了另一个项目,并返回到同一页面,但新项目未显示。这是因为显示的页面来自缓存并且仍在其 TTL 内。
如何确保在提交新项目后,该页面会从缓存中清除,并且将显示来自后端服务器的包含新项目的新页面?
我的简单VCL如图:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD") {
# We only deal with GET and HEAD by default
return (pass);
}
# remove unnecessary cookies
if (req.http.cookie ~ "wc.cookiecredentials|Path|Domain") {
# found wc.cookiecredentials in request, passing to backend server
return (lookup);
} else {
unset req.http.cookie;
}
}
sub vcl_fetch {
#unset beresp.http.Set-Cookie;
set beresp.ttl = 12h;
return(deliver);
}
# Routine used to determine the cache key if storing/retrieving a cached page.
sub vcl_hash {
# Do NOT use this unless you want to store per-user caches.
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}
sub vcl_deliver {
# send some handy statistics back, useful for checking cache
if (obj.hits > 0) {
set resp.http.X-Cache-Action = "HIT";
set resp.http.X-Cache-Hits = obj.hits;
} else {
set resp.http.X-Cache-Action = "MISS";
}
}
或者说白了,当我收到 POST 请求时,如何清除或清除域的整个缓存?
【问题讨论】:
标签: caching varnish varnish-vcl