“Expires” HTTP 标头是否需要在多个冷缓存请求之间保持一致?

发布于 2024-08-25 05:19:11 字数 256 浏览 6 评论 0 原文

我正在实现一种自定义网络服务器。我正在考虑添加 Expires 标头支持。但是,我有点不确定具体如何实施。

如果对服务器上相同的未更改资源发出多个冷缓存请求,并且服务器返回不同的 Expires 标头(假设它使用相对时间来计算 Expires 日期的确切值,例如从请求时间起 +6 小时),那么这也会使中间所有代理服务器上的缓存失效?或者这是不可能发生的(根据规范)?

Expires HTTP 标头是否需要在多个冷缓存请求之间保持一致?

I'm implementing a custom web server of a kind. And am looking into adding an Expires header support. However, I'm a little unsure of how exactly to implement it.

If multiple cold-cache requests are being made to the same unchanged resource on the server and the server returned different Expires header (say it uses relative time to calculate the exact value of the Expires date e.g. +6 hours from the request time), does that invalidate the cache on all the proxy servers in-between as well? Or is it impossible to happen (per the spec)?

Does the Expires HTTP header needs to be consistent across multiple cold-cache requests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不醒的梦 2024-09-01 05:19:11

好吧,没关系,在下找到了相关信息部分>HTTP 规范

基本上,您可以为您想要的所有不同验证器提供服务,但您必须注意,在这种情况下,代理可能有一组不同的验证器,这些验证器来自它们自己的缓存以及与通信的各种用户代理代理。他们可能会选择向您发送一份,但这对于最终用户来说可能不是正确的或最佳的。然而,规范中建议了“最佳方法”。

我想这应该涵盖 Expires 标头以及 ETags、Cache-Control 等。


以下是相关摘录,以防有人感兴趣:

当强制使用中间缓存时,
通过 max-age=0 指令,
重新验证其自己的缓存条目,以及
客户已经提供了自己的
请求中的验证器,提供的
验证器可能与
验证器当前存储在
缓存条目。在这种情况下,缓存
可以使用任一验证器来使其
自己的请求而不影响语义
透明度。然而,选择
验证器可能会影响性能。
最好的方法是对于
使用自己的中间缓存
验证器在发出请求时。如果
服务器回复 304(不是
修改),然后缓存就可以返回
现在已将其验证副本发送给客户端
并得到 200(OK)响应。如果
服务器回复一个新实体并且
然而,缓存验证器
中间缓存可以比较
返回验证器
在客户的要求中提供,
使用强比较功能。
如果客户端的验证器等于
源服务器的,然后
中间缓存简单地返回 304
(未修改)。否则,它返回
带有 200 的新实体(OK)
回复。如果请求包含
no-cache 指令,它不应该
包括最小新鲜、最大陈旧或
最大年龄。

Ok, never mind, found the relevant information under the Cache Revalidation and Reload Controls section of the HTTP Spec

Basically, you can serve all the different validators you want but you must be aware that in such case proxies may have a set of different validators from their own cache and from various user agents communicating with the proxy. They may choose to send one to you and that might not be the correct or the most optimal one for the end-users. However, a "best approach" has been suggested in the spec.

I suppose this should covers Expires headers as well as ETags, Cache-Control and whatnot.


Here's the relevant excerpt, in case anyone's interested:

When an intermediate cache is forced,
by means of a max-age=0 directive, to
revalidate its own cache entry, and
the client has supplied its own
validator in the request, the supplied
validator might differ from the
validator currently stored with the
cache entry. In this case, the cache
MAY use either validator in making its
own request without affecting semantic
transparency. However, the choice of
validator might affect performance.
The best approach is for the
intermediate cache to use its own
validator when making its request. If
the server replies with 304 (Not
Modified), then the cache can return
its now validated copy to the client
with a 200 (OK) response. If the
server replies with a new entity and
cache validator, however, the
intermediate cache can compare the
returned validator with the one
provided in the client's request,
using the strong comparison function.
If the client's validator is equal to
the origin server's, then the
intermediate cache simply returns 304
(Not Modified). Otherwise, it returns
the new entity with a 200 (OK)
response. If a request includes the
no-cache directive, it SHOULD NOT
include min-fresh, max-stale, or
max-age.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文