This is the request information, you can see that cache-control has been set successfully.
But when requesting, you still have to request it again from the server.
The status here should be 200, but the size should be from cache.
This is the request information, you can see that cache-control has been set successfully.
But when requesting, you still have to request it again from the server.
The status here should be 200, but the size should be from cache.
Refer to the example below
<code><?php $cache_time = 3600; $modified_time = @$_SERVER['HTTP_IF_MODIFIED_SINCE']; if( strtotime($modified_time)+$cache_time > time() ){ header("HTTP/1.1 304"); exit; } header("Last-Modified: ".gmdate("D, d M Y H:i:s", time() )." GMT"); echo time(); ?> </code>
Open with a browser, we can see that when opened for the first time, the status code returned is 200, and the printing time is the latest time. Then when we open it for the second time, we can see that the status code is 304 and the time is the same as before, indicating that we are using cache. We delete the last_modified.php file, and then open the page for the third time. The browser returns a 404 error. It can be seen that although Last-Modified uses caching, it still needs to initiate an http request to the server every time the page is opened. The browser based on the user's $_SERVER[ 'HTTP_IF_MODIFIED_SINCE'] to determine whether the browser content has expired. If it has not expired, it will return a 304 status and the browser content will be read from the cache.