0

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?

manu4543
  • 508
  • 1
  • 8
  • 15

1 Answers1

1

My answer is based on assumption that you really want to purge as in PURGEand 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:

  1. received PURGE request for object with req.http.X-Custom == foo
  2. return(purge)
  3. in vcl_purge, set req.http.X-Custom = bar, and introduce / adjust helper header with the set of values already purged, and return (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.

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35