public Entry put(String key, MediaType mediaType, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified) { Entry previousValue = internalCache.get(key, mediaType); int sizeDiff = -1; if (previousValue == null) sizeDiff = cached.length; else sizeDiff = cached.length - previousValue.getCached().length; if (bytes.addAndGet(sizeDiff) > maxBytes) { clear(); bytes.addAndGet(sizeDiff); } return internalCache.put(key, mediaType, headers, cached, expires, etag, lastModified); }
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = (String) request.getHeaderString(HttpHeaders.ACCEPT); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); // if Accept is present, use it, if not fallback to response Content-Type MediaType mediaType = accept != null ? MediaType.valueOf(accept) : MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
BrowserCache.Entry entry = cache.put(request.getUri().toString(), old.getMediaType(), old.getHeaders(), old.getCached(), expires, etag, lastModified); useCacheEntry(response, entry);
public Entry put(String key, MediaType mediaType, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified) { Entry previousValue = internalCache.get(key, mediaType); int sizeDiff = -1; if (previousValue == null) sizeDiff = cached.length; else sizeDiff = cached.length - previousValue.getCached().length; if (bytes.addAndGet(sizeDiff) > maxBytes) { clear(); bytes.addAndGet(sizeDiff); } return internalCache.put(key, mediaType, headers, cached, expires, etag, lastModified); }
public Entry put(String key, MediaType mediaType, MultivaluedMap<String, String> headers, byte[] cached, int expires, String etag, String lastModified) { Entry previousValue = internalCache.get(key, mediaType); int sizeDiff = -1; if (previousValue == null) sizeDiff = cached.length; else sizeDiff = cached.length - previousValue.getCached().length; if (bytes.addAndGet(sizeDiff) > maxBytes) { clear(); bytes.addAndGet(sizeDiff); } return internalCache.put(key, mediaType, headers, cached, expires, etag, lastModified); }
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); MediaType mediaType = MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = (String) request.getHeaderString(HttpHeaders.ACCEPT); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); // if Accept is present, use it, if not fallback to response Content-Type MediaType mediaType = accept != null ? MediaType.valueOf(accept) : MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
BrowserCache.Entry entry = cache.put(request.getUri().toString(), old.getMediaType(), old.getHeaders(), old.getCached(), expires, etag, lastModified); useCacheEntry(response, entry);
BrowserCache.Entry entry = cache.put(request.getUri().toString(), old.getMediaType(), old.getHeaders(), old.getCached(), expires, etag, lastModified); useCacheEntry(response, entry);