對squid中refresh
2024-07-09 22:41:56
供稿:網(wǎng)友
refresh_pattern的作用:
用于確定一個頁面進(jìn)入cache后,它在cache中停留的時間。refresh_pattern規(guī)則僅僅應(yīng)用到?jīng)]有明確過時期限的響應(yīng)。原始服務(wù)器能使用Expires頭部,或者Cache-Control:max-age指令來指定過時期限。
語法:refresh_pattern [-i] regexp min percent max [options]
min參數(shù)是分鐘數(shù)量。它是過時響應(yīng)的最低時間限制。如果某個響應(yīng)駐留在cache里的時間沒有超過這個最低限制,那么它不會過期。類似的,max參數(shù)是存活響應(yīng)的最高時間限制。如果某個響應(yīng)駐留在cache里的時間高于這個最高限制,那么它必須被刷新。
在最低和最高時間限制之間的響應(yīng),會面對squid的最后修改系數(shù)LM-factor算法LM-factor=(response age)/(resource age)。對這樣的響應(yīng),squid計算響應(yīng)的年齡和最后修改系數(shù),然后將它作為百分比值進(jìn)行比較。響應(yīng)年齡簡單的就是從原始服務(wù)器產(chǎn)生,或最后一次驗證響應(yīng)后,經(jīng)歷的時間數(shù)量。源年齡在Last-Modified和Date頭部之間是不同的。LM-factor是響應(yīng)年齡與源年齡的比率。
常用的幾個參數(shù)的意思
override-expire
該選項導(dǎo)致squid在檢查Expires頭部之前,先檢查min值。這樣,一個非零的min時間讓squid返回一個未確認(rèn)的cache命中,即使該響應(yīng)準(zhǔn)備過期。
override-lastmod
改選項導(dǎo)致squid在檢查LM-factor百分比之前先檢查min值。
reload-into-ims
該選項讓squid在確認(rèn)請求里,以no-cache指令傳送一個請求。換句話說,squid在轉(zhuǎn)發(fā)請求之前,對該請求增加一個If-Modified- Since頭部。注意這點(diǎn)僅僅在目標(biāo)有Last-Modified時間戳?xí)r才能工作。外面進(jìn)來的請求保留no-cache指令,以便它到達(dá)原始服務(wù)器。
一般情況可以使用 reload-into-ims。它其實是強(qiáng)行控制對象的超時時間,這違反了http協(xié)議的精神,但是在帶寬較窄的場合,可以提高明顯系統(tǒng)相應(yī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
該選項導(dǎo)致squid忽略請求里的任何no-cache指令。
所以。如果希望內(nèi)容一進(jìn)入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 =對象進(jìn)入cache的時間-對象的last_modified
response age =當(dāng)前時間-對象進(jìn)入cache的時間
LM-factor=(response age)/(resource age)
舉個例子,這里只考慮percent, 不考慮min 和max
例如:refresh_pattern 20%
假設(shè)源服務(wù)器上www.aaa.com/index.htm -----lastmodified 是 2007-04-10 02:00:00