<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;
mso-fareast-language:EN-US;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="FR-CA" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-CA" style="color:#1F497D">I found my issue… It had nothing to do with the max-age=0 after all, not with the way I was setting beresp.ttl either. I forgot to strip Set-Cookie from the backend response and that's why it wasn't
caching… /facepalm.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA" style="color:#1F497D">Thanks for your help!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-CA" style="color:windowtext;mso-fareast-language:FR-CA">De :</span></b><span lang="EN-CA" style="color:windowtext;mso-fareast-language:FR-CA"> Bender, Charles [ma</span><span lang="FR" style="color:windowtext;mso-fareast-language:FR-CA">ilto:charles@beachcamera.com]
<br>
<b>Envoyé :</b> jeudi 20 juillet 2017 14:25<br>
<b>À :</b> Girouard, Yanick <Yanick.Girouard@stm.info>; varnish-misc@varnish-cache.org<br>
<b>Objet :</b> Re: Varnish and max-age=0<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p><span style="font-size:10.0pt;font-family:"Verdana",sans-serif">Yanick,</span><span style="font-size:12.0pt;mso-fareast-language:FR-CA"><o:p></o:p></span></p>
<p><span style="font-size:10.0pt;font-family:"Verdana",sans-serif">You may just need to set beresp.ttl to a value and Varnish should obey it. And possibly unset cookies. For example-</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:10.0pt;font-family:"Verdana",sans-serif">sub vcl_backend_response {<br>
if (bereq.url ~ "somepage\.php" && beresp.status == 200) {<br>
unset beresp.http.cache-control;<br>
beresp.http.set-cookie;<br>
set beresp.ttl = 3600s;<br>
return(deliver);<br>
}<br>
<br>
Above example removes cache-control and set-cookie headers (by default Varnish will not cache responses that set cookies), sets TTL to 3600 seconds, and delivers response.</span><o:p></o:p></p>
<div>
<p class="MsoNormal">On 07/20/2017 02:14 PM, Girouard, Yanick wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">We use Varnish to cache for multiple backends and need Varnish to
<b>always</b> control what is cached despite what backends could respond. In other words, even if a backend sets Cache-Control headers to never cache its pages, we still want Varnish to cache them based on defined rules (i.e. certain URL patterns or hosts have
different TTLs).</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">We have recently realized that one of our backend always set the following header:
<b>Cache-Control: max-age=0, private, must-revalidate</b></span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">Our VCL unsets the Cache-Control header in vcl_backend_response and sets its own before delivering. By unsetting the Cache-Control header in vcl_backend_response I would expect Varnish to ignore the max-age=0 value and
still cache the page as per our other rules, but it seems that the second it sees max-age=<b>0
</b>in the response header, that it makrs the object as not cacheable.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">Other than by changing the backend's response to never set max-age=0, is there a way to force Varnish to cach pages even if it returned max-age=0?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">Is this even by design or is it a bug?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA">Thanks, </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span lang="EN-CA" style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#4F5150;mso-fareast-language:FR-CA">Yanick Girouard</span></b><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-CA"> </span><o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif;mso-fareast-language:FR-CA"><o:p> </o:p></span></p>
</div>
</body>
</html>