Welcome to the Linux community forum, and interact with 2 million technical staff to enter our actual development. This may be the requirement of setting the expiration time for the webpage to expire within a period of time. For example, if we are using Chinacache CDN, how should we design it so that the user can cache my content? In this way, no-cache is not afraid of sending the content?
Welcome to the Linux community forum and interact with 2 million technical staff> in our actual development, we may have the need to make the webpage expire within a period of time, set the expiration time of the webpage. For example, if we are using Chinacache CDN, how should we design it so that the user can cache my content? In this way, no-cache is not afraid of sending the content?
Welcome to the Linux community forum and interact with 2 million technicians>
In our actual development, we may need to set the expiration time for the webpage to expire within a period of time. For example, if we use Chinacache CDN, how should we design it so that it can cache my content.
In this way, no-cache is not used. this will convert no-cache to If-Modified-Since. therefore, we can write a program to control If-Modified-Since. note: In the cache system architecture, it is best to control the backend, so the best way is to manage the expiration by program.
The following is the program code:
Set the page to expire in 5 minutes.
$ Headers = apache_request_headers ();
$ Client_time = (isset ($ headers ['if-Modified-Since '])? Strtotime ($ headers ['if-Modified-Since ']): 0 );
$ Now = gmmktime ();
$ Now_list = gmmktime ()-60*5;
If ($ client_time <$ now and $ client_time> $ now_list ){
Header ('Last-Modified: '. gmdate ('d, d m y h: I: s', $ client_time). 'gmt', true, 304 );
Exit (0 );
} Else {
Header ('Last-Modified: '. gmdate ('d, d m y h: I: s', $ now). 'gmt', true, 200 );
}
?>