如何让 Varnish 停止缓存 ESI 片段

发布于 2024-11-30 01:29:09 字数 955 浏览 2 评论 0原文

我在成功使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-12-07 01:29:10

我首先尝试完全跳过 *.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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文