<div dir="ltr"><div dir="auto">Hi Uday,<div dir="auto"><br></div><div dir="auto">Ultimately, you'll probably want to learn and use this vmod: <a href="https://github.com/Dridi/libvmod-querystring" target="_blank">https://github.com/Dridi/libvmod-querystring</a> , but in the meantime, we can use a quick hack.</div><div dir="auto"><br></div><div dir="auto">Essentially, we don't need to modify the URL, but we can just alter the cache key computation.</div><div dir="auto"><br></div><div dir="auto">By default, the key logic looks like this:</div><div dir="auto"></div><div dir="auto"><pre style="font-family:ui-monospace,sfmono-regular,"sf mono",menlo,consolas,"liberation mono",monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;padding:16px;line-height:1.45;color:rgb(31,35,40);border-radius:6px">sub vcl_hash {
    hash_data(req.url);
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }
    return (lookup);
}</pre></div><div dir="auto">(It's done by default if you don't have a vcl_hash section in your VCL)</div><div dir="auto">We can tweak it slightly so that we ignore the whole querystring:</div><div dir="auto"></div><div dir="auto"><pre style="font-family:ui-monospace,sfmono-regular,"sf mono",menlo,consolas,"liberation mono",monospace;font-size:13.6px;margin-top:0px;margin-bottom:16px;padding:16px;line-height:1.45;color:rgb(31,35,40);border-radius:6px">sub vcl_hash {
    hash_data(regsub(req.url, "\?.*",""));
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }
    return (lookup);
}</pre>It's crude, but should do the job. To use it, just copy the code above in your VCL, for example just after the vcl_recv definition (not inside it though). Of course, if you already have a vlc_hash definition in your code, you'll need to modify that one, instead of adding a new one.<br></div><div dir="auto"><br></div><div dir="auto">Relevant documentation:<br>- <a href="https://varnish-cache.org/docs/trunk/users-guide/vcl-hashing.html">https://varnish-cache.org/docs/trunk/users-guide/vcl-hashing.html</a><br>- <a href="https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/">https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/</a></div><div dir="auto"><br></div><div>Last note: it would probably be better if the tomcat server didn't need that unique parameter, or at the very least, if Varnish could just add it itself rather than relying on client information as you're caching something public using something that was user-specific, so there's potential for snafus here.<br></div><div dir="auto"><br></div><div><font face="sans-serif">Hope that helps,</font></div><div><font face="sans-serif"><br></font></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 30, 2023, 03:45 Uday Kumar <<a href="mailto:uday.polu@indiamart.com" target="_blank">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><font face="arial, sans-serif"><span id="m_-2000533075358719500m_-6015162547979472214gmail-docs-internal-guid-145a922b-7fff-0263-4db5-5543f45c4c83"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">Hello everyone,</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">In our system, we're currently using Varnish Cache in front of our Tomcat Server for caching content.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">As part of our new requirement, we've started passing a </span><span style="color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">unique parameter</span><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap"> with every URL. The addition of this unique parameter in each request is causing a cache miss, as Varnish treats each request as distinct due to the difference in the parameter. Our intent is to have Varnish ignore this specific parameter for caching purposes, so that it can treat similar requests with different unique parameters as identical for caching purposes.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-style:italic;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">Expected Functionality of Varnish:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">1. We need Varnish to </span><span style="color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">ignore the unique parameter</span><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap"> when determining if a request is in the cache or while caching a request.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">2. We also need Varnish to </span><span style="color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">retain this unique parameter in the request URL when it's passed along to the Tomcat Server</span><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">.</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;font-variant-alternates:normal;vertical-align:baseline;white-space:pre-wrap">We're looking for a way to modify our Varnish configuration to address the above issues, your assistance would be greatly appreciated.</span></p></span><br></font></div><div><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><font face="arial, sans-serif" color="#000000">Thanks & Regards</font><div><font face="arial, sans-serif" color="#000000">Uday Kumar</font></div></div></div></div></div>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" rel="noreferrer" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
</blockquote></div>