2
votes

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**

1
And what headers does a request for the fragment return?symcbean

1 Answers

0
votes

I'd first try completely skipping the cache for *.esi URLs, i.e. return(pass); instead of set beresp.ttl = 0s;