I am caching multiple copies of an object based on certain header values in the request using vcl hash. How do I purge them all at once?
1 Answers
My answer is based on assumption that you really want to purge as in PURGE
and not BAN
:
In case all the possible values of the certain header are known, you would use restarts coupled with setting custom header. Logic is the following:
- received
PURGE
request for object withreq.http.X-Custom == foo
return(purge)
- in
vcl_purge
, setreq.http.X-Custom = bar
, and introduce / adjust helper header with the set of values already purged, andreturn (restart)
As a result, Varnish will recursively purge all the objects.
You can see example of this approach in complete Brotli VCL implementation.
But in case the values of the certain header are really arbitrary, you can't really PURGE
them all at once. If you need this, you have to make use of Vary: X-Custom
so that Varnish will consider all those objects as one with many variations. With Vary
in place, you don't have to hash on the header and PURGE
on one variation will effectively clear out all other variations.
I like Vary
approach much better.

- 8,725
- 2
- 29
- 35