0
votes

I have a website with a page

www.mydomain.com/product-listing/

Sometimes one of our vendors visit this page with a specific parameter set in the URL:

www.mydomain.com/product-listing/?vendor=VENDORID

All this does is print out some information in the header of the page specfic to that vendor.

I want any versions of the page, apart from those containing the vendor parameter to be cached and served by varnish - the rest to be served by the backend.

However it seems that Varnish sometimes seem to catch one of these visiting vendors and cache that result - after that the page with the header information will be returned.

There's also a cookie present: first time the vendor visits a cookie will be set so that the header information can be displayed upon returning even if the parameter isn't present. However: as far as I understand Varnish shouldn't cache if the backend sends a cookie? We do not manipulate cookies in the vcl.

My VCL:

sub vcl_recv {

    // I expect this to catch all urls with the parameter vendor present
    if (req.url ~ "vendor")
    {
        return (pass);
    }

    if (req.url ~ "^/product-listing"){
        return (hash);
    }

    return(pass);
}

Nothing in the other subroutines.

1

1 Answers

1
votes

Haven't tested this code (Varnish 4), but you may want to try changing it to the following to see if that picks it up:

if ( req.url ~ "^/\?vendor" ) {
   return (pass);
}

Also if that doesn't fix it, you could try adding the following to vcl_backend_response in addition to the above:

if (bereq.url ~ "^/product-listing" && bereq.url !~ "^/\?vendor" ) {
    unset beresp.http.set-cookie;
}

That should tell varnish to unset the response cookie as long as ?vender= is not in the URL, caching product-listing by a cookie unset, but not for product-listing/?vender=.