【发布时间】:2020-03-28 13:04:25
【问题描述】:
Varnish-Cache 中是否有类似 Nginx 的proxy_cache_min_uses 之类的功能,可以在对该资源进行特定数量的请求后缓存该资源? 这是Varnish-Cache plus 中的一些类似解决方案(基于slimhazard 对this issue 的评论):
import vsthrottle;
sub vcl_recv {
if (req.url ~ "^/min/use/me" && vsthrottle.is_denied(req.url, 50, 2h, 1h) {
# If the URL was requested more than 50 times during the last two hours,
# then go to cache lookup for the next hour.
return (hash);
}
else {
# Otherwise bypass the cache
return (pass);
}
}
是否有任何类似的解决方案可以用于 Varnish-Cache 本身?
【问题讨论】:
-
您可以保留后端请求的计数 - 如果它们超出限制,请设置一个标头值,强制 Varnish 缓存响应。
标签: nginx caching varnish varnish-vcl