2

Is the HTTP verb PURGE idempotent? If I send the same PURGE request twice will I receive 200 the second time?

I have a microservice that invalidates a Varnish cache before publishing a message into a rabbit queue. In case of purge failure our need is to just log and continue the execution.

The queue consumer has to get the latest status of the resource from the Varnish cache. Will a new purge request (before actually requesting the resource from varnish) from the second microservice return success in case the first purge from the first microservice succeeded?

Gabe
  • 5,997
  • 5
  • 46
  • 92

2 Answers2

6

PURGE is not a standard HTTP method. It is just something configured in Varnish VCL - usually in this fashion or similar:

if (req.method == "PURGE") {
        if (!client.ip ~ purge) {
                return(synth(405,"Not allowed."));
        }
        return (purge);
}

(See: https://www.varnish-cache.org/docs/trunk/users-guide/purging.html)

When you call PURGE on a resource (URL) it will be removed from the cache (Varnish) so for the next GET request on the same resource Varnish will call the backend and cache its response. If you then call PURGE again on this resource it will be evicted from the cache again.

Ronald
  • 2,864
  • 3
  • 25
  • 36
  • Well but I'll send a purge twice without requesting the resource meanwhile. Will I receive 200 twice? – Gabe Feb 25 '16 at 17:26
  • @GaSacchi: why not just try it and see what actually happens? – Remy Lebeau Oct 05 '16 at 20:44
  • Because when I posted the question I didn't have access to that env. As you can see from my comment above and my answer I did try later on.. :) – Gabe Oct 06 '16 at 01:31
1

enter image description here

Yes, multipile PURGE requests return 200.

Gabe
  • 5,997
  • 5
  • 46
  • 92
  • Wondering what's that **Error** 200 Purged though.. (It's returned also on the first purge request) – Gabe Apr 10 '16 at 16:29