HTTP 缓存控制

发布于 2024-10-06 14:16:03 字数 801 浏览 0 评论 0原文

我正在为此苦苦挣扎- 在 PHP 中,我为 GET AJAX 调用执行此操作

header('Cache-Control: max-age = 10000, private');

此后浏览器仍然设法发出请求?为什么?

header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 10000) . ' GMT');

不过效果很好!

谢谢

编辑

header("Cache-Control: private, max-age=10000");

似乎有效!

更多

规范是明确说明这一点。

cache-directive = cache-request-directive | cache-response-directive

http://www.w3.org/Protocols/rfc2616/rfc2616 -sec14.html#sec14.9.1

I am struggling with this -
In PHP, I do this for a GET AJAX call

header('Cache-Control: max-age = 10000, private');

The browser still manages to place a request thereafter? Why?

header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 10000) . ' GMT');

works fine, though!

Thanks

EDIT

header("Cache-Control: private, max-age=10000");

seems to work!!

MORE

The specification is explicit about this.

cache-directive = cache-request-directive | cache-response-directive

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1

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

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

发布评论

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

评论(2

夏至、离别 2024-10-13 14:16:03

你用Firebug吗?如果是,则在页面加载时转到 NET 选项卡检查浏览器看到的标头。这会让你知道可能出了什么问题......

我用这个 -

Cache-Control   public, max-age=60
Content-Type    text/html; charset=utf-8

Do you use Firebug? If yes, then go to the NET tab when your page loads & inspect what headers the browser is seeing. This will give you an idea as to what might be wrong...

I use this -

Cache-Control   public, max-age=60
Content-Type    text/html; charset=utf-8
泪之魂 2024-10-13 14:16:03

您希望浏览器缓存页面,我说得对吗?如果是这样,Cache-Control“private”可能是阻止浏览器缓存页面的罪魁祸首。根据 RFC-2616 第 14.9.1 节什么是可缓存,“私人”的意思是:

表示全部或部分响应消息适用于单个用户,并且不得由共享缓存进行缓存。这允许源服务器声明响应的指定部分仅适用于一个用户,并且不是对其他用户的请求的有效响应。私有(非共享)缓存可以缓存响应。

简单来说,这意味着缓存 HTTP 代理可能不会缓存页面,但 Web 浏览器可以。但请注意,如果 Cache-Control 包含“private”,则 Web 浏览器通常不会缓存页面。

Am I correct that you want the browser to cache the page? If so, Cache-Control "private" is likely the culprit that is preventing the browser from caching the page. According to RFC-2616 Section 14.9.1 What is Cacheable, "private" means:

Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the response are intended for only one user and are not a valid response for requests by other users. A private (non-shared) cache MAY cache the response.

Translated to plain English, this means that caching HTTP proxies may not cache the page, but the web browser can. Note, however, that web browsers often do not cache a page if Cache-Control includes "private".

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