Question

I have the following returned from a Jersey @GET method. It works, fine but always includes the No-cache header. I'd like to allow the client to cache this data since it rarely changes.

ResponseBuilder rb = Response.ok(c);
    CacheControl cc = new CacheControl();
    cc.setMaxAge(60);
    cc.setNoCache(false);
    return rb.cacheControl(cc).build();

The response is always:

 Server Apache-Coyote/1.1
 Pragma No-cache
 Cache-Control  no-cache, no-transform, max-age=60
 Expires    Wed, 31 Dec 1969 19:00:00 EST
 Content-Type   application/xml
 Content-Length 291
 Date   Tue, 16 Feb 2010 01:54:02 GMT

That am I doing wrong here?

Was it helpful?

Solution

This was caused by having BASIC auth turned on.

Specifying this in the context will correct the issue:

<Valve className="org.apache.catalina.authenticator.BasicAuthenticator"
       disableProxyCaching="false" />

Hope this helps someone else out.

OTHER TIPS

Your code looks okay.

Which container are you using? Make sure cache is not disabled on it. Also verify downstream response handlers or filters aren't setting the no-cache directive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top