This article introduces some basic knowledge about php Cache. For more information, see. we can use the header in the HTML page to control it by using the metatag and PHP programs. for example, the instance code is as follows :? Phpnbs... This article introduces some basic knowledge about php Cache. if you need it, please refer to the article.
We can use meta tag and header in the PHP program to control the HTML page. for example:
The instance code is as follows:
Write another HTML file c.htm: Haha, go
We requested 127.1/c.htm, clicked the link, and then used the back-to-back button of the browser to return to c.htm, and then click the link, as shown on the left. we found that when the cache command is added, we will go back and click the link no matter how we do it, the following network request URL is always gray, indicating that the browser did not initiate the actual network request, but directly called the cache page stored in the user's computer, unless the cache time expires, during this period, even if the actual content changes, the browser will not re-read our resources on the server. after modifying the echo sentence, you can click again to find that the network request is still gray. in this case, the browser updates the cache only in the following three cases:
(1) cache expiration
(2) the cache is cleared;
(3) F5 or ctrl + F5 force refresh. (this may vary with browser processing. my test environment is firefox 4)
When we block the preceding header command or use the following code, // tell the client browser not to use the cache, HTTP 1.1 Protocol
The instance code is as follows:
Header ("Cache-Control: no-cache, must-revalidate"); // tells the client browser that the Cache is not used and is compatible with the HTTP 1.0 Protocol.
The instance code is as follows:
header("Pragma: no-cache");
The browser will read resources from the server each time it requests. as shown in the figure on the right below. here, we can get a general idea of the browser's page cache processing. it is easy for us to come up with a scenario. sometimes we need it to be cached and sometimes it is not needed. you can use it based on the scenario. however, the cache function of the browser is very small, but it can save a little bit. sometimes, the browser cache is very powerful, and we need to force refresh to take effect, such as JS files, sometimes you change, even if the refresh is not changed. in addition to setting page cache in code, you can also configure it on servers such as APACHE, especially static resources. besides, adding cache can effectively reduce unnecessary requests.
Sometimes, we usually see