Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2224705
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-03-24 11:10:01






refresh_pattern 的一些理解和建议.
Jan 22nd, 2008
 | 

转载本站文章请注明,转载自:扶凯[]

本文链接: 

Squid 中 refresh_pattern 的作用

 

用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern 规则仅仅应用到没有明确过时期限的响应。原始服务器能使 用 Expires 头部,或者 Cache-Control:max-age 指令来指定过时期限 ,只要没有在设置 override-expire。

语法:

refresh_pattern [-i] regexp min percent max [options]

 min 参数是分钟数量。它是过时响应的最低时间限制。如果某个响应驻留在 cache 里的时间没有超过这个最低限制,那么它不会过期。类似的,max 参数是存活响应的最高时间限制。如果某个响应驻留在 cache 里的时间高于这个最高限制,那么它必须被刷新。

在最低和最高时间限制之间的响应,会面对 squid 的最后修改系数 LM-factor 算法 LM-factor=(response age)/(resource age)。对这样的响应,squid 计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较。响应年龄简单的就是从原始服务器产生,或最后一次验证响应后,经历的时间数量。源年龄在 Last-Modified 和 Date头 部之间是不同的。LM-factor 是响应年龄与源年龄的比率。这个基本不用详细了解,这是不是一个精确控制过期的参数,如果要精确控制过期,就不要使用这个。

 

Refresh_pattern 有14个参数

 

我讲讲常用的几个参数的意思

override-expire
该选项导致 squid 在检查 Expires 之前,先检查 min 值。这样,一个非零的 min 时间让 squid 返回一个未确认的 cache 命中,即使该响应准备过期。

override-lastmod
改选项导致 squid 在检查 LM-factor 百分比之前先检查min ,它生效在expire 之后

reload-into-ims
该选项让 squid 在确认请求里,以 no-cache 指令传送一个请求。换句话说,squid 在转发请求之前,对该请求增加一个 If-Modified- Since 头部。注意这点仅仅在目标有 Last-Modified 时间戳时才能工作。外面进来的请求保留 no-cache 指令,以便它到达原始服务器。
一般情况可以使用 reload-into-ims。它其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。
举例:

refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims-
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims

 ignore-reload
该选项导致 squid 忽略请求里的任何 no-cache 指令。
所以。如果希望内容一进入 cache 就不删除,直到被主动 purge 掉为止,可以加上 ignore-reload 选项,这个我们常用在mp3,wma,wmv,gif之类。
Examples:

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

ignore-no-cache
该选项导致 Squid 强制忽略从源站而来的“Pragma: no-cache”和“Cache-control: no-cache”

ignore-private
该选项导致 Squid 强制忽略从源站而来的“Cache-control: private”

ignore-auth:强制将一个请求认为是源站发送的带有“Cache-control: public”

ignore-auth
该选项导致 Squid 强制将一个请求认为是源站发送的带有“Cache-control: public”

 

Refresh_pattern  percent 的计算

resource age =对象进入cache的时间-对象的last_modified
response age =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)

 

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

例如:refresh_pattern 20%

假设源服务器上 —–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) * 百分比,一直到被重新确认。










转载本站文章请注明,转载自:扶凯[]

本文链接:

Squid 中 refresh_pattern 的作用

 

用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern 规则仅仅应用到没有明确过时期限的响应。原始服务器能使 用 Expires 头部,或者 Cache-Control:max-age 指令来指定过时期限 ,只要没有在设置 override-expire。

语法:

refresh_pattern [-i] regexp min percent max [options]

 min 参数是分钟数量。它是过时响应的最低时间限制。如果某个响应驻留在 cache 里的时间没有超过这个最低限制,那么它不会过期。类似的,max 参数是存活响应的最高时间限制。如果某个响应驻留在 cache 里的时间高于这个最高限制,那么它必须被刷新。

在最低和最高时间限制之间的响应,会面对 squid 的最后修改系数 LM-factor 算法 LM-factor=(response age)/(resource age)。对这样的响应,squid 计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较。响应年龄简单的就是从原始服务器产生,或最后一次验证响应后,经历的时间数量。源年龄在 Last-Modified 和 Date头 部之间是不同的。LM-factor 是响应年龄与源年龄的比率。这个基本不用详细了解,这是不是一个精确控制过期的参数,如果要精确控制过期,就不要使用这个。

 

