Disabling Client Cache from Jetty Server for REST Requests

I have a Java REST server implemented with a Jetty powered jersey. It seems that some browsers (IE7) internally cache all requests made to the server.

I would like to do this in order to send a specific HTTP header in response from the REST server, indicating to the browser that it should not cache this response, and therefore will request the server again the next time it needs access to this resource.

Any ideas on how to set up a Jersey / Jetty for this? Or the only way to configure it on the client side?

+3
source share
4 answers

-, Jetty HTTP- appopriate. Last-Modified Cache-Control.

+2

, ( ).

response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires", "0");

, , URL-, : http://www.company.com/services/staff?id=xxx&requestTime=" + (. Date()) GetTime(); , url , .

+2

@Dave : , http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9, , Cache-control , . , , , () (. , 14.9.1).

@all: In addition, section 14.21 of the same document states that the Expires header set to 0 means β€œinvalid date” and may be ignored by clients. And my tests with sending an expiration date to 1 jan 1970 (timestamp 0) does not cause anything but ignoring IE (and ff, for that matter), which will still cache the response.

My solution was to send the current date for the Expires field, which the spec says.

0
source

Source: https://habr.com/ru/post/1697465/


All Articles