varnish 清理缓存 purge和ban

【软件版本】html

varnish 4.x后端


参考:https://www.varnish-cache.org/docs/4.1/users-guide/purging.html缓存

【分析purge 和 ban的区别】curl


共同点:ide

清除缓存fetch


不一样点:ui

purge 是一个动做 执行对访问的url在缓存中进行purge 清除。 一次只能对一个urlurl

ban 是一个策略,必须先增长ban禁止策略,下次访问匹配到这个禁止策略的时候,不会去缓存中找,直接去fetch后面的。ban能清理匹配到的任何内容。spa



purge比较好理解,ban看官网的一段解释翻译

官方原文:

There is another way to invalidate content: Bans. You can think of bans as a sort of a filter on objects already in the cache. You bancertain content from being served from your cache. You can ban content based on any metadata we have. A ban will only work on objects already in the cache, it does not prevent new content from entering the cache or being served.

Support for bans is built into Varnish and available in the CLI interface. To ban every png object belonging on example.com, issue the following command:

ban req.http.host == "example.com" && req.url ~ "\\.png$"




翻译:

这个是(清除)无效内容的另外一个方法: Bans. 你能将bans做为一个排序过的过滤缓存中的对象。你禁止某些内容来自你的缓存中。你能禁止的内容是咱们缓存中的任何元数据。ban 仅仅工做在已经缓存的对象上,它不能阻止一个新的内容条目将被缓存。(我理解的意思是 ban只能使用一次,即一次性清理)



【用法】

purge的用法:

1 vcl配置文件中添加purge容许

2 curl -I - X PURGE http://10.59.74.33/123.jpg


ban的用法:

添加一个ban到禁止list中。

1 varnishadm -S /etc/varnish/secret -T 127.0.0.1:8080 'ban req.url ~ "0*.jpg$"'


当访问任何0*.jpg的uri的时候,将不会从缓存中取,直接去后端取(其实就是禁止使用缓存,换句话就是达到了 清除缓存的目的,这个就是squid没有设计到的,由于squid的清理只有purge 只能是执行动做去清理(一个很大的目录须要不少cpu),而不是想办法去匹配到禁止的url而后不去进入缓存中去取,达到相同的目的。)

相关文章
相关标签/搜索