Servlet/JSP如何控制页面缓存于squid中
response.setDateHeader("Expires", 0);??
response.addHeader( "Cache-Control", "no-cache" );??
response.addHeader( "Cache-Control", "no-store" );??
response.addHeader( "Cache-Control", "must-revalidate" );
如果HTML页面信息中包括了Expires头信息,则其相关的缓存机制不再处理该页面,而是安装页面的缓存控制要求来处理。所以做了上述工作后,Squid无需做任何配置上的修改(指Squid的refresh_pattern指令不处理这些页面 )。
?????? 下面说一下Squid缓存一些静态资源的一些原理,Squid通过refresh_pattern指令来控制用户请求是否命中。???? "Squid中文权威指南"文章中描述Squid的refresh_pattern指令一段文章读起来非常的拗口,就是LM_factor比率的算法,这个算法的概念翻译的比较模糊,网络上传来传去的,感觉都是搞不清楚,后来参考"OReilly - Squid The Definitive Guide.chm"英文原文,总算明白过来 。
英文原文应用代码
Responses that fall between the minimum and maximum are subject to Squid's???
last-modified factor (LM-factor) algorithm. For such responses, Squid calculates??
the response age and the LM-factor and compares it to the percent value. The???
response age is simply the amount of time passed since the origin server???
generated, or last validated, the response. The resource age is the difference???
between the Last-Modified and Date headers. The LM-factor is the ratio of the??
response age to the resource age.??
LM-factor的定义是(response age)/(the resource age).??
其中response age是指HTTP头信息中的age信息。??
resource age是指HTTP头信息中的Date值减去Last-Modified的值转化为秒的值。??
各位可以通过curl命令(Linux下自带命令)来参看一个资源返回回来的HTTP头详细信息,如下面这样:??
curl -I http://10.0.85.125:8384/mailproxy/welcome.htm
经过试验,这个算法是正确的,同时这里要提醒一下,特别是对一些HTML类型的资源,max值不要设置的太大,如果设置的太大的话,有可能修改的文档信息需要非常长的时间才能得到更新,因为LM-factor参数值是变化的,越来越大,分母变大的结果就是比率越来越小,总是小于我们设定的比率,导致需要max来控制页面刷新。