對squid中refresh_pattern的一些理解和建議
更新時間:2009年04月17日 21:31:13 作者:
用于確定一個頁面進入cache后,它在cache中停留的時間。refresh_pattern規(guī)則僅僅應用到?jīng)]有明確過時期限的響應。原始服務器能使用Expires頭部,或者Cache-Control:max-age指令來指定過時期限。
refresh_pattern的作用:
用于確定一個頁面進入cache后,它在cache中停留的時間。refresh_pattern規(guī)則僅僅應用到?jīng)]有明確過時期限的響應。原始服務器能使用Expires頭部,或者Cache-Control:max-age指令來指定過時期限。
語法:refresh_pattern [-i] regexp min percent max [options]
min參數(shù)是分鐘數(shù)量。它是過時響應的最低時間限制。如果某個響應駐留在cache里的時間沒有超過這個最低限制,那么它不會過期。類似的,max參數(shù)是存活響應的最高時間限制。如果某個響應駐留在cache里的時間高于這個最高限制,那么它必須被刷新。
在最低和最高時間限制之間的響應,會面對squid的最后修改系數(shù)LM-factor算法LM-factor=(response age)/(resource age)。對這樣的響應,squid計算響應的年齡和最后修改系數(shù),然后將它作為百分比值進行比較。響應年齡簡單的就是從原始服務器產(chǎn)生,或最后一次驗證響應后,經(jīng)歷的時間數(shù)量。源年齡在Last-Modified和Date頭部之間是不同的。LM-factor是響應年齡與源年齡的比率。
常用的幾個參數(shù)的意思
override-expire
該選項導致squid在檢查Expires頭部之前,先檢查min值。這樣,一個非零的min時間讓squid返回一個未確認的cache命中,即使該響應準備過期。
override-lastmod
改選項導致squid在檢查LM-factor百分比之前先檢查min值。
reload-into-ims
該選項讓squid在確認請求里,以no-cache指令傳送一個請求。換句話說,squid在轉(zhuǎn)發(fā)請求之前,對該請求增加一個If-Modified- Since頭部。注意這點僅僅在目標有Last-Modified時間戳時才能工作。外面進來的請求保留no-cache指令,以便它到達原始服務器。
一般情況可以使用 reload-into-ims。它其實是強行控制對象的超時時間,這違反了http協(xié)議的精神,但是在帶寬較窄的場合,可以提高明顯系統(tǒng)相應時間。
舉例:
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指令。
所以。如果希望內(nèi)容一進入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%
假設源服務器上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收到該請求后,由于已經(jīng)過期, squid會向源服務器發(fā)一個index.htm是否有改變的請求,源服務器收到后,如果index.htm沒有更新,squid就不用更新緩存,直接把緩存的內(nèi)容放回給客戶端,同時,重置對象進入cache的時間為與源服務器確認的時間,比如2007-04-10 03:13:00,如果正好在這個后重新確認了頁面。重置后,resource age變長,相應在cache中存活的時間也變長。
如果有改變則把最新的index.htm返回給squid,squid收到會更新緩存,然后把新的index.htm返回給客戶端,同時根據(jù)新頁面中的Last_Modified和取頁面的時間,重新計算resource age,進一步計算出存活時間。
實際上,一個頁面進入cache后,他的存活時間就確定了,即 (resource age) * 百分比,一直到被重新確認。
用于確定一個頁面進入cache后,它在cache中停留的時間。refresh_pattern規(guī)則僅僅應用到?jīng)]有明確過時期限的響應。原始服務器能使用Expires頭部,或者Cache-Control:max-age指令來指定過時期限。
語法:refresh_pattern [-i] regexp min percent max [options]
min參數(shù)是分鐘數(shù)量。它是過時響應的最低時間限制。如果某個響應駐留在cache里的時間沒有超過這個最低限制,那么它不會過期。類似的,max參數(shù)是存活響應的最高時間限制。如果某個響應駐留在cache里的時間高于這個最高限制,那么它必須被刷新。
在最低和最高時間限制之間的響應,會面對squid的最后修改系數(shù)LM-factor算法LM-factor=(response age)/(resource age)。對這樣的響應,squid計算響應的年齡和最后修改系數(shù),然后將它作為百分比值進行比較。響應年齡簡單的就是從原始服務器產(chǎn)生,或最后一次驗證響應后,經(jīng)歷的時間數(shù)量。源年齡在Last-Modified和Date頭部之間是不同的。LM-factor是響應年齡與源年齡的比率。
常用的幾個參數(shù)的意思
override-expire
該選項導致squid在檢查Expires頭部之前,先檢查min值。這樣,一個非零的min時間讓squid返回一個未確認的cache命中,即使該響應準備過期。
override-lastmod
改選項導致squid在檢查LM-factor百分比之前先檢查min值。
reload-into-ims
該選項讓squid在確認請求里,以no-cache指令傳送一個請求。換句話說,squid在轉(zhuǎn)發(fā)請求之前,對該請求增加一個If-Modified- Since頭部。注意這點僅僅在目標有Last-Modified時間戳時才能工作。外面進來的請求保留no-cache指令,以便它到達原始服務器。
一般情況可以使用 reload-into-ims。它其實是強行控制對象的超時時間,這違反了http協(xié)議的精神,但是在帶寬較窄的場合,可以提高明顯系統(tǒng)相應時間。
舉例:
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指令。
所以。如果希望內(nèi)容一進入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%
假設源服務器上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收到該請求后,由于已經(jīng)過期, squid會向源服務器發(fā)一個index.htm是否有改變的請求,源服務器收到后,如果index.htm沒有更新,squid就不用更新緩存,直接把緩存的內(nèi)容放回給客戶端,同時,重置對象進入cache的時間為與源服務器確認的時間,比如2007-04-10 03:13:00,如果正好在這個后重新確認了頁面。重置后,resource age變長,相應在cache中存活的時間也變長。
如果有改變則把最新的index.htm返回給squid,squid收到會更新緩存,然后把新的index.htm返回給客戶端,同時根據(jù)新頁面中的Last_Modified和取頁面的時間,重新計算resource age,進一步計算出存活時間。
實際上,一個頁面進入cache后,他的存活時間就確定了,即 (resource age) * 百分比,一直到被重新確認。
您可能感興趣的文章:
- VBS教程:VBscript屬性-Pattern 屬性
- JAVA正則表達式 Pattern和Matcher
- JavaScript constructor和instanceof,JSOO中的一對歡喜冤家
- Javascript的構(gòu)造函數(shù)和constructor屬性
- JavaScript類和繼承 constructor屬性
- 理解Javascript_11_constructor實現(xiàn)原理
- 用于過濾空白字符的幾種常見的js正則表達式pattern
- php設計模式 Prototype (原型模式)代碼
- js constructor的實際作用分析
- 深入分析js中的constructor和prototype
- AspNetPager分頁控件UrlRewritePattern參數(shù)設置的重寫代碼
- JavaScript中幾個重要的屬性(this、constructor、prototype)介紹
- JavaScript設計模式之原型模式(Object.create與prototype)介紹
- js使用Array.prototype.sort()對數(shù)組對象排序的方法
- php示例詳解Constructor Prototype Pattern 原型模式
相關文章
php通過exif_read_data函數(shù)獲取圖片的exif信息
這篇文章主要介紹了php通過exif_read_data函數(shù)獲取圖片的exif信息,默認情況下,PHP讀取圖片Exif信息模塊是不開啟的,我們需要先開啟這個模塊。開啟Exif模塊需要mbstring支持,這里就不詳細說明了,我們來先看下函數(shù)的用法2015-05-05同臺服務器使用緩存APC效率高于Memcached的演示代碼
之前看到有文章說同臺服務器上APC的效率是Memcached的7倍,APC效率比Memcached高是肯定的,至于倒底快多少,我寫了個小程序測試了下。2010-02-02PHP has encountered a Stack overflow問題解決方法
這篇文章主要介紹了PHP has encountered a Stack overflow問題解決方法,需要的朋友可以參考下2014-11-11php class中public,private,protected的區(qū)別以及實例分析
本篇文章是對php class中public,private,protected的區(qū)別以及實例進行了詳細的分析介紹,需要的朋友參考下2013-06-06