跳到主要內容

Squid refresh-pattern

套用沒有明確定義Expire or Cache-Control:max-age的Req

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

min參數是分鐘數量。它是過時響應的最低時間限制。如果某個響應駐留在cache裡的時間沒有超過這個最低限制,那麼它不會過期。
max參數是存活響應的最高時間限制。如果某個響應駐留在cache裡的時間高於這個最高限制,那麼它必須被刷新。

LM-factor算法 LM-factor=(response age)/(resource age)。
resource age =對象進入cache的時間-對象的last_modified
response age =當前時間-對象進入cache的時間

假設源服務器上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沒有更新,B就不用更新緩存,直接把緩存的內容放回給客戶端,同時,重置對象進入cache的時間為與源服務器確認的時間,比如2007-04-10 03:13:00,如果正好在這個後重新確認了頁面。重置後,resource age變長,相應在cache中存活的時間也變長。
如果有改變則把最新的index.htm返回給squid,squid收到會更新緩存,然後把新的index.htm返回給客戶端,同時根據新頁面中的Last_Modified和取頁面的時間,重新計算resource age,進一步計算出存活時間。實際上,一個頁面進入cache後,他的存活時間就確定了,即 (resource age) * 百分比,一直到被重新確認。

留言

這個網誌中的熱門文章

How do I compile ffmpeg on a QNAP NAS

Tested on QNAP TS-419p+ with ARM CPU, but should work the same way for others. Install “Optware (IPKG)” qpkg from  http://www.qnap.com/qpkg.asp In case the “ipkg update” fails, try to adjust the following two config files: [/opt/etc/ipkg] # more tsx19-kmod.conf src/gz cs08q1armel http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable [/opt/etc/ipkg] # more tsx19.conf src/gz cs08q1armel http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/unstable ipkg update ipkg install optware-devel ipkg install git ipkg install yasm ipkg install lame mkdir /opt/compile cd /opt/compile git clone git://git.videolan.org/ffmpeg.git cd ffmpeg ./configure --enable-ssse3 --prefix=/opt --extra-cflags='-I/opt/include' --extra-ldflags='-L/opt/lib' --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-libmp3lame make make install replace built-in ffmpeg with link to new version rm /usr/bin/ffmpeg ln -s /opt/bin/ffmpeg /usr/bin http://bubbl

Setting up a CUPS server with Docker on a Synology NAS for my Brother printer

I made the unfortunate mistake of purchasing a cheap brother printer, the Brother HL-L2300D, which is USB only. And not only is it a USB printer, it is a Winprinter which makes it very limited in anything other than Windows. from Pocket http://ift.tt/2gbYuYH via IFTTT

台灣第一家「真.無人商店」登場,711 推出台灣第一家臉部辨識無人超商!

【我們為什麼挑選這篇文章】上週我們才看了亞馬遜盛大開幕,這週 711 就公布了無人商店實驗店,在這如雨後春筍般的無人商店潮中,我們的生活正在疾速變動。但我覺得全家的概念也蠻有意思的:「與其推出一間跨時代概 from Pocket http://ift.tt/2BCDxQp via IFTTT