Question

I am new to Varnish and I am struggling to see why so many requests are either a miss, or hit_for_pass.

I have added unset req.http.Cookie; inside vcl_recv to (if I am right) effectively ignore all cookies and cache regardless of cookies? Is this right?

But despite this I am still getting no hits. So this cookie approach is either wrong or there is an entirely different reason why this is not working.

Any ideas on this, or is there a way to see exactly why I am getting hit_for_pass or miss so often.

Thanks Jake

EDIT

Some more Googling and I found this

sub vcl_fetch {
    unset beresp.http.set-cookie; 
}

So I guess this removes the cookie from the response object, can someone explain why this now works and what it is I have done to get it working?

EDIT2

A second look at varnishstat shows this isn't working as I expected and I am still getting many many misses.

Was it helpful?

Solution

Chances are, if you're getting a lot of hit_for_pass decisions, you've also got very little in the cache itself, hence the misses.

hit_for_pass is only thrown from the vcl_fetch method, I believe, so it is worth looking at what your server is returning. Things to consider include:

  • remove beresp.http.Cache-Control; and remove beresp.http.Pragma; to stop your backend applications from blocking caching.

  • remove beresp.http.Expires; to avoid now/past expiry dates (you may wish to change this to a far-future expires depending on what you're serving).

  • If your app is not serving cookies, then remove beresp.http.Set-Cookie; will have a big impact on your hit_for_pass rates.

  • Make sure you are setting an appropriate beresp.ttl value.

I'd also recommend that you read this article about the 'Accept-Encoding' header (the code in the example goes in the vcl_recv method).

OTHER TIPS

For others who may have this issue, this was useful.

https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader

Setting headers to show what is and is not cached and why.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top