<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 23, 2014 at 11:44 AM, Federico Schwindt <span dir="ltr"><<a href="mailto:fgsch@lodoss.net" target="_blank">fgsch@lodoss.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi,<br><br>After Per's recent post (1) and discussing it with him here's a patch that uses this to initialize beresp.grace.<br>
I've reused cache_rfc2616.c but perhaps this should be moved into its own file, i.e. cache_rfc5861.c.<br>
Comments?<br><br></div></blockquote><div><br></div><div>RFC5861 ads two subheaders to Cache-control, stale-while-revalidate and stale-while-error. I think it makes sense to parse these in Varnish because it is much more convenient to have the backend issue the policy on each response, instead of having lots and lots of VCL.</div>
<div><br></div><div>The semantics would be to parse both stale-while-revalidate and stale-while-error, set beresp.grace to the biggest.</div><div><br></div><div>The problematic part is delivery, where one would have to have a bit more logic in vcl_hit. So vcl_hit would maybe look something like this:</div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"><br></span></div><div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap">if (std.healthy(req.backend_hint)) {</span></div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> # backend healthy. </span></div><div><span style="font-size:13.63636302947998px;color:rgb(51,51,51);font-family:monospace,serif;line-height:21px;white-space:pre-wrap"> if (obj.ttl + </span><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.333333969116211px;line-height:21px;white-space:pre-wrap">obj.cachecontrol.stale-while-revalidate</span><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> > 0s) {</span></div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> return(deliver);</span></div><div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> } else {</span></div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> return(fetch);</span></div><div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> }</span></div>
<div><font color="#333333" face="monospace, serif"><span style="line-height:21px;white-space:pre-wrap">} else {</span></font></div><div><font color="#333333" face="monospace, serif"><span style="line-height:21px;white-space:pre-wrap"> # backend is not healthy, do stale-while-error</span></font></div>
<div><span style="font-size:13.63636302947998px;color:rgb(51,51,51);font-family:monospace,serif;line-height:21px;white-space:pre-wrap"> if (obj.ttl + </span><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.333333969116211px;line-height:21px;white-space:pre-wrap">obj.cachecontrol.stale-while-error</span><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> > 0s) {</span></div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> return(deliver);</span></div><div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> } else {</span></div>
<div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> return(fetch);</span></div><div><span style="color:rgb(51,51,51);font-family:monospace,serif;font-size:13.63636302947998px;line-height:21px;white-space:pre-wrap"> }</span></div>
<div><font color="#333333" face="monospace, serif"><span style="line-height:21px;white-space:pre-wrap">} </span></font></div></div><div><br></div><div>One of the problems here is that the logic relies on a probe being active on the backend. In my experience the added complexity is worth it, a lot of the "low end" users out there have mental barriers writing VCL but have no problems adding a header or two to their PHP application. The stale-while-revalidate functionality has been in Squid for quite some time and I believe there is support for ATS as well. Nginx or Apache mod_proxy does not seem to have any support for this, but those aren't very ambitious proxies, imho.</div>
<div><br></div><div><br></div><div><br></div><div><br></div>-- <br><div dir="ltr"><div style="font-size:12.727272033691406px;margin:5px 15px 0px 0px;padding-bottom:5px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">
<table border="0" cellpadding="0" cellspacing="0" style="text-align:start;font-size:12px;line-height:1.5em;font-family:'Helvetica Neue',Arial,sans-serif;color:rgb(102,102,102);width:550px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(238,238,238);border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);margin-top:20px;padding-top:5px;padding-bottom:5px">
<tbody><tr><td width="100" style="font-family:arial,sans-serif;margin:0px"><a href="http://www.varnish-software.com/" style="color:rgb(17,85,204)" target="_blank"><img src="http://www.varnish-software.com/static/media/logo-email.png" style="float: left; margin-left: 10px;"></a></td>
<td style="font-family:arial,sans-serif;margin:0px"><b style="font-size:14px;color:rgb(34,34,34)">Per Buer</b><br>CTO | Varnish Software<br><br></td></tr></tbody></table><div></div></div><div style="font-size:12.727272033691406px;margin:15px 0px;clear:both;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">
</div></div>
</div></div>