簡體   English   中英

我可以使用Varnish使任意緩存條目無效嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM