[Varnish 4] Respecting client's Cache-Control: max-age= as TTL

Martynas Jusevičius martynas at atomgraph.com
Mon Jul 31 17:42:16 CEST 2017


Hi,

I have been reading quite a bit about Varnish and VCL but found almost no
examples with Cache-Control coming from the client request [1].

What I want to achieve: if the client sends Cache-Control: max-age=60, TTL
becomes 60 s. If the cache hit is fresher than 60 s, deliver it, otherwise
fetch a new response from backend (I hope I'm not misusing the VCL terms
here) *and* cache it.

I had hacked this together in the vcl_fetch section in Varnish 3.x by
setting the req.http.Cache-Control max-age value as beresp.ttl, but
vcl_fetch is gone in Varnish 4.x.

I have received a suggestion to use vcl_hit and/or grace [2], but again --
no examples...

Could anyone provide some VCL pseudo-code that uses req.http.Cache-Control
value to override TTL? max-age number parsing not necessary, I have figure
that out.

Thanks,

Martynas

[1]
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Cache_request_directives
[2]
https://github.com/varnishcache/varnish-cache/issues/2014#issuecomment-319096566
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170731/5255041f/attachment.html>


More information about the varnish-misc mailing list