Java servlet 如何禁用页面缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3976624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 07:50:24  来源:igfitidea点击:

Java servlet how to disable caching of page

javaservlets

提问by EugeneP

How to disable caching ?

如何禁用缓存?

What headers should doGet set?

doGet 应该设置哪些标头?

Could you provide a code snippet?

你能提供一个代码片段吗?

采纳答案by rsp

This will set caching to disabled on the response:

这将在响应中将缓存设置为禁用:

// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");

// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");

回答by Alpesh Jikadra

I want to disabled the varnish cache if backend server return some header

如果后端服务器返回一些标头,我想禁用清漆缓存

eg.

例如。

if is set header like follow

如果设置标题像follow

JAVA code

JAVA代码

ServletActionContext.getResponse().addHeader("ABC","true")

then in varnish if I found value of header ABC as true then I don't want to cache this page.

然后在清漆中,如果我发现标题 ABC 的值为 true,那么我不想缓存此页面。