13

How to disable caching ?

What headers should doGet set?

Could you provide a code snippet?

1

2 Answers 2

28

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");
Sign up to request clarification or add additional context in comments.

2 Comments

I believe you would like to add response.setDateHeader("Expires", 0); for proxies. See another answer
Which servlet should we write this code into? the one that is redirecting to the html page keeping the cache?
0

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

eg.

if is set header like follow

JAVA code

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.