zoukankan      html  css  js  c++  java
  • http 缓存相关

    首先分享一下CI中文件强制下载时的header设置。

    
    [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的设置让人比较迷惑。

    关于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

    关于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.

    关于Pragma:public 作用未知,还请阅读本篇文章的各位大侠给予解释。

  • 相关阅读:
    blktrace分析IO
    Mac-配置SecureCRT
    Mac-安装itellij idea
    Mac-sublime text 3破解版
    Mac-item+zsh
    Mac-安装homebrew
    Mac-装机
    Mac-WIFI总是断网
    Git-ssh登录github
    Git-回滚操作
  • 原文地址:https://www.cnblogs.com/1995hxt/p/5686063.html
Copyright © 2011-2022 走看看