[英]Can I invalidate an arbitrary cache entry with Varnish?
我正在研究是否可以使用Varnish加速REST API。
基本上,我想将GET
请求缓存很长时间。 但是,当收到PUT
/ POST
/ DELETE
请求时,我想解析URL,并根据找到的信息来清除缓存条目。
例如:
GET /documents/:docType // return document list for specified docType
DELETE /document/:docType/:docId // delete a document
GET /documents/A0 <-- cached
GET /documents/A1 <-- cached
DELETE /document/A0/333 <-- first entry is purged
我可以用VCL实现吗?
我建议在此清漆教程条目中说明清除和禁止。
清除时要小心,因为您不应该允许所有人清除URL。
为此,您应该执行以下操作:
# IPs allowed to purge
acl purgeIps {
"localhost";
"192.168.55.0"/24;
}
然后,必须在vcl_recv中决定何时清除/禁止:
if (req.request == "PUT" ||
req.request == "POST" ||
req.request == "DELETE"){
if (!client.ip ~ purgeIps) {
error 405 "Not allowed.";
}
purge; #I'm not sure if purge can be done here, if it doesn't work you should use it in vcl_hit and vcl_miss
# Also, if purge does not work here you should change this line for return(lookup);
error 200 "Purged";
}
在这里您可以找到有关禁止和清除的更多示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.