cc.setMaxAge(600);
@GET @Produces(MediaType.APPLICATION_JSON) public Response getGeoJsonIsochrone() throws Exception { SimpleFeatureCollection contourFeatures = makeContourFeatures(computeIsochrone()); StringWriter writer = new StringWriter(); FeatureJSON fj = new FeatureJSON(); fj.writeFeatureCollection(contourFeatures, writer); CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok().entity(writer.toString()).cacheControl(cc).build(); }
@GET @Path("/tile/{layer}/{z}/{x}/{y}.{ext}") @Produces("image/*") public Response tileGet() throws Exception { // Re-use analyst Envelope2D env = SlippyTile.tile2Envelope(x, y, z); TileRequest tileRequest = new TileRequest(env, 256, 256); Router router = otpServer.getRouter(routerId); BufferedImage image = router.tileRendererManager.renderTile(tileRequest, layer); MIMEImageFormat format = new MIMEImageFormat("image/" + ext); ByteArrayOutputStream baos = new ByteArrayOutputStream(image.getWidth() * image.getHeight() / 4); ImageIO.write(image, format.type, baos); CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(baos.toByteArray()).type(format.toString()).cacheControl(cc).build(); }
private static Response generateStreamingGeotiffResponse(final GridCoverage2D coverage) { StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); new GeoTiffWriter(outStream).write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); //new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing twice and trashing compressed version? long t1 = System.currentTimeMillis(); LOG.debug("wrote geotiff in {}msec", t1-t0); } catch (Exception e) { LOG.error("exception while preparing geotiff : {}", e.getMessage()); throw new WebApplicationException(e); } } }; CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(streamingOutput) .type("image/geotiff") .cacheControl(cc) .build(); }
public static Response generateStreamingImageResponse( final BufferedImage image, final MIMEImageFormat format) { if (image == null) { LOG.warn("response image is null"); } StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); ImageIO.write(image, format.type, outStream); long t1 = System.currentTimeMillis(); LOG.debug("wrote image in {}msec", (int)(t1-t0)); } catch (Exception e) { LOG.error("exception while preparing image : {}", e.getMessage()); throw new WebApplicationException(e); } } }; CacheControl cc = new CacheControl(); cc.setMaxAge(3600); cc.setNoCache(false); return Response.ok(streamingOutput) .type(format.toString()) .cacheControl(cc) .build(); }
cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365)); cacheControl.setNoCache(false); cacheControl.setPrivate(false);
cacheControl.setProxyRevalidate(true); } else if ("max-age".equals(directiveName)) { cacheControl.setMaxAge(readIntValue(reader, directiveName)); } else if ("s-maxage".equals(directiveName)) { cacheControl.setSMaxAge(readIntValue(reader, directiveName));
cacheControl.setProxyRevalidate(true); } else if ("max-age".equals(directiveName)) { cacheControl.setMaxAge(readIntValue(reader, directiveName)); } else if ("s-maxage".equals(directiveName)) { cacheControl.setSMaxAge(readIntValue(reader, directiveName));
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(); }
cc.setMustRevalidate(false); cc.setNoCache(false); cc.setMaxAge(3600);
cc.setMaxAge(entry.getExpirationInSeconds()); if (builder != null)
@Path("/book") public Response getBook() throws InterruptedException { String book = " Sample Text Book"; TimeUnit.SECONDS.sleep(5); // thanks @fge final CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge((int) TimeUnit.MINUTES.toSeconds(1)); return Response.ok(book).cacheControl(cacheControl).build(); }
private CacheControl oneDayCache() { CacheControl cc = new CacheControl(); //Set max age to one day cc.setMaxAge(86400); return cc; } }
protected CacheControl createStandardCacheControl() { CacheControl cc = new CacheControl(); cc.setMaxAge((int) TimeUnit.SECONDS.convert(1, TimeUnit.DAYS)); return cc; }
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; }
/** * 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; }
private Caching(final int maxAge) { this.cacheControl = new CacheControl(); if (maxAge > 0) { cacheControl.setMaxAge(maxAge); } else { cacheControl.setNoCache(true); } }
private Caching(final int maxAge) { this.cacheControl = new CacheControl(); if (maxAge > 0) { cacheControl.setMaxAge(maxAge); } else { cacheControl.setNoCache(true); } }
Caching(final int maxAge) { this.cacheControl = new CacheControl(); if (maxAge > 0) { cacheControl.setMaxAge(maxAge); } else { cacheControl.setNoCache(true); } }
protected Response noCacheResponse( Object entity ) { CacheControl cc = new CacheControl(); cc.setNoCache( true ); cc.setMaxAge( -1 ); cc.setMustRevalidate( true ); return Response.ok( entity ).cacheControl( cc ).build(); }