Sometimes we need to control the expiration time of web pages such as home pages. But for example, if we use Chinacache's CDN, how should we design it so that it can cache my content?
Of course, the prerequisite is to turn on a function reload_into_ims on in the CDN. In this way, users Don’t worry about sending no-cache. This will convert no-cache into If-Modified-Since. So we write programs mainly to control If-Modified-Since. Remember, the cache system architecture is included It is best to control it with the backend, so the best way is to use a program to manage expiration. Haha, I only know PHP, so I will write one in PHP. The same applies to other programs. See my program below, haha, it expires in 5 minutes.
<?php
$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 MYH:i:s', $client_time).' GMT', true, 304);
exit(0);
}else{
header('Last-Modified: '.gmdate('D, d MYH:i:s', $now).' GMT', true, 200);
}
?>