我从 Jersey @GET 方法返回了以下内容。它工作正常,但始终包含 No-cache header 。我希望允许客户端缓存此数据,因为它很少更改。
ResponseBuilder rb = Response.ok(c);
CacheControl cc = new CacheControl();
cc.setMaxAge(60);
cc.setNoCache(false);
return rb.cacheControl(cc).build();
响应总是:
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
我是不是做错了?
最佳答案
这是由于启用了 BASIC 身份验证造成的。
在上下文中指定此项将更正问题:
<Valve className="org.apache.catalina.authenticator.BasicAuthenticator"
disableProxyCaching="false" />
希望这对其他人有帮助。
关于rest - 设置 Jersey 以允许缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2270186/