我正在实现一种自定义网络服务器。我正在考虑添加 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?
发布评论
评论(1)
好吧,没关系,在下找到了相关信息部分>HTTP 规范
基本上,您可以为您想要的所有不同验证器提供服务,但您必须注意,在这种情况下,代理可能有一组不同的验证器,这些验证器来自它们自己的缓存以及与通信的各种用户代理代理。他们可能会选择向您发送一份,但这对于最终用户来说可能不是正确的或最佳的。然而,规范中建议了“最佳方法”。
我想这应该涵盖
Expires
标头以及 ETags、Cache-Control 等。以下是相关摘录,以防有人感兴趣:
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: