免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 9560 | 回复: 9
打印 上一主题 下一主题

[proxy] 如何理解Squid refresh_pattern [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-11 14:33 |只看该作者 |倒序浏览
看了下面这篇对Squid refresh_pattern理解,觉得不对,后面是自己研究的结果。
http://leftleg.hzpub.com/post/362.htm


=================================================
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%

假设源服务器上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

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2007-04-13 22:11 |只看该作者
不错, 比较详细清楚的。

论坛徽章:
0
3 [报告]
发表于 2008-02-29 11:39 |只看该作者
看的我还是很不清楚啊,

如果我需要缓存一天 (1440分钟),那如何计算min percent max  呢?

论坛徽章:
0
4 [报告]
发表于 2008-03-03 14:30 |只看该作者
原帖由 everest 于 2008-2-29 11:39 发表
看的我还是很不清楚啊,

如果我需要缓存一天 (1440分钟),那如何计算min percent max  呢?


1440 100% 1440 可以这样写了试试

论坛徽章:
0
5 [报告]
发表于 2008-05-29 16:34 |只看该作者
“squid上       proxy.aaa.com/index.htm  index.htm进入cache的时间  2007-04-10 03:00:00”

我想请问一下,怎么能看到上面这个时间

我意思是怎么能查到一个页面进入cache的时间,用什么命令?

论坛徽章:
0
6 [报告]
发表于 2008-06-02 18:00 |只看该作者
请问我要缓存30秒要如何设置呢?

论坛徽章:
0
7 [报告]
发表于 2008-06-05 15:20 |只看该作者
相关的选项为啥不也解释一下?
override-expire           enforces min age even if the server sent a Expires: header. Doing this VIOLATES the HTTP standard.  Enabling this
feature could make you liable for problems which it causes.
override-lastmod          enforces min age even on objects that was modified recently.
reload-into-ims          changes client no-cache or ``reload'' to If-Modified-Since requests. Doing this VIOLATES the HTTP standard. Enabling
this feature could make you liable for problems which it causes.
ignore-reload          ignores a client no-cache or ``reload'' header. Doing this VIOLATES the HTTP standard. Enabling this feature could
make you liable for problems which it causes.

论坛徽章:
0
8 [报告]
发表于 2008-06-13 17:42 |只看该作者
一个橘子罐头 是 8月1号凌晨零点生产出来的 盖子上表明 “保质期” 15天

到8月15号凌晨零点就过期啦 不能吃啦

那么这三个值应该是15 100% 15

论坛徽章:
0
9 [报告]
发表于 2009-06-02 11:15 |只看该作者

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


fresh表示马上对页面进行刷新,stale表示不刷新,是这个意思吗?

论坛徽章:
0
10 [报告]
发表于 2010-12-14 09:06 |只看该作者
fresh表示马上对页面进行刷新,stale表示不刷新,是这个意思吗?
sailer_sh 发表于 2009-06-02 11:15



   



fresh 表示还是缓存里面数据还是新的...不刷新
stale 表示过期....所以要重新发请求去源服务器
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP