Enforce 503 caching in 3 (beresp.ttl =?utf-8?Q?=3D_?=beresp.Cache-Control.max-age)
Kent Karlsson
vogonistic at gmail.com
Thu Aug 9 01:03:22 CEST 2012
We have a service that returns 503 errors with Cache-Control: max-age=X. In Varnish 2 it was easy to get it to cache and get the appropriate ttl with a block like this:
sub vcl_fetch {
if (beresp.status == 503) {
set beresp.cacheable = true;
}
}
Now that beresp.cacheable is removed in varnish 3, how do I set beresp.ttl to the contents of Cache-Control: max-age?
This is the best I've come up with so far, but it doesn't take Age into account and it's a bit ugly in my opinion:
if (beresp.status == 503 && beresp.http.Cache-Control ~ "max-age") {
set beresp.ttl = std.duration(regsub(beresp.http.Cache-Control, "^.*max-age=([0-9]+).*$", "\1s"), 1s);
}
Does anyone have a better solution?
-- kent
More information about the varnish-misc
mailing list