SQUID的refresh_pattern配置方法
2014-11-15 17:27:50   来源:   评论:0 点击:

Squid中refresh_pattern配置语句的作用:用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern 只对后端没设置Expires过...
Squid中refresh_pattern配置语句的作用:
用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern 只对后端没设置Expires过期时间的页面起作用,比如论坛页面, 对类似apache mod_expires 设置过的页面不起作用。普通的静态页面与图片等文件Last_Modified也是可以计算Expires的一种。


语法:
refresh_pattern [-i] regexp min percent max [options]


min, max的单位是分钟,percent就是百分比,也就是LM-factor。

refresh_pattern 的算法如下:(当前时间定义为CURRENT_DATE)
1) If ((CURRENT_DATE-DATE(就是LM里定义的时间)) < min),cache是新鲜的
2) else if ((CURRENT_DATE-DATE) < (min + (max-min)*percent),cache是新鲜的
3) else cache是过期的
cache过期就需要从后面server取新鲜内容。

几个概念:
resource age =对象进入cache的时间-对象的last_modified
response age  =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)
Date一般是Squid从后面取页面的时间,Last-Modified 一般是页面生成时间。

举个例子,这里只考虑percent, 不考虑min  和 max

例如:refresh_pattern   20%

假设源服务器上

www.aaa.com/index.htm  -----lastmodified 是          2007-04-10 02:00:00
squid上       proxy.aaa.com/index.htm  index.htm进入cache的时间  2007-04-10 03:00:00

1)如果当前时间   2007-04-10 03:00:00
resource age =3点-2点=60分钟
response age =0分钟
index.htm还可以在cache停留的时间(resource age)*20%=12分钟
也就是说,index.htm进入cache后,可以停留12分钟,才被重新确认。


2)如果当前时间  2007-04-10 03:05:00
resource age =3点-2点=60分钟
response age =5分钟
index.htm还可以在cache停留的时间(resource age)*20%=12分钟-5=7
LM-factor=5/60=8.3%<20%

    一直到2007-04-10 03:12:00   LM-factor=12/60=20% 之后,cache中的页面index.htm终于stale。
    如果这时没有index.htm的请求,index.htm会一直在缓存中,如果有index.htm请求,squid收到该请求后,由于已经过期, squid会向源服务器发一个index.htm是否有改变的请求,源服务器收到后,如果index.htm没有更新,squid就不用更新缓存,直接把 缓存的内容放回给客户端,同时,重置对象进入cache的时间为与源服务器确认的时间,比如2007-04-10 03:13:00,如果正好在这个后重新确认了页面。重置后,resource age变长,相应在cache中存活的时间也变长。

   如果有改变则把最新的index.htm返回给squid,squid收到会更新缓存,然后把新的index.htm返回给客户端,同时根据新页面中的Last_Modified和取页面的时间,重新计算resource age,进一步计算出存活时间。

   实际上,一个页面进入cache后,他的存活时间就确定了,即 (resource age) * 百分比,一直到被重新确认。

   理解了百分比后,min max就好理解了

squid收到一个页面请求时:
1、计算出response age,
2、如果response age<min 则 fresh  如果response age>max 则 stale
3、如果response age在之间,如果response时间<存活时间,fresh,否则stale

如果希望页面一进入cache就不删除,直到被主动purge掉为止,可以加上ignore-reload选项
一般情况可以使用 reload-into-ims。

举例:

refresh_pattern -i \.gif$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.png$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.mp3$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.wmv$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.rm$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.swf$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.mpeg$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.wma$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.css$ 10 50% 60 reload-into-ims
refresh_pattern -i \.js$ 10 50% 60 reload-into-ims
refresh_pattern -i \.xml$ 10 50% 30 reload-into-ims

相关热词搜索:squid refresh_pattern 配置

上一篇:揭秘阿里CDN核心技术
下一篇:最后一页

分享到: 收藏