Refresh_pattern 有14个参数

 

我讲讲常用的几个参数的意思

override-expire
该选项导致 squid 在检查 Expires 之前,先检查 min 值。这样,一个非零的 min 时间让 squid 返回一个未确认的 cache 命中,即使该响应准备过期。

override-lastmod
改选项导致 squid 在检查 LM-factor 百分比之前先检查min ,它生效在expire 之后

reload-into-ims
该选项让 squid 在确认请求里,以 no-cache 指令传送一个请求。换句话说,squid 在转发请求之前,对该请求增加一个 If-Modified- Since 头部。注意这点仅仅在目标有 Last-Modified 时间戳时才能工作。外面进来的请求保留 no-cache 指令,以便它到达原始服务器。
一般情况可以使用 reload-into-ims。它其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。
举例:

refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims-
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims

 ignore-reload
该选项导致 squid 忽略请求里的任何 no-cache 指令。
所以。如果希望内容一进入 cache 就不删除,直到被主动 purge 掉为止,可以加上 ignore-reload 选项,这个我们常用在mp3,wma,wmv,gif之类。
Examples:

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

ignore-no-cache
该选项导致 Squid 强制忽略从源站而来的“Pragma: no-cache”和“Cache-control: no-cache”

ignore-private
该选项导致 Squid 强制忽略从源站而来的“Cache-control: private”

ignore-auth:强制将一个请求认为是源站发送的带有“Cache-control: public”

ignore-auth
该选项导致 Squid 强制将一个请求认为是源站发送的带有“Cache-control: public”

 

Refresh_pattern  percent 的计算

resource age =对象进入cache的时间-对象的last_modified
response age =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)

 

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

例如:refresh_pattern 20%

假设源服务器上 —–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) * 百分比,一直到被重新确认

























文件:squid-2.6.STABLE181.tar.bz2
一.安装
#tar -zxvf squid-2.6.STABLE181.tar.bz2
#cd squid-2.6
#configure --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"
#make
#make install
二,配置
squid的配置文件:
1./usr/local/squid/etc/squid.conf  
visible_hostname localhost
http_port 10.122.89.104:80 vhost vport
http_port 10.122.89.222:80 vhost vport
icp_port 0
cache_mem 900 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 20000 KB
maximum_object_size_in_memory 4096 KB
cache_dir ufs /home/tmp 1000 16 256
access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
emulate_httpd_log on
pid_filename /usr/local/squid/var/logs/squid.pid
acl Safe_ports port 80
http_access deny !Safe_ports
tcp_recv_bufsize 65535 bytes
negative_ttl 1 second
cache_store_log none
cache_vary on
emulate_httpd_log on
logfile_rotate 0
acl all src 0.0.0.0/0.0.0.0   
acl QUERY urlpath_regex cgi-bin .html .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe .rar
cache deny QUERY

