I have a jersey client returning json response. I have quite crudely set a no-cache header in all my jersey responses. However, when I am making changes, while I see the changes in the database...when I test the raw rest url, the data I have persisted isnt returned unless I restart the app server (Tomcat).
I have set no-cache using a ContainerResponseFilter.
public class HeaderResponseFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext request, ContainerResponseContext response) {
MediaType type = response.getMediaType();
if (type != null) {
String contentType = type.toString();
if (!contentType.contains("charset")) {
contentType = contentType + ";charset=utf-8";
response.getHeaders().putSingle("Content-Type", contentType);
response.getHeaders().putSingle("Cache-Control", "no-cache");
}
}
}
}
I am seeing no-cache set as the header in chrome:
Cache-Control:no-cache
Content-Length:1986
Content-Type:application/json;charset=utf-8
Date:Tue, 30 Sep 2014 20:22:02 GMT
Server:Apache-Coyote/1.1
Restart the app server..and voila, there it is, as per persisted database record.
I am using angularjs with Restangular, and am not explicity setting any cache policy on the client via Angular/Restangular...wouldn't know how at the moment.
Its nothing to do with angular/restangular, as bypassing this and going directly to the rest endpoint, I don't see what is persisted in Oracle. And its nothing to do with local caching in the browser, as when I try the raw URL in IE vs Chrome I can't see it either.
---Update--- have created an @NoCache annotation to try that approach, and in the client I am setting:
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
But i can't disable caching!! Help....
Any help appreciated.
Regards
i
Seems it was caching in my JPA layer....
Only a small app, so am disabling the EclipseLink shared cache...and now it is working.
<persistence-unit name="xp-jpa" transaction-type="RESOURCE_LOCAL">
<shared-cache-mode>NONE</shared-cache-mode>