使用单个 http 请求在 varnish 4 中 prime/refresh a url 的最佳方法是什么?

What's the best way to prime/refresh a url in varnish 4 using a single http request?

force cache miss 注释指出:

Forcing cache misses do not evict old content. This means that causes Varnish to have multiple copies of the content in cache. In such cases, the newest copy is always used. Keep in mind that duplicated objects will stay as long as their time-to-live is positive.

我不想在缓存中保留多个副本。我启动 url 的方法是否有效?我通过将旧内容添加到禁令潜伏者来手动驱逐​​旧内容。然后自己强制一个缓存miss来替换被禁的内容。

acl purge_prime {
    "127.0.0.1";
    "::1";
}

sub vcl_recv {
    if (req.method == "PRIME") {
        if (!client.ip ~ purge_prime) {
            return(synth(405,"No priming for you. (" + client.ip + ")"));
        }
        # Add to the ban lurker. Purging existing pages.
        ban("obj.http.x-host == " + req.http.host + " && obj.http.x-url == " + req.url);
        # Call the backend to fetch new content and add it to the cache.
        set req.method = "GET";
        set req.hash_always_miss = true;
    }
    # ... other custom rules.
}

# ... other subroutines below, e.g. adding ban-lurker support etc.

这个逻辑对我来说很有意义,我只是担心,因为没有人做过(我假设这是有原因的)。

与使用 purge with restart 相比,这是错误的方法吗?如果是,使用单个 http 请求启动 url 的最佳方法是什么?

我想你的方法根本不好,因为它使用了禁令。 使用清除而不是禁止将允许您利用宽限模式。

重启完全没问题 - 它们不会导致两个或更多 HTTP 请求,而是再次通过 VCL 状态机推送请求。