acl Safe_ports port 80
acl Safe_ports port 21
http_access deny !Safe_ports
tcp_recv_bufsize 65535 bytes
refresh_pattern -i .shtml 1440 100% 129600 reload-into-ims
refresh_pattern -i .gif 1440 100% 129600 reload-into-ims
refresh_pattern -i .swf 1440 100% 129600 reload-into-ims
refresh_pattern -i .png 1440 100% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 100% 129600 reload-into-ims
refresh_pattern -i .css 1440 100% 129600 reload-into-ims
refresh_pattern -i .jpg 1440 100% 129600 reload-into-ims
refresh_pattern -i .txt 1440 100% 129600 reload-into-ims
refresh_pattern -i .rhtml 1440 100% 129600 reload-into-ims
refresh_pattern -i .xml 1440 100% 129600 reload-into-ims
cache_peer 127.0.0.1 parent 8080 0 no-query originserver
cache_effective_user nobody
cache_effective_group nobody
三,完成
#mkdir -p /home/tmp
#chmod 777 /home/tmp
#mkdir  /usr/local/squid/var/logs/access.log
#chmod 777 /usr/local/squid/var/logs/access.log
usr/local/squid/sbin/squid -z   创建缓存
/usr/local/squid/sbin/squid       启动squid
/usr/local/squid/sbin/squid -k shutdown 重启squid
四.测试
查看你的日志文档。
#more /usr/local/squid/var/logs/access.log | grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户。
#more /usr/local/squid/var/logs/access.log | grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户。
#more /usr/local/squid/var/logs/access.log | grep TCP_MISS
该指令可以看到在squid运行过程中,有那些文件没有被squid缓存,而是现重原始服务器获取并返回给访问用户。
五.在squid2.6中refresh_pattern的一些理解和建议.]
refresh_pattern的作用:
用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern规则仅仅应用到没有明确过时期限的响应。原始服务器能使用Expires头部,或者Cache-Control:max-age指令来指定过时期限。
语法:
refresh_pattern [-i] regexp min percent max [options]
min参数是分钟数量。它是过时响应的最低时间限制。如果某个响应驻留在cache里的时间没有超过这个最低限制,那么它不会过期。类似的,max参数是存活响应的最高时间限制。如果某个响应驻留在cache里的时间高于这个最高限制,那么它必须被刷新。
在最低和最高时间限制之间的响应,会面对squid的最后修改系数LM-factor算法LM-factor=(response age)/(resource age)。对这样的响应,squid计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较。响应年龄简单的就是从原始服务器产生,或最后一次验证 响应后,经历的时间数量。源年龄在Last-Modified和Date头部之间是不同的。LM-factor是响应年龄与源年龄的比率。
常用的几个参数的意思
override-expire
该选项导致squid在检查Expires头部之前,先检查min值。这样,一个非零的min时间让squid返回一个未确认的cache命中,即使该响应准备过期。
override-lastmod
改选项导致squid在检查LM-factor百分比之前先检查min值。
reload-into-ims
该选项让squid在确认请求里,以no-cache指令传送一个请求。换句话说,squid在转发请求之前,对该请求增加一个If-Modified- Since头部。注意这点仅仅在目标有Last-Modified时间戳时才能工作。外面进来的请求保留no-cache指令,以便它到达原始服务器。
一般情况可以使用 reload-into-ims。它其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。
举例:
refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims-
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims
ignore-reload
该选项导致squid忽略请求里的任何no-cache指令。
所以。如果希望内容一进入cache就不删除,直到被主动purge掉为止,可以加上ignore-reload选项,这个我们常用在mp3,wma,wmv,gif之类。
Examples:
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
resource age =对象进入cache的时间-对象的last_modified
response age =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)
举个例子,这里只考虑percent, 不考虑min 和max
例如:refresh_pattern 20%
假设源服务器上 -----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) * 百分比,一直到被重新确认。



















[squid] Refresh_pattern配置详解

apache 2011-02-28 09:15:01 阅读36 评论0  字号: 订阅

  Refresh_pattern 指令间接的控制磁盘缓存。宽松的设置增加了cache的命中率,同样也增加了用户接受过时相应的几率; 保守的设置,降低了cache的命中率和过时响应.Refresh_pattern 规则仅仅应用到没有明确过时期限响应。原始服务器能使用Expires 头部,或者使用Cache-Control:max-age指令来设置过时期限,当然在squid主配置文件中配置refresh_pattern 配置任意数量,squid是按照顺序进行查找以匹配正则表达式,。一旦squid找到一个匹配时,squid会使用相应的值来决定,某个缓存响应是存活还是过期,当正则表达式之一被匹配URI时,squid 就会停止搜索

Refresh_pattern 的语法:Refresh _pattern [-i] regexp min  percent  max  [Option]

