Determining a HIT or a MISS in Varnish 4 VCL

Umesh Telang Umesh.Telang at bbc.co.uk
Thu Apr 2 14:28:49 CEST 2015


Hello,

It's unclear if the way to detect whether a particular response was the result of a cache hit or miss in VCL, has changed from Varnish 3 to Varnish 4.

At this page (not an official Varnish page...), it suggests using the value of resp.http.X-Varnish (whether it has a single or multiple values) to determine this:
http://foshttpcache.readthedocs.org/en/latest/varnish-configuration.html#

Alternatively I've also seen suggestions for continuing to use obj.hits in vcl_deliver. e.g. :
sub vcl_deliver {
if (obj.hits > 0) { # Add debug header to see if it's a HIT/MISS and the number of hits, disable when not needed
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}

We've observed that the value of %{Varnish:handling}x in the varnish ncsa log has been accurate in reporting HITs vs MISSes. Could we use a VCL equivalent of this in vcl_deliver to determine whether a particular response is the result of a HIT or a MISS?

Any advice on the recommended way in VCL to determine whether a response is the result of a HIT or MISS would be greatly appreciated!

Thanks,
Umesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20150402/e2826fd5/attachment.html>


More information about the varnish-misc mailing list