http: 缓存
http/1.0
- Pragma:
它用于向后兼容HTTP / 1.0缓存,其中Cache-Control HTTP / 1.1标头尚不存在。
注意:没有为HTTP响应指定Pragma,因此它不是一般HTTP / 1.1 Cache-Control标头的可靠替代品,尽管它的行为与Cache-Control相同:no-cache,如果Cache-Control标头字段是 在请求中省略。 仅将Pragma用于向后兼容HTTP / 1.0客户端。
就一个指令:
Pragma: no-cache
The "Pragma" header field allows backwards compatibility with
HTTP/1.0 caches, so that clients can specify a "no-cache" request
that they will understand (as Cache-Control was not defined until
HTTP/1.1). When the Cache-Control header field is also present and
understood in a request, Pragma is ignored.
向后兼容http/1.0 缓存, 针对 http/1.0 客户端, Pragma: no-cache 将被识别;
当 Cache-Control 也存在,并且可以被识别, Pragma将被忽略。
http/1.1
- Age
- Expires
- Cache-Control
- Age
The Age header contains the time in seconds the object has been in a proxy cache.
代理缓存中的时间,
- Expires
If there is a Cache-Control
header with the max-age
or s-maxage
directive in the response, the Expires
header is ignored.
如果响应中存在带有max-age或s-maxage指令的Cache-Control标头,则忽略Expires标头。
- Cache-Control
指定过期时间
freshness lifetime
The freshness lifetime is calculated based on several headers. If a "Cache-control: max-age=N" header is specified, then the freshness lifetime is equal to N. If this header is not present, which is very often the case, it is checked if an Expires header is present. If an Expires header exists, then its value minus the value of the Date header determines the freshness lifetime. Finally, if neither header is present, look for a Last-Modified header. If this header is present, then the cache's freshness lifetime is equal to the value of the Date header minus the value of the Last-modified header divided by 10.
基于几个标题计算新鲜度寿命。 如果指定了“Cache-control:max-age = N”标题,则新鲜度寿命等于N.如果不存在该标题(通常是这种情况),则检查是否存在Expires标题。 如果存在Expires标头,则其值减去Date标头的值将确定新鲜度生存期。 最后,如果两个标头都不存在,请查找Last-Modified标头。 如果此标头存在,则缓存的新鲜度生命周期等于Date标头的值减去Last-modified标头的值除以10。
expirationTime = responseTime + freshnessLifetime - currentAge
缓存校验:ETag
Last-Modified 可作为弱校验器
ETag 可作为强校验器
总结:
Cache-Control 和 ETag 结合使用;
网友评论