cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365)); cacheControl.setNoCache(false); cacheControl.setPrivate(false);
/** * Edit the response headers to indicating no caching. * * @param response response * @return builder */ protected ResponseBuilder noCache(final ResponseBuilder response) { final CacheControl cacheControl = new CacheControl(); cacheControl.setPrivate(true); cacheControl.setNoCache(true); cacheControl.setNoStore(true); return response.cacheControl(cacheControl); }
cacheControl.setPrivate(true); readFieldNames(cacheControl.getPrivateFields(), reader); } else if ("public".equals(directiveName)) {
cacheControl.setPrivate(true); readFieldNames(cacheControl.getPrivateFields(), reader); } else if ("public".equals(directiveName)) {
cacheControl.setPrivate(true); builder.cacheControl(cacheControl);
cacheControl.setPrivate(true); builder.cacheControl(cacheControl);
CacheControlledResponseFilter(CacheControl control) { final javax.ws.rs.core.CacheControl cacheControl = new javax.ws.rs.core.CacheControl(); cacheControl.setPrivate(control.isPrivate()); cacheControl.setNoCache(control.noCache()); cacheControl.setNoStore(control.noStore()); cacheControl.setNoTransform(control.noTransform()); cacheControl.setMustRevalidate(control.mustRevalidate()); cacheControl.setProxyRevalidate(control.proxyRevalidate()); cacheControl.setMaxAge((int) control.maxAgeUnit().toSeconds(control.maxAge())); cacheControl.setSMaxAge((int) control.sharedMaxAgeUnit() .toSeconds(control.sharedMaxAge())); if (control.immutable()) { cacheControl.setMaxAge(ONE_YEAR_IN_SECONDS); } cacheResponseHeader = cacheControl.toString(); }
protected CacheControl initCacheControl(Cache methodCached) { CacheControl cacheControl = new CacheControl(); if (methodCached.isPrivate()) { cacheControl.setPrivate(true); } if (methodCached.maxAge() > -1) { cacheControl.setMaxAge(methodCached.maxAge()); } if (methodCached.sMaxAge() > -1) { cacheControl.setSMaxAge(methodCached.sMaxAge()); } cacheControl.setMustRevalidate((methodCached.mustRevalidate())); cacheControl.setNoStore((methodCached.noStore())); cacheControl.setNoTransform((methodCached.noTransform())); cacheControl.setProxyRevalidate(methodCached.proxyRevalidate()); cacheControl.setNoCache(methodCached.noCache()); return cacheControl; }
@Inject public HttpHeader(final @Named(APPLICATION_ID) String applicationName, final @Named(ACCESS_CONTROL_MAX_AGE_DELTA_SECONDS) String deltaSeconds) { this.applicationName = applicationName; this.deltaSeconds = deltaSeconds; cacheControl = new CacheControl(); cacheControl.setPrivate(TRUE); cacheControl.setNoCache(TRUE); }
@Inject public HttpHeader() { cacheControl = new CacheControl(); cacheControl.setPrivate(TRUE); cacheControl.setNoCache(TRUE); }
@Inject public HttpHeader() { cacheControl = new CacheControl(); cacheControl.setPrivate(TRUE); cacheControl.setNoCache(TRUE); }
/** * Returns a CacheControl with a 1 year limit. Effectively forever. * * @return a CacheControl */ public static javax.ws.rs.core.CacheControl forever() { javax.ws.rs.core.CacheControl cacheForever = new javax.ws.rs.core.CacheControl(); cacheForever.setPrivate(false); cacheForever.setMaxAge(ONE_YEAR); return cacheForever; }
You can specify the cache's maxage by setMaxAge() of CacheControl class. Also you can set it to public or private according to your requirement **Follow the code snippets** @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/thumbnails", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getThumbnail(int id) { BodyBuilder builder = (BodyBuilder) ResponseEntity.ok(); CacheControl cc = new CacheControl(); cc.setMaxAge(64, TimeUnit.HOURS); cc.setPrivate(true); builder.cacheControl(cc); return builder.body(service.find(id)); }
@GET public String getAllSates(@Context HttpServletResponse response) { CacheControl cc = new CacheControl(); cc.setMaxAge(86400); cc.setPrivate(true); response.addHeader("Cache-Control", cc.toString()); [...] }
@GET public Response getImage(@PathParam("vreName") String vreName) { return transactionEnforcer.executeAndReturn(timbuctooActions -> { final Vre vre = timbuctooActions.getVre(vreName); if (vre == null) { return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build()); } final byte[] imageBlob = timbuctooActions.getVreImageBlob(vreName); final MediaType mediaType = vre.getMetadata().getImageMediaType(); if (imageBlob != null && mediaType != null) { final CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge(604800); cacheControl.setPrivate(false); return TransactionStateAndResult.commitAndReturn(Response .ok(imageBlob).type(mediaType).cacheControl(cacheControl).build()); } else { return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build()); } }); } }
/** * Set the caching header on the response * @param builder Response builder to put the caching header on * @param maxAgeSecs Max retention time on the client. Only set if the value is > 0 */ protected void setCachingHeader(Response.ResponseBuilder builder, int maxAgeSecs) { CacheControl cc = new CacheControl(); cc.setPrivate(false); cc.setNoCache(false); cc.setNoStore(false); if (maxAgeSecs>-1) cc.setMaxAge(maxAgeSecs); builder.cacheControl(cc); }
public CacheControl build() { CacheControl cacheControl = new CacheControl(); cacheControl.setMustRevalidate(mustRevalidate); cacheControl.setProxyRevalidate(proxyRevalidate); cacheControl.setMaxAge(maxAge); cacheControl.setSMaxAge(sMaxAge); cacheControl.setNoCache(noCache); cacheControl.setPrivate(privateFlag); cacheControl.setNoTransform(noTransform); cacheControl.setNoStore(noStore); if (privateFields != null) { cacheControl.getPrivateFields().addAll(privateFields); } if (noCacheFields != null) { cacheControl.getNoCacheFields().addAll(noCacheFields); } if (cacheExtension != null) { cacheControl.getCacheExtension().putAll(cacheExtension); } return cacheControl; } }
CacheControlledResponseFilter(CacheControl control) { final javax.ws.rs.core.CacheControl cacheControl = new javax.ws.rs.core.CacheControl(); cacheControl.setPrivate(control.isPrivate()); cacheControl.setNoCache(control.noCache()); cacheControl.setNoStore(control.noStore()); cacheControl.setNoTransform(control.noTransform()); cacheControl.setMustRevalidate(control.mustRevalidate()); cacheControl.setProxyRevalidate(control.proxyRevalidate()); cacheControl.setMaxAge((int) control.maxAgeUnit().toSeconds(control.maxAge())); cacheControl.setSMaxAge((int) control.sharedMaxAgeUnit() .toSeconds(control.sharedMaxAge())); if (control.immutable()) { cacheControl.setMaxAge(ONE_YEAR_IN_SECONDS); } cacheResponseHeader = cacheControl.toString(); }
protected CacheControl initCacheControl(Cache methodCached) { CacheControl cacheControl = new CacheControl(); if (methodCached.isPrivate()) { cacheControl.setPrivate(true); } if (methodCached.maxAge() > -1) { cacheControl.setMaxAge(methodCached.maxAge()); } if (methodCached.sMaxAge() > -1) { cacheControl.setSMaxAge(methodCached.sMaxAge()); } cacheControl.setMustRevalidate((methodCached.mustRevalidate())); cacheControl.setNoStore((methodCached.noStore())); cacheControl.setNoTransform((methodCached.noTransform())); cacheControl.setProxyRevalidate(methodCached.proxyRevalidate()); return cacheControl; }
protected CacheControl initCacheControl(Cache methodCached) { CacheControl cacheControl = new CacheControl(); if (methodCached.isPrivate()) { cacheControl.setPrivate(true); } if (methodCached.maxAge() > -1) { cacheControl.setMaxAge(methodCached.maxAge()); } if (methodCached.sMaxAge() > -1) { cacheControl.setSMaxAge(methodCached.sMaxAge()); } cacheControl.setMustRevalidate((methodCached.mustRevalidate())); cacheControl.setNoStore((methodCached.noStore())); cacheControl.setNoTransform((methodCached.noTransform())); cacheControl.setProxyRevalidate(methodCached.proxyRevalidate()); cacheControl.setNoCache(methodCached.noCache()); return cacheControl; }