Varnish 5.2 Already Available on

Varnish Cache released their latest 5.2 version late last week and it is already available on’s globally distributed Application Edge. provides you with Varnish 5.2 on’s 60 Global PoPs right now, with:

  • Instant global cache clear;
  • Instant global configuration change;
  • Comprehensive real time logs and metrics; and
  • A git backed management workflow for complete control.’s modular, transparent Application Edge means you will never again be stuck with old software at the edge to improve your web application performance, availabilty and security.

According to Varnish most of the changes in 5.2 are transparent to users, however there are some VCL changes and new default VMODs.

Hyphens now allowed in subroutines & VMOD object names

This is just for language consistency, but subroutines and objects can now have hyphens in their names. So if you’ve been really wanting your subroutine names to use kebab-case rather than snake_case, your dreams are now a reality.

req.hash & bereq.hash variables and the blob_vmod

The hash that Varnish uses to lookup the current request in the cache is now available as a variable, so it can be sent to the client or the backend server using the new blob vmod to encode it.

import blob;

sub vcl_deliver {
    set resp.http.Hash = blob.encode(BASE64, blob=req.hash);

req.hash & bereq.hash are a BLOB data type. This represents “opaque data of any length” according to the docs, and previously this data type was only available in vmods. Because of this, Varnish has also included the blob vmod to work with this type. It can be used to create, manipulate, compare & encode blobs. See the blob vmod docs for more information on what it can do.

bereq.is_bgfetch variable

The is_bgfetch has been added to the backend request object. If true, this request to the backend is happening as a background fetch, which happens if a request comes in for which there is an stale cached object (ie its TTL has expired) but grace mode is enabled. The requesting client will be served the stale cached object and a request will be sent to the backend server to refresh the cache.

You can now change the behaviour of the request to the backend or how to process the response it sends if the request was a background fetch.


Back in the misty past of Varnish 3, there was a purge function you could call inside vcl_hit & vcl_miss which would remove the object corresponding to the current request’s hash from the cache. This was changed in Varnish 4 to a return (purge) called in vcl_recv.

The purge vmod adds 2 functions purge.hard and purge.soft.

purge.hard does the same thing as calling return (purge), but you can call it from vcl_hit & vcl_miss. It also returns the number of purged objects. You can see an example of how this can be used on the vmod docs.

purge.soft(DURATION ttl=0, DURATION grace=-1, DURATION keep=-1) allows you to update the ttl, grace and keep of a cached object. If you’re not familiar with how those 3 variables impact how long an object is retained in cache, have a look at this diagram in the Varnish Book.

If you don’t pass in any parameters, the object’s ttl will be immediately set to 0, but the grace and keep will be unchanged. This means that, if grace is enabled, subsequent requests for the object will be served the now stale object and a background fetch will be done to refresh it. If you wanted to expire the object, but have the object removed from the cache at the end of the existing grace period you would do this

purge.soft(0s, -1s, 0s);

Other changes and additions

There are a number of other updates, including a new default vmod to help with testing, a few other new VCL variables and some subtle changes to how varnishd, varnishstat and varnishlog work.

If you would like all the details check out the changes page and upgrading notes on the Varnish docs site.

Try it now

You can spin up Varnish 5.2 for your site right now by signing up with, you can try it risk-free using our Developer POP.

Alternatively, if you just want to check out some of the new language features, we’ve added Varnish 5.2 to vclFiddle

Blog Categories

Interested in articles about a specific topic? Click on a category to see all related content. Sign up

Want to get started improving your website performance, scalability, and security? Sign up for a 14 day free trial of and see what we can do for you!

Get started