<div dir="ltr">Sorry, sent too soon. Here it goes:<div><br></div><div><div style="font-size:12.8px"><div>Thanks Guillaume.</div><div><br></div><div>First I tried <span style="font-size:12.8px">return(fetch) </span><span style="font-size:12.8px">as you suggested</span></div><div><br></div><div><div>sub vcl_hit {</div><div>    if (req.http.Cache-Control ~ "max-age=[0-9]*") {</div><div>        set req.http.Max-Age = regsub(req.http.Cache-Control, "max-age=([0-9]*)", "\1");</div><div>        if (obj.age > std.duration(req.http.Max-Age + "s", 1000000s)) {</div><div>            std.log("obj.age: " + obj.age + " req.http.Max-Age: " + req.http.Max-Age);</div><div>            return(fetch);</div><div>        }</div><div>    }</div></div><div>    ...</div><div><br></div><div>but I got an error:</div><div><br></div><div>-   VCL_call       HIT</div><div>-   ReqHeader      Max-Age: 69</div><div>-   VCL_Log        obj.age: 102.306 req.http.Max-Age: 69</div><div>-   VCL_return     fetch</div><div>-   VCL_Error      change return(fetch) to return(miss) in vcl_hit{}</div><div>-   VCL_Error      vcl_hit{} returns miss without busy object.  Doing pass.</div><div>-   VCL_call       PASS</div><div>-   VCL_return     fetch</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I did as told and I tried <span style="font-size:12.8px">return(miss)</span></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div style="font-size:12.8px">sub vcl_hit {</div><div style="font-size:12.8px">    if (req.http.Cache-Control ~ "max-age=[0-9]*") {</div><div style="font-size:12.8px">        set req.http.Max-Age = regsub(req.http.Cache-Control, "max-age=([0-9]*)", "\1");</div><div style="font-size:12.8px">        if (obj.age > std.duration(req.http.Max-Age + "s", 1000000s)) {</div><div style="font-size:12.8px">            std.log("obj.age: " + obj.age + " req.http.Max-Age: " + req.http.Max-Age);</div><div style="font-size:12.8px">            return(miss);</div><div style="font-size:12.8px">        }</div><div style="font-size:12.8px">    }</div><div style="font-size:12.8px">    ...</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">but then I got another error:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div style="font-size:12.8px">-   VCL_call       HIT</div><div style="font-size:12.8px">-   ReqHeader      Max-Age: 69</div><div style="font-size:12.8px">-   VCL_Log        obj.age: 195.391 req.http.Max-Age: 69</div><div style="font-size:12.8px">-   VCL_return     miss</div><div style="font-size:12.8px">-   VCL_Error      vcl_hit{} returns miss without busy object.  Doing pass.</div><div style="font-size:12.8px">-   VCL_call       PASS</div><div style="font-size:12.8px">-   VCL_return     fetch</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So it looks like the max-age logic is triggered correctly, but what is wrong with the return values?</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 1, 2017 at 12:01 AM, Martynas Jusevičius <span dir="ltr"><<a href="mailto:martynas@atomgraph.com" target="_blank">martynas@atomgraph.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Thanks Guillaume.</div><div><br></div><div>First I tried</div><div><br></div><div><div>sub vcl_hit {</div><div>    if (req.http.Cache-Control ~ "max-age=[0-9]*") {</div><div>        set req.http.Max-Age = regsub(req.http.Cache-Control, "max-age=([0-9]*)", "\1");</div><div>        if (obj.age > std.duration(req.http.Max-Age + "s", 1000000s)) {</div><div>            std.log("obj.age: " + obj.age + " req.http.Max-Age: " + req.http.Max-Age);</div><div>            return(fetch);</div><div>        }</div><div>    }</div></div><div>    ...</div><div><br></div><div>but I got an error:</div><div><br></div><div>-   VCL_call       HIT</div><div>-   ReqHeader      Max-Age: 69</div><div>-   VCL_Log        obj.age: 102.306 req.http.Max-Age: 69</div><div>-   VCL_return     fetch</div><div>-   VCL_Error      change return(fetch) to return(miss) in vcl_hit{}</div><div>-   VCL_Error      vcl_hit{} returns miss without busy object.  Doing pass.</div><div>-   VCL_call       PASS</div><div>-   VCL_return     fetch</div></div></div><div><br></div><div>I did as told and I tried</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 9:11 PM, Guillaume Quintard <span dir="ltr"><<a href="mailto:guillaume@varnish-software.com" target="_blank">guillaume@varnish-software.<wbr>com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>man vcl<div dir="auto"><br><div dir="auto">bereq is filtered to avoid side effects of the client forcing the ttl to the backed.</div><div dir="auto"><br></div><div dir="auto">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.</div><span class="m_-380998739932775428HOEnZb"><font color="#888888"><div dir="auto"><br><div data-smartmail="gmail_signature" dir="auto">-- <br>Guillaume Quintard </div></div></font></span></div><div><div class="m_-380998739932775428h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Jul 31, 2017 19:56, "Martynas Jusevičius" <<a href="mailto:martynas@atomgraph.com" target="_blank">martynas@atomgraph.com</a>> wrote:<br type="attribution"><blockquote class="m_-380998739932775428m_-6498831793997542946quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks. What was mostly unclear to me is passing the req header value all the way to where it's used to set TTL.<br><br>Why doesn't bereq contain the req headers? At least Cache-Control is gone.<br><br>But I guess that can be done using obj.ttl, which I didn't know about. Any documentation on that?<div class="m_-380998739932775428m_-6498831793997542946elided-text"><br><div class="gmail_quote"><div dir="ltr">On Mon, 31 Jul 2017 at 18.38, Guillaume Quintard <<a href="mailto:guillaume@varnish-software.com" target="_blank">guillaume@varnish-software.co<wbr>m</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">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.<div dir="auto"><br></div><div dir="auto">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.<br><br><div data-smartmail="gmail_signature" dir="auto">-- <br>Guillaume Quintard </div></div></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On Jul 31, 2017 18:25, "Martynas Jusevičius" <<a href="mailto:martynas@atomgraph.com" target="_blank">martynas@atomgraph.com</a>> wrote:<br type="attribution"></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>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].</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>I have received a suggestion to use vcl_hit and/or grace [2], but again -- no examples...</div><div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div><br></div><div>Martynas</div><div><br></div><div>[1] <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Cache_request_directives" target="_blank">https://developer.mozilla.<wbr>org/en-US/docs/Web/HTTP/Header<wbr>s/Cache-Control#Cache_request_<wbr>directives</a></div><div>[2] <a href="https://github.com/varnishcache/varnish-cache/issues/2014#issuecomment-319096566" target="_blank">https://github.com/varnish<wbr>cache/varnish-cache/issues/201<wbr>4#issuecomment-319096566</a></div></div>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/varnish<wbr>-misc</a><br></blockquote></div></div>
</blockquote></div>
</div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>