0
if (req.url == "/") {
  return(pass);
}

Does this allow us to cancel the varnish only on the homepage (ex: www.prism.com) and not other pages like www.prism.com/product?

I was thinking this would also work, but I am not sure, and is the above the better option?

if (req.url ~ "") {
  return(pass);
}

I just want it to skip caching on the homepage, because we're using it to set a cookie for all users. I need to modify the caching, because I realized some code for generating cookies didn't work during peak hours.

Sayaman
  • 187
  • 1
  • 11

1 Answers1

1

The following code is indeed to right way to bypass the cache on the homepage:

if (req.url == "/") {
    return(pass);
}

However, please consider the impact of such an action. The homepage is the point of entry for the majority of your users. Not being able to cache it will have a severe impact on your performance.

The question is: what kind of cookie are you setting on the homepage?

  • Is this cookie really required?
  • Could to cookie be synthesized and created by Varnish instead?
  • Could the cookie be set by Javascript instead.

Please consider your options and try to look for a solution where your most important page is still cached.

As a side-effect, you'll need to write the necessary VCL to deal with the Cookie request header for incoming requests that are considered cacheable.

Thijs Feryn
  • 1,166
  • 4
  • 5