【问题标题】:Caching a resource in Varnish-Cache after specific number of requests在特定数量的请求后在 Varnish-Cache 中缓存资源
【发布时间】:2020-03-28 13:04:25
【问题描述】:

Varnish-Cache 中是否有类似 Nginx 的proxy_cache_min_uses 之类的功能,可以在对该资源进行特定数量的请求后缓存该资源? 这是Varnish-Cache plus 中的一些类似解决方案(基于slimhazardthis 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


【解决方案1】:

本身不在 Varnish Cache 核心中,但您可以使用 VMOD 实现此目的,例如 this counter VMOD

它将允许您在请求资源的次数内增加一些计数器,然后检查其值并应用所需的缓存逻辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 2016-01-17
    • 2019-11-27
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多