This involves 4 header types:
Last-Modified (last modification time);
Expires (validity period);
Pragma (compilation instructions);
Cache-Control (cache Control);
The first three headers belong to the HTTP1.0 standard. The Last-Modified header uses UTC date and time values. If the caching system sees that the Last-Modified value is closer to the current time than the cached version of the page, it knows it should use the new version from the server.
Expires indicates when the cached version should expire (GMT). Setting this to a previous time will force the page on the server to be used.
Pragma defines how the page data should be processed. You can avoid caching the page like this:
header("Pragma:no-cache");
The Cache-Co0ntrol header was added in HTTP1.1, which can achieve more detailed Control (should also continue to use HTTP 1.0 headers). There are
many settings for Cache-Control, as shown in the following table:
The following example uses header() to set the browser's cache:
指令 | 含义 |
public | 可以在任何地方缓存 |
private | 只能被浏览器缓存 |
no-cache | 不能在任何地方缓存 |
must-revalidate | 缓存必须检查更新版本 |
proxy-revalidate | 代理缓存必须检查更新版本 |
max-age | 内容能够被缓存的时期,以秒表示 |
s-maxage | 覆盖共享缓存的max-age设置 |