HTTP响应缓存 [英] HTTP response caching

查看:125
本文介绍了HTTP响应缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确保我的servet的响应永远不会被broswer缓存,这样即使发出两个相同的请求(相隔一个纳秒),也始终会联系服务器。这是实现此目的的正确方法:

I want to ensure that my servet's response is never cached by the broswer, such that even if two identical requests are made (a nanosecond apart), the server is always contacted. Is this the correct way to achieve this:

class MyServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Cache-Control", "no-cache");
    }
}

谢谢,
Don

Thanks, Don

推荐答案

不,这不是正确的方法。这是正确的方法:

No, that's not the correct way. Here is the correct way:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

您可能会看到其他人建议其他条目/属性,但这些至少在完全不相关时上面提到了。

You'll probably see someone else suggesting other entries/attributes, but those are completely irrelevant when at least the above are mentioned.

在更改后的测试之前,不要忘记清除浏览器缓存。

Don't forget to clear your browser cache before testing after the change.

  • Caching tutorial for webmasters
  • Making sure a page is not cached across all browsers

这篇关于HTTP响应缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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