<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post/179/</link>
<title><![CDATA[Varnish缓存更新策略调试过程[原创]]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[Varnish]]></category>
<pubDate>Wed, 13 Jan 2010 09:48:54 +0000</pubDate> 
<guid>https://blog.liuts.com/post/179/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;由于应用要求对更新过的页面需要进行实时更新，如新记录的数据发表、修改、隐藏等操作，目前有两种方法可以实现，第一种为在应用平台结合Varnish的Purege进行处理;第二种为利用http request的header做相应的处理，比如页面的redirect/header、按F5或Ctrl+F5键都会向服务器发送不同的Cache-Control，再将非更新页配置obj.ttl=86400s(1天)，这样可以大大提高缓存的命中率。以下为采用第二种方法针对不同浏览器的测试结果。<br/><br/><strong>1） 默认配置下的浏览器响应</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=59" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=59" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>&nbsp;&nbsp;&nbsp;&nbsp;结论：在默认配置下浏览不管发送任何类型的Cache-Control，Varnish都不会对Purege进行处理。<br/><br/><strong>2） 配置Cache-Control的no-cache时的浏览器响应</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=60" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=60" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>&nbsp;&nbsp;&nbsp;&nbsp;结论：说明Firefox浏览器只有按Ctrl+F5时才会发送no-cache的Cache-Control，IE浏览器认为服务器端的redirect的重定向就是一个no-cache，同样按Ctrl+F5也如此。比较奇怪的就是Chrome浏览器即使按Ctrl+F5后同样没有向服务器端发送no-cache，后来查了资料，得知google为了更好的利用本地cache，将Ctrl+F5的功能屏蔽。<br/><br/><strong>3） 配置Cache-Control的max-age=0时的浏览器响应</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=61" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=61" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>&nbsp;&nbsp;&nbsp;&nbsp;结论：通过上表数据可以得出，Firefox在redirect的情况下，它会发送一public或Private的Cache-Control给服务器端，同时IE及Chrome都会以一个max-age=0的Cache-Control的标志给服务器，此时的Chrome浏览器Ctrl+F5没有发送no-cache，而是max-age=0。<br/><br/><strong>Varnish配置文件处理块</strong><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>if (req.http.Cache-Control ~ "(no-cache&#124;max-age=0)")&#123;<br/>&nbsp;&nbsp;purge_url(req.url); <br/>&#125;<br/></div></div><br/><strong>与原配置(squid)命中率对比</strong><br/><a href="https://blog.liuts.com/attachment.php?fid=58" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=58" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>squid命中率<br/><a href="https://blog.liuts.com/attachment.php?fid=57" target="_blank"><img src="https://blog.liuts.com/attachment.php?fid=57" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/>Varnish命中率<br/><br/>如大家有什么疑问或感兴趣的话题可以通过weibo与我交流：<a href="http://t.qq.com/yorkoliu" target="_blank">http://t.qq.com/yorkoliu</a><br/>Tags - <a href="https://blog.liuts.com/tags/varnish/" rel="tag">varnish</a> , <a href="https://blog.liuts.com/tags/%25E5%258F%258D%25E5%2590%2591%25E4%25BB%25A3%25E7%2590%2586/" rel="tag">反向代理</a> , <a href="https://blog.liuts.com/tags/%25E7%25BC%2593%25E5%25AD%2598/" rel="tag">缓存</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post/179/#blogcomment18</link>
<title><![CDATA[[评论] Varnish缓存更新策略调试过程[原创]]]></title> 
<author>passthis &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 24 Jan 2010 11:07:03 +0000</pubDate> 
<guid>https://blog.liuts.com/post/179/#blogcomment18</guid> 
<description>
<![CDATA[ 
	好文，学习了！
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post/179/#blogcomment36</link>
<title><![CDATA[[评论] Varnish缓存更新策略调试过程[原创]]]></title> 
<author>#include忍者 &lt;sa@linuxnotes.cn&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 12 Mar 2010 03:20:27 +0000</pubDate> 
<guid>https://blog.liuts.com/post/179/#blogcomment36</guid> 
<description>
<![CDATA[ 
	讲的不错，不过我有一个疑问，<br/>if (req.http.Cache-Control ~ &quot;(no-cache&#124;max-age=0)&quot;){<br/>&nbsp;&nbsp;purge_url(req.url); <br/>}<br/>这个代码加上，那岂不是让用户来控制缓存了？这种办法可行吗
]]>
</description>
</item>
</channel>
</rss>