1> regexp 参数是大小写敏感的正则表达式,-i选项是忽略大小写
2> min参数是分钟数量,它是过时响应的最低是时间限制。如果魔鬼响应驻留在cache里的时间没有超过这个最低限制,那么它不会过期。同样max 参数是存活响应的最高时间限制。如果某个响应驻留在cache里的时间高于这个最高限制,那么它必须被刷新
3> 在min和max时间限制之间的响应,会面对squid的最后修改系统LM-factor算法LM-factor=(responseb age)/(resource age). 对这样的响应,squid计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较,响应年龄简单地就是从原始服务器产生,或者是最后一次验证响应后,经历的时间数量。源年龄在Last-Modified 和Date头部之间是不同的,LM-factor 是响应年龄与源年龄的比率。这不是一个精确控制过期的参数,如果要精确控制过期,就不要使用该参数
4> squid的refresh_pattern 算法的简单描述
   a> 如果响应年龄超过refresh_pattern 的max值,该响应过期;
   b> 如果LM-factor 少于refresh_pattern 的percent的值。该响应存活
   c> 如果响应年龄少于refresh_pattern 的min值,该响应存活
   d> 其他情况,响应过期
5> Refresh_pattern  percent 计算方法
      Resource age=对象进入cache的时间–对象的last_modified
      Response age=当前时间–对象进入cache的时间
      LM-factor   =(response age)/(resource age)
      例: refresh_pattern 20%
      假如源服务器上
 - --lastmodified 是2007-04-10 02:00:00
      Squid 上的proxy.aaa.com/index.html  index.html存入cache的时间2007-04-10 03:00:00 
      1.如果当前时间 2007-04-10 03:00:00
      Resource age =3点 – 2点 =60分钟
      Response age =0 分钟
      Index.html 还可以在cache 中停留的时间(resource age)*20%= 12 分钟,换句话说,    index.html 进入cache后,可以停留十二分钟,才被重新载入
      2.如果当前时间是 2007-04-10 03:05:00
      Resource age =3点 – 2点 =60 分钟
      Response age=5 分钟
      Index.html 还可以在cache中停留的时间
     ( resource age)*20%=12 分钟-5=7分钟
      LM-factor=5/60 =8.3% <20%
      3.所有说2007-04-10 03:12:00 LM-factor=12/60=20% 之后,cache中的页面index.html 终于stale,如果这段时间没有index.html的请求,index.html会一直缓存中,如果有index.html 请求,squid收到请求后,由于已经过期,squid 会像源服务器发一个index.html是否有改变的请求,如果源服务器收到请求后,如果index.html没有更新,squid就不用缓存,直接会把缓存中的内容给客户端;同时,重置对象进入cache的时间为源服务器确认的时间。比如2007-04-10 03:13:00 ,如果正好在这个后重新确认了页面。重置后,resource age 变长,相应在cache中的cache中存活的时间也同样变长.如果有改变则把最新的index.html返还给squid ,而squid 收到会更新缓存,然后把新的index.html 返还给客户端,同时根据新页面中的Last_Modified 和取页面的时间,重新计算resource age,同样也重新计算存活时间.实际上,一个对象进入cache后,同样他的存活时间就确定了,即(resource age)*percent,直到被重新确认
6>refresh_pattern 指令
Override-expire   该项导致squid在检查Ecpires 头部之前,先检查min 值,这样。一个非零的min时间让squid返回一个未确认的cache命中,及时该响应准备过期
Override-lastmod  该选项导致squid在检查LM-factor 百分比之前先检查min值,其生效在expire 之后
Reload-into-ims   该项让squid在确认请求里,以no-cache指令传送一个请求,话句话说,squid在转发请求前,对该请求增加一个If-Modified-Since 头部,主要该点的是,仅仅在目标有Last-Modified 时间截时才能工作。外面进来的请求保留no-cache 指令,以便他到达原始服务器。一般情况下可以使用reload-into-ims。它是强行控制对象的超时时间,这违反了http协议的精神,但是也在带宽较窄的情况下。可以明显的提高系统的响应时间
Ignore-reload     该选项导致squid的忽略请求里的任何no-cache指令
 如果希望内容一旦进入cache就不删除,除非是被主动purge掉为止,可以加上ignore-reload 选项,该项常用在mp3,wma,wmv,gif 之类
Ignore-no-cache   该项导致squid强制忽略从源站而来的“Pragma:no-cache”和“cache-control:no-cache”
Ignore-private    该项导致squid强制忽略从源站而来的“cache-control:private”
Ignore-auth      该项导致squid 强制将一个请求认为是源站发送的带有“cache-control:public”
Ignore-no-store   该指令是忽略来自源站不缓存对象
Refresh-ims       
该项是client一个刷新请求转换成一个If-Modified-Since 请求

