Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable Tomcat caching completly?

I'm having trouble with a site im currently working on.

We are trying to make facebook connect comments widget. The widget loads every time we make a new request that responds with a 200 OK status. But when it returns with a 304 Not Modified the widget wont load.

It all points out to a caching issue. I tryed changin the context.xml

<Context cachingAllowed="false">

This did not seem to work. Any tips?

like image 392
flexterra Avatar asked Jan 28 '10 16:01

flexterra


1 Answers

This did not seem to work. Any tips?

The cachingAllowed attribute actually configures the server-side caching, not the client-side caching as you seem to expect.

Client-side caching is to be done with appropriate response headers. To entirely disable client-side caching on the particular resources, you need to create a Filter which listens on the desired url-pattern and has at least the following lines inside the doFilter() method:

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.

The response is here by the way the HttpServletResponse which is been casted back from the 2nd ServletResponse argument of the doFilter() method.

Don't forget to clear the client-side cache (thus, inside the webbrowser config) before testing this all :)

like image 141
BalusC Avatar answered Oct 13 '22 18:10

BalusC