On github I pointed to the doc explaining how you can return(fetch) to ignore a cached object, possibly based on ttl, so you already have half the answer.
The other part of the equation is just converting req.http.cache-control to a duration and comparing that to obj.ttl. It will be similar to what you have done on v3. -- Guillaume Quintard On Jul 31, 2017 18:25, "Martynas Jusevičius" <[email protected]> wrote: > 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 > > _______________________________________________ > varnish-misc mailing list > [email protected] > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc >
_______________________________________________ varnish-misc mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
