在Cache-Control HTTP标头中使用max-age和s-maxage是否有意义? [英] Does it make sense to have max-age and s-maxage in the Cache-Control HTTP header?

查看:6263
本文介绍了在Cache-Control HTTP标头中使用max-age和s-maxage是否有意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到max-age适用于所有缓存,而s-maxage仅适用于共享缓存(代理和网关缓存)....

Considering that max-age applies to all the caches, and s-maxage only applies to shared caches (proxy and gateway cache)....

在不可过期和公共页面中使用这两个指令是否有意义?

控制器伪代码:

w = Response();
w.setPublic();
w.setMaxAge("1 year");
w.setShareMaxAge("1 year");

return w;


推荐答案

来自 HTTP标头字段定义


14.9.3基本到期机制的修改



...

14.9.3 Modifications of the Basic Expiration Mechanism

...

如果响应包含s-maxage指令,则对于共享缓存(但不包括私有缓存),此指令指定的最大年龄覆盖 max-age指令或Expires标题指定的最大年龄。

If a response includes an s-maxage directive, then for a shared cache (but not for a private cache), the maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header.

...

注意,覆盖。因此,只有当您打算为共享缓存指定不同的最大年龄时,才会有意义,而最终用户将使用 max-age

Note, "overrides". So, it would only make sense if you intend to specify a different maximum age for shared caches as compared to max-age, which would be used by end users.

在您的特定示例中,它们是相同的,因此指定 s-maxage 是不必要的。

In your particular example, they're the same, so specifying s-maxage is just unnecessary.

这篇关于在Cache-Control HTTP标头中使用max-age和s-maxage是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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