PHP Header Cache

Source: Internet
Author: User

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

    1. Last-modified: When judging the cache, If-modified-since sends this value to the server.

    2. Expires: The later date is used to identify when the cache expires

    3. Pragma: Try to replace with Cache-control

    4. Cache-control: You can have the following values:

      1. Public: can be cached anywhere, including browsers, proxies, etc.

      2. Private: Can only be cached by the browser, the shared cache cannot be cached

      3. No-cache: Do not cache

      4. No-store:

      5. No-transform:

      6. Must-revalidate: Cache must check for updated version

      7. Proxy-revalidate: the proxy cache must check for newer versions

      8. Max-age: The period in which content can be cached, expressed in seconds

      9. 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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.