http 緩存相關

首先分享一下CI中文件強制下載時的header設置。php


[php] view plain copy

    if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)  
            {  
                header('Content-Type: "'.$mime.'"');  
                header('Content-Disposition: attachment; filename="'.$filename.'"');  
                header('Expires: 0');  
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  
                header("Content-Transfer-Encoding: binary");  
                header('Pragma: public');  
                header("Content-Length: ".strlen($data));  
            }  
            else  
            {  
                header('Content-Type: "'.$mime.'"');  
                header('Content-Disposition: attachment; filename="'.$filename.'"');  
                header("Content-Transfer-Encoding: binary");  
                header('Expires: 0');  
                header('Pragma: no-cache');  
                header("Content-Length: ".strlen($data));  
            }  

 

其餘的都比較好理解,主要是關於Cache-control和Pragma的設置讓人比較迷惑。html

關於Cache-Control的must-revalidate:強制頁面不緩存,做用與no-cache相同,但更嚴格,強制意味更明顯。詳細做用請參考:http://hi.baidu.com/chenleibupt/blog/item/9627bec6932e5a179c163df2.html緩存

關於post-check和pre-check:Internet Explorer 5對於HTTP頭信息使用兩種新的時間間隔指示:pre-check 和post-check。pre-check擴展名定義了這樣一段時間間隔(以秒記):即在這段時間間隔以後,一個對象在顯示給用戶以前應被選中進行更 新。選中對象也能夠發生在該對象已經顯示給用戶以後,可是,要保證在用戶下次想要看這個對象時,被高速緩存起來的副本是更新過的。post-check擴 展名定義了這樣一段時間間隔(以秒記):即在這段時間以後,在顯示給用戶以前,該對象被選中進行更新。即post-check=0,pre- check=0是IE5.0纔有的防cache聲明。(參考自http://bbs.chinaunix.net/thread-704320-1-1.htmlhttp://blog.sina.com.cn/s/blog_5595d51401000b23.html
post

關於Pragma:no-cache,跟Cache-Control: no-cache相同。Pragma: no-cache兼容http 1.0 ,Cache-Control: no-cache是http 1.1提供的。所以,Pragma: no-cache能夠應用到http 1.0 和http 1.1,而Cache-Control: no-cache只能應用於http 1.1..net

關於Pragma:public 做用未知,還請閱讀本篇文章的各位大俠給予解釋。3d

相關文章
相關標籤/搜索