Varnish4 强制所有缓存过期

如果你正在使用Varnish 4, 使用Ban命令/参数可以使缓存强制过期

varnishadm命令行中使用ban命令

ban req.url ~ /foo
ban req.http.host ~ example.com && obj.http.content-type ~ text
ban.list

 

VCL文件中使用BAN参数

ban("req.url ~ /foo");

 

在VCL文件中增加BAN方法

sub vcl_recv {
    if (req.method == "BAN") {
        ban("req.http.host == " + req.http.host +
            " && req.url == " + req.url);
        # Throw a synthetic page so the request won't go to the backend.
        return(synth(200, "Ban added"));
    }
}

 

请注意:

Ban只能清除已经在缓存中的对象,例如ban并不能阻止新的对象加入缓存或者正在被处理. 已缓存的对象满足ban将被标记为过时的(obsolete). 过时的对象会被自动回收和其他 obj.ttl==0 的对象一样.

 

更多内容请参考官方文档: http://book.varnish-software.com/4.0/chapters/Cache_Invalidation.html#banning

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据