The cache in the PHP header () has four types of identity headers: Last-modified,expires,pragma:no-cache,cache-control.
The following test environment is Google Chrome, the rest of the tests are not tested
Last-modified: When judging the cache, If-modified-since sends this value to the server.
Expires: The later date is used to identify when the cache expires
Pragma: Try to replace with Cache-control
Cache-control: You can have the following values:
Public: can be cached anywhere, including browsers, proxies, etc.
Private: Can only be cached by the browser, the shared cache cannot be cached
No-cache: Do not cache
No-store:
No-transform:
Must-revalidate: Cache must check for updated version
Proxy-revalidate: the proxy cache must check for newer versions
Max-age: The period in which content can be cached, expressed in seconds
S-maxage: Overwrite max-age settings for shared cache
Here's a look at last-modified
1.php
<?php$cache_expire_date = Gmdate ("D, D M Y h:i:s", Time () +), header ("Last-modified: $cache _expire_date");? ><a href= "2.php" title= "" >this is page 1</a><div> page 1 number:111</div>
2.php
<?php?><a href= "1.php" title= "" >this is page2</a><div> page 2 number:</div>
When you click on a link or refresh 1.php, you will find that there is more than one row if-modified-since field in its requestheaders. However, a separate last-modified does not have any caching effect.
Here's a look at expires:
Modify the 1.php
<?php$cache_expire_date = Gmdate ("D, D M Y h:i:s", Time () +), header ("Expires: $cache _expire_date");? ><a href= "2.php" title= "" >this is page 1</a><div> page 1 number:111</div>
When the first request 1.php, and ordinary no difference
Jump back to 1.php in 2.php, found that network--size is displayed in the from cache, and click on the file, its headers column is not requestheaders and other information. It is fetched directly from the cache. At this point, even if the number in the Div is modified, within 300 seconds, the 2.php link jumps back, still shows the unmodified page.
But after refreshing the page, the request is no different from the normal.
Now look at Cache-control.
Change the 1.php revision to
<?phpheader (' cache-control:private, ');? ><a href= "2.php" title= "" >this is page 1</a><div> page 1 number:111</div>
For Cache-control that do not have a time set, there is no difference between ordinary
Then continue to modify
<?phpheader (' cache-control:private, max-age=300 ');? ><a href= "2.php" title= "" >this is page 1</a><div> page 1 number:111</div>
This is similar to the one set by expires.
When the page is
<?phpheader (' cache-control:max-age=300 ');? ><a href= "2.php" title= "" >this is page 1</a><div> page 1 number:111</div>
Even if you do not set the private parameter, you will cache
When the parameter is No-cache, it will be re-requested