CacheControl JAX-RS公共指令

时间:2014-08-07 09:25:42

标签: java jax-rs cache-control

我尝试使用public类(JAX-RS)设置javax.ws.rs.core.CacheControl指令

例如:Cache-Control : public, max-age= 1000

但是这段代码确实创建了public指令:

Response.ResponseBuilder rb = Response.ok(entity);

CacheControl cacheControl = new CacheControl();
cacheControl.setPrivate(false);
cacheControl.setMaxAge(1000);

rb.cacheControl(cacheControl);
return rb.build();

1 个答案:

答案 0 :(得分:1)

通过cacheControl.setPrivate(false)将private设置为false并不意味着它应该被缓存public。还有一个no-cache令牌。 由于CacheControl没有设置public令牌的方法,您需要手动执行此操作:

CacheControl cacheControl = CacheControl.valueOf("public, max-age=1000")