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

Guillaume Quintard guillaume at varnish-software.com
Mon Jul 31 21:11:40 CEST 2017


man vcl

bereq is filtered to avoid side effects of the client forcing the ttl to
the backed.

Anyway, by the time you have access to bereq, it's too late for you since
the decision to go to the backend has already been been made.

-- 
Guillaume Quintard


On Jul 31, 2017 19:56, "Martynas Jusevičius" <martynas at atomgraph.com> wrote:

Thanks. What was mostly unclear to me is passing the req header value all
the way to where it's used to set TTL.

Why doesn't bereq contain the req headers? At least Cache-Control is gone.

But I guess that can be done using obj.ttl, which I didn't know about. Any
documentation on that?

On Mon, 31 Jul 2017 at 18.38, Guillaume Quintard <
guillaume at varnish-software.com> wrote:

> 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" <martynas at atomgraph.com>
> 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
>> varnish-misc at varnish-cache.org
>> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170731/8a70f64d/attachment-0001.html>


More information about the varnish-misc mailing list