Mark Needham

Thoughts on Software Development

Archive for the ‘no-cache’ tag

Tomcat – No caching of RESTlet resources for Firefox

with 3 comments

One problem that we've been trying to solve today is how to make a RESTlet resource non cacheable.

The reason for this is that when a user logs out of the system and then hits the back button they shouldn't be able to see that page, but instead should see the login form.

After several hours of trawling Google and trying out various different suggestions we came across the idea of setting 'cache-control' with the value 'no-store' in the response headers.

The code to make this happen is as follows (use inside a class which extends Resource):

1
2
3
HttpResponse response = (HttpResponse) getResponse();
Series<Parameter> headers = response.getHttpCall().getResponseHeaders();
headers.add("cache-control", "no-store");

The important part in this example is the last line. As long as it's added to the Http Response Headers that response should no longer be cached.

A bit of research revealed that Internet Explorer may change the 'no-store' value to 'no-cache' so I'm not sure if this will work for that browser.

Written by Mark Needham

October 22nd, 2008 at 10:00 pm

Posted in Java

Tagged with , ,