Using ESI-tags inside a cached object
Kasper Grubbe
kaspergrubbe at gmail.com
Mon Jul 9 16:51:04 CEST 2012
I am following the guide here:
https://www.varnish-cache.org/docs/trunk/tutorial/esi.html
I have two pages in my project as of now:
1. http://127.0.0.1:3001/ (Cache-Control:max-age=60, private):
<b>Cached:</b> <%= Time.now %> <br/>
<b>ESI:</b> <esi:include src="/staticview" /> <br/>
2. http://127.0.0.1:3001/staticview (Cache-Control:max-age=1, private):
<%= Time.now %>
However, every time I request the first page, it seems like it also
caches the ESI-include result for the 60 seconds instead of refreshing
every second.
First request:
Cached: 2012-07-09 01:31:12 +0200
ESI: 2012-07-09 01:31:12 +0200
Second request (10 seconds later):
Cached: 2012-07-09 01:31:12 +0200
ESI: 2012-07-09 01:31:12 +0200
Third request (about a minute later):
Cached: 2012-07-09 01:32:19 +0200
ESI: 2012-07-09 01:32:19 +0200
Is this expected? Or am I misunderstanding the documentation?
My VCL config looks like this:
backend default {
.host = "127.0.0.1";
.port = "3000";
}
sub vcl_recv {
# Don't cache POST, PUT, or DELETE requests
if (req.request == "POST" || req.request == "PUT" || req.request ==
"DELETE") {
return(pass);
}
return(lookup);
}
sub vcl_fetch {
# We want ESI
set beresp.do_esi = true;
if (beresp.http.Cache-Control ~ "max-age") {
unset beresp.http.Set-Cookie;
return(deliver);
}
# Do not deliver into cache otherwise.
return(hit_for_pass);
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT (" +obj.hits+ ")";
} else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
Varnish is running with these parameters:
varnishd -F -a 127.0.0.1:3001 -f config/varnish/development.vcl
My Varnish version is this (running on Mac OS X, with Varnish from the
Homebrew repo):
varnishd (varnish-3.0.2 revision 55e70a4)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
--
Kasper Grubbe
Phone: (+45) 42 42 42 74
Skype: kasper.grubbe
Mail: kaspergrubbe at gmail.com
Web: http://kaspergrubbe.dk
More information about the varnish-misc
mailing list