问题
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?
回答1:
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.
回答2:
Yes, multipile PURGE requests return 200.
来源:https://stackoverflow.com/questions/35632607/is-the-http-method-purge-idempotent-in-varnish