Detailed explanation of cache settings in header (header field) (about Cache-control and pragma)

Source: Internet
Author: User
Tags time interval

First, share the header settings for a file in CI when it is forced to download.

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));
		
Others are better to understand, mainly about the Cache-control and pragma settings are more confusing.

About Cache-control must-revalidate: Force the page does not cache, the role and no-cache the same, but more stringent, mandatory means more obvious. Detailed role please refer to: http://hi.baidu.com/chenleibupt/blog/item/9627bec6932e5a179c163df2.html

About Post-check and pre-check:internet Explorer 5 use two new time interval instructions for HTTP header information: Pre-Check and Post-check. The Pre-Check extension defines such a time interval (in seconds): After this interval, an object should be selected for updating before it is displayed to the user. The selected object can also occur after the object has been displayed to the user, but make sure that the cached copy is updated the next time the user wants to see the object. The Post-check extension defines such a time interval (in seconds): After that time, the object is selected for updating before it is displayed to the user. That is, post-check=0,pre-check=0 is IE5.0 only to prevent cache statement. (Reference from http://bbs.chinaunix.net/thread-704320-1-1.html and http://blog.sina.com.cn/s/blog_5595d51401000b23.html)

About Pragma:no-cache, same with Cache-control:no-cache. Pragma:no-cache is compatible with HTTP 1.0, Cache-control:no-cache is provided by HTTP 1.1. Therefore, Pragma:no-cache can be applied to HTTP 1.0 and HTTP 1.1, while Cache-control:no-cache can only be applied to HTTP 1.1.

About the role of pragma:public unknown, please read this article of the heroes to give an explanation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.