我有一個位於光油後面的Plone網站。除了一件事外,所有的工作都可以。清漆:POST數據後清除緩存
這是一個動態網站,因此會不時有新的內容。場景如下:
我有一個顯示項目列表的頁面。此頁面已被緩存。因此,我通過某種形式添加了另一個項目,並返回到同一頁面,但未顯示新項目。這是因爲顯示的頁面來自緩存並且仍在TTL內。
如何確保在提交新項目時,該頁面將從緩存中清除,並且將顯示來自後端服務器的具有新項目的新頁面?
我簡單的VCL被如圖所示:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.request != "GET" && req.request != "HEAD") {
# We only deal with GET and HEAD by default
return (pass);
}
# remove unnecessary cookies
if (req.http.cookie ~ "wc.cookiecredentials|Path|Domain") {
# found wc.cookiecredentials in request, passing to backend server
return (lookup);
} else {
unset req.http.cookie;
}
}
sub vcl_fetch {
#unset beresp.http.Set-Cookie;
set beresp.ttl = 12h;
return(deliver);
}
# Routine used to determine the cache key if storing/retrieving a cached page.
sub vcl_hash {
# Do NOT use this unless you want to store per-user caches.
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}
sub vcl_deliver {
# send some handy statistics back, useful for checking cache
if (obj.hits > 0) {
set resp.http.X-Cache-Action = "HIT";
set resp.http.X-Cache-Hits = obj.hits;
} else {
set resp.http.X-Cache-Action = "MISS";
}
}
還是把它說白了,我怎麼能清除或清除整個緩存域每當我收到一個POST請求?
感謝您的回答@Ketola。每當我收到POST請求時,是否有辦法清除整個緩存? – Frankline
確實有。我已經更新了我的答案,以涵蓋此替代方案。雖然這不是一個非常有效的解決方案,並且在這種情況下,緩存命中率永遠不會很高。 – Ketola
這應該是我現在的目的。 – Frankline