Home  >  Q&A  >  body text

php - Using http's Last-Modified cache to read cached files?

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.

天蓬老师天蓬老师2620 days ago466

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 13:16:43

    引用别人的一篇回答链接描述

    reply
    0
  • Cancelreply