Is the HTTP method PURGE idempotent in Varnish?

半城伤御伤魂 提交于 2019-12-29 01:45:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!