Recently studied the Last-Modified cache mechanism using http, which allows the browser to read the cache file.
$num = 4; //Simulate server data changes to determine whether the browser needs to read the cache file
if($num==4) {
if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){
$browserCachedCopyTimestamp = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ( ( $browserCachedCopyTimestamp + 3600 ) > time() ) {
header("HTTP/1.1 304");
exit(1);
}
}
}else{
header('Last-Modified: '.gmdate('D, d M Y H:i:s',time())." GMT");
header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600)." GMT");
header("Cache-Control:max-age=3600");
for( $i=1; $i < 10 ; $i++ ){
echo "$i|";
}
}
I tested above that the cache file can be read, but I just checked online and said it is
[Last-Modified and ETags request http headers are used together. The server first generates the Last-Modified/Etag tag. The server can later use it to determine whether the page has been modified and determine whether the file should continue to be cached]
Why use Last-Modified and ETags together? Don't understand.