Need Assistance in Configuring Varnish to Retain and Ignore Unique Parameter in Request URL while caching

Uday Kumar uday.polu at indiamart.com
Mon Jun 5 11:31:04 UTC 2023


Hello Guillaume,

Thanks for the update!


(It's done by default if you don't have a vcl_hash section in your VCL)
>>>> We can tweak it slightly so that we ignore the whole querystring:
>>>> sub vcl_hash {
>>>>     hash_data(regsub(req.url, "\?.*",""));
>>>>     if (req.http.host) {
>>>>         hash_data(req.http.host);
>>>>     } else {
>>>>         hash_data(server.ip);
>>>>     }
>>>>     return (lookup);
>>>> }
>>>>
>>>
Would like to discuss about above suggestion.

*FYI:*
*In our current vcl_hash subroutine, we didnt had any return lookup
statement in production , and the code is as below*
#Working
sub vcl_hash{
       hash_data(req.url);
       hash_data(req.http.Accept-Encoding);
}
The above code is *working without any issues on production even without
return (lookup)* statement.

For our new requirement * to ignore the parameter in URL while caching, * as
per your suggestion we have made changes to the vcl_hash subroutine, new
code is as below.

#Not Working
sub vcl_hash{
    set req.http.hash-url = regsuball(req.url, "traceId=.*?(\&|$)", "");
    hash_data(req.http.hash-url);
    unset req.http.hash-url;
    hash_data(req.http.Accept-Encoding);
}

The above code is *not hashing the URL by ignoring traceId (not as
expected)** but if I add return lookup at the end of subroutine its working
as expected.*

#Working Code
sub vcl_hash{
    set req.http.hash-url = regsuball(req.url, "traceId=.*?(\&|$)", "");
    hash_data(req.http.hash-url);
    unset req.http.hash-url;
    hash_data(req.http.Accept-Encoding);
    *return (lookup);*
}


*I have few doubts to be clarified:*
1. May I know what difference return (lookup) statement makes?
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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20230605/1e098a3f/attachment-0001.html>


More information about the varnish-misc mailing list