protected Header[] mergeHeaders(HttpCacheEntry entry, HttpResponse response) { if (entryAndResponseHaveDateHeader(entry, response) && entryDateHeaderNewerThenResponse(entry, response)) { // Don't merge headers, keep the entry's headers as they are newer. return entry.getAllHeaders(); } List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry .getAllHeaders())); removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response); removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry); cacheEntryHeaderList.addAll(Arrays.asList(response.getAllHeaders())); return cacheEntryHeaderList.toArray(new Header[cacheEntryHeaderList.size()]); }
public HttpCacheEntry updateVariantCacheEntry(HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse, Date requestSent, Date responseReceived, String cacheKey) throws IOException { HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry( request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse); storage.putEntry(cacheKey, updatedEntry); return updatedEntry; }
public BasicHttpCache( final ResourceFactory resourceFactory, final HttpCacheStorage storage, final CacheConfig config, final CacheKeyGenerator uriExtractor, final HttpCacheInvalidator cacheInvalidator) { this.resourceFactory = resourceFactory; this.uriExtractor = uriExtractor; this.cacheEntryUpdater = new CacheEntryUpdater(resourceFactory); this.maxObjectSizeBytes = config.getMaxObjectSize(); this.responseGenerator = new CachedHttpResponseGenerator(); this.storage = storage; this.cacheInvalidator = cacheInvalidator; }
/** * Update the entry with the new information from the response. Should only be used for * 304 responses. * * @param requestId * @param entry The cache Entry to be updated * @param requestDate When the request was performed * @param responseDate When the response was gotten * @param response The HttpResponse from the backend server call * @return HttpCacheEntry an updated version of the cache entry * @throws java.io.IOException if something bad happens while trying to read the body from the original entry */ public HttpCacheEntry updateCacheEntry( String requestId, HttpCacheEntry entry, Date requestDate, Date responseDate, HttpResponse response) throws IOException { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_MODIFIED) throw new IllegalArgumentException("Response must have 304 status code"); Header[] mergedHeaders = mergeHeaders(entry, response); Resource resource = resourceFactory.copy(requestId, entry.getResource()); return new HttpCacheEntry( requestDate, responseDate, entry.getStatusLine(), mergedHeaders, resource); }
public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config) { this.resourceFactory = resourceFactory; this.uriExtractor = new CacheKeyGenerator(); this.cacheEntryUpdater = new CacheEntryUpdater(resourceFactory); this.maxObjectSizeBytes = config.getMaxObjectSize(); this.responseGenerator = new CachedHttpResponseGenerator(); this.storage = storage; this.cacheInvalidator = new CacheInvalidator(this.uriExtractor, this.storage); }
Args.check(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED, "Response must have 304 status code"); final Header[] mergedHeaders = mergeHeaders(entry, response); Resource resource = null; if (entry.getResource() != null) {
protected Header[] mergeHeaders(final HttpCacheEntry entry, final HttpResponse response) { if (entryAndResponseHaveDateHeader(entry, response) && entryDateHeaderNewerThenResponse(entry, response)) { // Don't merge headers, keep the entry's headers as they are newer. return entry.getAllHeaders(); } final List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry .getAllHeaders())); removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response); removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry); cacheEntryHeaderList.addAll(Arrays.asList(response.getAllHeaders())); return cacheEntryHeaderList.toArray(new Header[cacheEntryHeaderList.size()]); }
public HttpCacheEntry updateCacheEntry(HttpHost target, HttpRequest request, HttpCacheEntry stale, HttpResponse originResponse, Date requestSent, Date responseReceived) throws IOException { HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry( request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse); storeInCache(target, request, updatedEntry); return updatedEntry; }
public HttpCacheEntry updateCacheEntry(final HttpHost target, final HttpRequest request, final HttpCacheEntry stale, final HttpResponse originResponse, final Date requestSent, final Date responseReceived) throws IOException { final HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry( request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse); storeInCache(target, request, updatedEntry); return updatedEntry; }
public HttpCacheEntry updateVariantCacheEntry(final HttpHost target, final HttpRequest request, final HttpCacheEntry stale, final HttpResponse originResponse, final Date requestSent, final Date responseReceived, final String cacheKey) throws IOException { final HttpCacheEntry updatedEntry = cacheEntryUpdater.updateCacheEntry( request.getRequestLine().getUri(), stale, requestSent, responseReceived, originResponse); storage.putEntry(cacheKey, updatedEntry); return updatedEntry; }