Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling client cache from Jetty server for REST requests

I have a REST Java server implemented with Jersey running on Jetty. It seems that certain browsers (IE7) internally caches all requests made to the server.

What I would like to do is to send a certain HTTP header in the response from the REST server indicating the browser that it shouldn't cache that response, and so will query the server again the next time it needs access to that resource.

Any ideas on how to configure Jersey/Jetty for this? Or the only way to configure it is client-side?

like image 217
Santiago Palladino Avatar asked Dec 06 '25 04:12

Santiago Palladino


2 Answers

response.setHeader("Pragma", "no-cache");

No, No. No!

The use of the pragma header to disabling client side caching is wrong, it's a request header and has zero effect on the response.

http://www.mnot.net/cache_docs/#PRAGMA

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32

Also, setting Expires: 0 isn't correct, Expires should be a date, not a number of seconds, however this will work as an invalid http date is interpreted as "already expired"

http://www.mnot.net/cache_docs/#EXPIRES

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21

like image 85
Dave Cheney Avatar answered Dec 08 '25 18:12

Dave Cheney


There's nothing you can do about rogue clients, but Jetty can send the appopriate HTTP headers. Try here for info on configuring the Last-Modified and Cache-Control headers.

like image 34
Hank Gay Avatar answered Dec 08 '25 17:12

Hank Gay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!