Last Updated: February 25, 2016
·
1.821K
· theist

Vanish 4 effectively detect HIT / MISS in VCL

From V4 obj.hits no longer reports the number of hits for a cached object, so a cache MISS does't mean a obj.hits == 0

Some on the Varnish misc list states that varnish sets the X-Varnish header with two numbers when it is a hit and only one if not. So you ned somethig like this to get HIT/MISS in a header:

sub vcl_deliver {
  if (resp.http.X-Varnish ~ "[0-9]+ +[0-9]+") {
    set resp.http.X-Cache = "HIT";
  } else {
    set resp.http.X-Cache = "MISS";
  }
}