<div dir="ltr"><div>Hi,</div><div><br></div><div>Relevant documentation:</div>- <a href="https://varnish-cache.org/docs/trunk/users-guide/vcl-hashing.html" target="_blank">https://varnish-cache.org/docs/trunk/users-guide/vcl-hashing.html</a><br><div>- <a href="https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/" target="_blank">https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/</a></div><div>- <a href="https://varnish-cache.org/docs/trunk/users-guide/vcl-built-in-code.html">https://varnish-cache.org/docs/trunk/users-guide/vcl-built-in-code.html</a></div><div><br></div><div>Essentially: if you don't use a return statement, then the built-in vcl code is executed, and so the logic will be different with and without that statement.</div><div><br></div><div>You wrote that the code isn't working, but don't explain further, which makes it hard to debug, my best guess is that you're hashing too much because of the built-in code.</div><div>One thing you can do is this:</div><div>```</div><div>sub vcl_deliver {</div><div> set resp.http.req-hash = req.hash;</div><div> ...<br></div><div>}</div><div>```</div><div>That will allow you to see objects get the same hash, or a different one. On that topic, I'm pretty certain that hashing the Accept-Encoding header is useless
and will fragment your cache needlessly, as Varnish already takes that
header into account implicitly.</div><div><br></div><div>Note that the vcl I shared in my last email doesn't have a vcl_hash function because it relies entirely on modifying the url before it is hashed by the built-in vcl.</div><div><br></div><div>Hope that helps.</div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div><div>Guillaume Quintard<br></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 5, 2023 at 4:31 AM Uday Kumar <<a href="mailto:uday.polu@indiamart.com">uday.polu@indiamart.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello Guillaume,</div><div dir="ltr"><br></div><div dir="ltr">Thanks for the update!</div><div dir="ltr"><br></div><div dir="ltr"><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote">(It's done by default if you don't have a vcl_hash section in your VCL)<br>We can tweak it slightly so that we ignore the whole querystring:<br>sub vcl_hash {<br> hash_data(regsub(req.url, "\?.*",""));<br> if (req.http.host) {<br> hash_data(req.http.host);<br> } else {<br> hash_data(server.ip);<br> }<br> return (lookup);<br>}<br></div></div></blockquote></div></blockquote></div></blockquote></div></blockquote><div><br></div><div>Would like to discuss about above suggestion. </div><div><br></div><div><b>FYI:</b></div><div><b>In our current vcl_hash subroutine, we didnt had any return lookup statement in production , and the code is as below</b></div><div>#Working</div><div>sub vcl_hash{<br> hash_data(req.url);<br> hash_data(req.http.Accept-Encoding);<br>}</div><div>The above code is <i style="background-color:rgb(255,255,0)"><b>working without any issues on production even without return (lookup)</b></i> statement.</div><div><br></div><div>For our new requirement <b> to ignore the parameter in URL while caching, </b> as per your suggestion we have made changes to the vcl_hash subroutine, new code is as below.</div><div><br></div><div>#Not Working</div><div>sub vcl_hash{<br> set req.http.hash-url = regsuball(req.url, "traceId=.*?(\&|$)", "");<br> hash_data(req.http.hash-url);<br> unset req.http.hash-url;<br> hash_data(req.http.Accept-Encoding);<br>}</div><div><br></div><div>The above code is<span style="background-color:rgb(244,204,204)"> <b>not hashing the URL by ignoring traceId (not as expected)</b></span><b style="background-color:rgb(255,255,0)"> but if I add return lookup at the end of subroutine its working as expected.</b></div><div><br></div><div>#Working Code</div><div>sub vcl_hash{<br> set req.http.hash-url = regsuball(req.url, "traceId=.*?(\&|$)", "");<br> hash_data(req.http.hash-url);<br> unset req.http.hash-url;<br> hash_data(req.http.Accept-Encoding);</div><div> <b>return (lookup);</b><br>}<br></div><div><br></div><div><br></div><div><b>I have few doubts to be clarified:</b></div><div><div>1. May I know what difference return (lookup) statement makes?</div><div>2. Will there be any side effects with modified code, if I use return (lookup)? (Because original code was not causing any issue even without return lookup in production)</div></div><div> <br></div></div></div>
</blockquote></div>