3

我从 Jersey @GET 方法返回了以下内容。它可以正常工作,但始终包含 No-cache 标头。我想让客户端缓存这些数据,因为它很少改变。

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

我在这里做错了吗?

4

2 回答 2

5

这是由于打开了 BASIC auth 造成的。

在上下文中指定这一点将更正问题:

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

希望这可以帮助其他人。

于 2010-02-24T20:39:23.233 回答
0

你的代码看起来不错。

你用的是哪个容器?确保没有禁用缓存。还要验证下游响应处理程序或过滤器没有设置 no-cache 指令。

于 2010-02-16T02:20:21.437 回答