caching - 如何清除 Varnish 中的完整缓存?

标签 caching varnish varnish-vcl varnish-4 clear-cache

我正在寻找一种方法来清除 Varnish 中所有域和所有 URL 的缓存。

目前,我需要为每个 URL 发出单独的命令,例如:

curl -X PURGE http://example.com/url1
curl -X PURGE http://example.com/url1
curl -X PURGE http://subdomain.example.com/
curl -X PURGE http://subdomain.example.com/url1
// etc.

虽然我正在寻找一种方法来做类似的事情
curl -X PURGE http://example.com/*

这将清除 example.com 下的所有 URL,但也会清除 example.com 子域中的所有 URL,基本上所有由 Varnish 管理的 URL。

知道如何实现这一目标吗?

这是我当前的 VCL 文件:
vcl 4.0;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv {
    # Command to clear the cache
    # curl -X PURGE http://example.com
    if (req.method == "PURGE") {
        return (purge);
    }
}

最佳答案

在 Varnish 4.0 中,我最终使用 ban 实现了它。命令:

sub vcl_recv {
    # ...

    # Command to clear complete cache for all URLs and all sub-domains
    # curl -X XCGFULLBAN http://example.com
    if (req.method == "XCGFULLBAN") {
        ban("req.http.host ~ .*");
        return (synth(200, "Full cache cleared"));
    }

    # ...
}

关于caching - 如何清除 Varnish 中的完整缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38892021/

相关文章:

ios - 缓存下载的数据

caching - 如何从Varnish缓存中删除文件

Varnish - 为什么有两个过程

caching - Varnish 中的禁止是如何工作的?

caching - Varnish 4,清理 - 我以为我已经弄清楚了一切

caching - Varnish 4以从具有不同内容的多台服务器缓存

javascript - 发布 ASP.NET 网站

php - PHP cURL DNS 缓存如何工作?

php - 带有 PHP 文件的 JQuery AJAX 缓存

php - Nginx - 如果 URL 有查询然后运行命令?