缓存控制:必须重新验证是否有义务验证所有请求,或仅仅是过时的请求? [英] Is Cache-Control:must-revalidate obliging to validate all requests, or just the stale ones?

查看:177
本文介绍了缓存控制:必须重新验证是否有义务验证所有请求,或仅仅是过时的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个标题感到困惑,我已经读过 Cache-Control:must-revalidate 在提供缓存项目之前要求使用源验证所有请求,但是只是陈旧的?或者无论陈旧还是新鲜?我已经在不同的地方阅读了这两件事。

I have a mess with this header, I have read that Cache-Control:must-revalidate oblige to validate all requests with the source before serving a cached item, but just the stale ones? or all no matter if stale or fresh? I have read both things in different places.

Cache-Control:no-cache 有什么区别?因为这些标题看起来与我相同。

What is the difference with Cache-Control:no-cache ? Because these headers look equivalent to me.

更新1:我从一本书中读过这篇文章:

UPDATE 1: I have read this from a book:


Cache-Control:必须重新验证响应头告诉缓存
绕过新鲜度计算机制并重新验证每个
访问

@Peter O.指出了RFC所说的内容。所以旧书是错误的。

@Peter O. has pointed out what the RFC says. So that old book is wrong.

更新2:在本教程中: http://www.mnot.net/cache_docs/


no-cache - 强制缓存每次都在释放缓存副本之前将请求提交到源服务器
进行验证。这是
有用,可以确保认证(与
public一起使用),或保持严格的新鲜度,同时不会牺牲所有
缓存的好处。

no-cache — forces caches to submit the request to the origin server for validation before releasing a cached copy, every time. This is useful to assure that authentication is respected (in combination with public), or to maintain rigid freshness, without sacrificing all of the benefits of caching.

必须重新验证 - 告诉缓存他们必须
服从你给他们的关于表示的任何新鲜度信息。
HTTP允许缓存在特殊的
条件下提供陈旧的表示;通过指定此标题,您告诉缓存
您希望它严格遵守您的规则。

must-revalidate — tells caches that they must obey any freshness information you give them about a representation. HTTP allows caches to serve stale representations under special conditions; by specifying this header, you’re telling the cache that you want it to strictly follow your rules.


推荐答案

14.9.4 HTTP / 1.1:

Section 14.9.4 of HTTP/1.1:



a缓存收到的响应
中存在must-revalidate指令时,该缓存绝不能使用条目成为
stale

以响应后续请求而不首先使用
原始服务器重新验证

When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server

HTTP / 1.1的第14.8节:

Section 14.8 of HTTP/1.1:


如果响应包含必须重新验证缓存控制
指令,则缓存可以在回复
后续请求时使用该响应。但如果响应是陈旧的,所有缓存
必须首先用原始服务器重新验证它...

If the response includes the "must-revalidate" cache-control directive, the cache MAY use that response in replying to a subsequent request. But if the response is stale, all caches MUST first revalidate it with the origin server...

因此,如果收到
必须重新验证,则必须重新验证过时的回复。

So it appears that only stale responses must be revalidated if must-revalidate is received.

对于 no-cache ,请参阅第14.9.1节:

For no-cache, see section 14.9.1:


如果no-cache指令没有指定字段名[在这里为
的情况下为
],然后缓存不得使用响应来满足
后续
请求使用原始服务器成功重新验证...

If the no-cache directive does not specify a field-name [which is the case here], then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server...

因此, no-cache 适用于新鲜和陈旧的回复。

Thus, no-cache applies both to fresh and stale responses.

编辑:

此短语可能与此相关(第13.3节) :

This phrase may be relevant here (section 13.3):


当缓存有一个陈旧的条目,它想用作客户请求的响应
,它首先必须检查原始服务器
(或者可能是一个带有新响应的中间缓存),看看
的缓存条目是否仍然可用。

When a cache has a stale entry that it would like to use as a response to a client's request, it first has to check with the origin server (or possibly an intermediate cache with a fresh response) to see if its cached entry is still usable.

因此,当缓存具有中间
缓存时,必须重新验证可能是相关的,否则缓存可以检查中间缓存是否为
新鲜的响应,而不是直接检查原始服务器。

So, must-revalidate is probably relevant when the cache has intermediate caches, since otherwise the cache can check the intermediate cache for a fresh response rather than check the origin server directly.

这篇关于缓存控制:必须重新验证是否有义务验证所有请求,或仅仅是过时的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