如何让 Varnish 停止缓存 ESI 片段
我在成功使用 ESI 和 Varnish 3.0 以及 repoze.bfg 项目时遇到问题。我有一个 ESI 片段,它通过 ESI 标签显示登录用户的通知。但是,varnish 会缓存包含的 ESI 片段,因此对片段所做的更改(无论是手动还是会话结果)不会反映在包含(和缓存)的网页中。
使用的 ESI 标签:
VCL配置:
sub vcl_recv {
if (req.url ~ "[A-Za-z0-9_-]*.esi$") {
return (pass);
}
if (req.http.cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
if (req.http.cookie ~ "^ *$") {
remove req.http.cookie;
}
}
remove req.http.cookie;
remove req.http.etag;
}
sub vcl_fetch {
remove beresp.http.Set-Cookie;
remove beresp.http.ETag;
#do esi processing
set beresp.do_esi = true;
if (bereq.url ~ "[A-Za-z0-9_-]*.esi$") {
set beresp.ttl = 0s;
} else {
set beresp.ttl = 24h;
}
}
我的假设是:
1)Varnish将向“path/to/fragment.esi”发出请求,并在每次从其缓存存储中获取时重新组装缓存网页,特别是因为beresp.ttl设置为0s每个 .esi 片段 2) Varnish 不会将 ESI 片段与网页一起存储在其缓存存储中**
I am having problem using ESI with Varnish 3.0 with a repoze.bfg project successfully. I have an ESI fragment that displays a notice for logged in users, included via an ESI tag. However, varnish caches the included ESI fragment, so changes made to the fragment, either manually, or as a result of a session does not reflect in the including (and cached) web page.
ESI tag as used:
VCL configuration:
sub vcl_recv {
if (req.url ~ "[A-Za-z0-9_-]*.esi$") {
return (pass);
}
if (req.http.cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
if (req.http.cookie ~ "^ *$") {
remove req.http.cookie;
}
}
remove req.http.cookie;
remove req.http.etag;
}
sub vcl_fetch {
remove beresp.http.Set-Cookie;
remove beresp.http.ETag;
#do esi processing
set beresp.do_esi = true;
if (bereq.url ~ "[A-Za-z0-9_-]*.esi$") {
set beresp.ttl = 0s;
} else {
set beresp.ttl = 24h;
}
}
My assumptions are:
1) Varnish will make requests to "path/to/fragment.esi" and the re-assemble cache web page every time it fetches from its cache store, especially since beresp.ttl is set to 0s for every .esi fragments
2) Varnish does not store the ESI fragments together with a web page in its cache store**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先尝试完全跳过 *.esi URL 的缓存,即 return(pass);而不是设置 beresp.ttl = 0s;
I'd first try completely skipping the cache for *.esi URLs, i.e. return(pass); instead of set beresp.ttl = 0s;