http://freehat.blog.51cto.com/1239536/448848



























如何理解Squid refresh_pattern

refresh_pattern的作用:
用于确定一个页面进入cache后,它在cache中停留的时间。

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

几个概念:
resource age =对象进入cache的时间-对象的last_modified
response age   =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)


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

例如:refresh_pattern 20% 

假设源服务器上
   -----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 agemax 则 stale
3、如果response age在之间,如果response时间<存活时间,fresh,否则stale

refresh_pattern指令间接的控制磁盘缓存。它帮助squid决 定,是否某个给定请求是cache命中,或作为cache丢失对待。宽松的设置增加了你的cache命中率,但也增加了用户接收过时响应的机会。另一方 面,保守的设置,降低了cache命中率和过时响应。

refresh_pattern规则仅仅应用到没有明确过时期限的响应。原始服务器能使用Expires头部,或者Cache-Control:max-age指令来指定过时期限。

你可以在配置文件里放置任意数量的refresh_pattern行。squid按顺序查找它们以匹配正则表达式。当squid找到一个匹配时,它使用相应的值来决定,某个缓存响应是存活还是过期。refresh_pattern语法如下:

refresh_pattern [-i] regexp min percent max [options]

例如:

refresh_pattern -i \.jpg$ 30 50% 4320 reload-into-ims

refresh_pattern -i \.png$ 30 50% 4320 reload-into-ims

refresh_pattern -i \.htm$ 0 20% 1440

refresh_pattern -i \.html$ 0 20% 1440

refresh_pattern -i . 5 25% 2880

regexp参数是大小写敏感的正则表达式。你可以使用-i选项来使它们大小写不敏感。squid按顺序来检查refresh_pattern行;当正则表达式之一匹配URI时,它停止搜索。

min参数是分钟数量。它是过时响应的最低时间限制。如果某个响应驻留在cache里的时间没有超过这个最低限制,那么它不会过期。类似的,max参数是存活响应的最高时间限制。如果某个响应驻留在cache里的时间高于这个最高限制,那么它必须被刷新。

在最低和最高时间限制之间的响应,会面对squid的最后修改系数 (LM-factor)算法。对这样的响应,squid计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较。响应年龄简单的就是从原始服务器产 生,或最后一次验证响应后,经历的时间数量。源年龄在Last-Modified和Date头部之间是不同的。LM-factor是响应年龄与源年龄的比 率。

图7-2论证了LM-factor算法。squid缓存了某个目标3个小时(基于Date和Last-Modified头部)。LM-factor 的值是50%,响应在接下来的1.5个小时里是存活的,在这之后,目标会过期并被当作过时处理。假如用户在存活期间请求cache目标,squid返回没 有确认的cache命中。若在过时期间发生请求,squid转发确认请求到原始服务器。

理解squid检查不同值的顺序非常重要。如下是squid的refresh_pattern算法的简单描述:

  • 假如响应年龄超过refresh_pattern的max值,该响应过期;
  • 假如LM-factor少于refresh_pattern百分比值,该响应存活;
  • 假如响应年龄少于refresh_pattern的min值,该响应存活;
  • 其他情况下,响应过期。

refresh_pattern指令也有少数选项导致squid违背HTTP协议规范。它们如下:

override-expire

该选项导致squid在检查Expires头部之前,先检查min值。这样,一个非零的min时间让squid返回一个未确认的cache命中,即使该响应准备过期。

override-lastmod

改选项导致squid在检查LM-factor百分比之前先检查min值。

reload-into-ims

该选项让squid在确认请求里,以no-cache指令传送一个请求。换句话说,squid在转发请求之前,对该请求增加一个If- Modified-Since头部。注意这点仅仅在目标有Last-Modified时间戳时才能工作。外面进来的请求保留no-cache指令,以便它 到达原始服务器。

ignore-reload

该选项导致squid忽略请求里的任何no-cache指令


阅读(1037) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~