List of usage examples for org.apache.http.client.cache CacheResponseStatus VALIDATED
CacheResponseStatus VALIDATED
To view the source code for org.apache.http.client.cache CacheResponseStatus VALIDATED.
Click Source Link
From source file:org.esigate.cache.CacheAdapter.java
public ClientExecChain wrapCachingHttpClient(final ClientExecChain wrapped) { return new ClientExecChain() { /**// w w w . java2 s.c o m * Removes client http cache directives like "Cache-control" and "Pragma". Users must not be able to bypass * the cache just by making a refresh in the browser. Generates X-cache header. * */ @Override public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext httpClientContext, HttpExecutionAware execAware) throws IOException, HttpException { OutgoingRequestContext context = OutgoingRequestContext.adapt(httpClientContext); // Switch route for the cache to generate the right cache key CloseableHttpResponse response = wrapped.execute(route, request, context, execAware); // Remove previously added Cache-control header if (request.getRequestLine().getMethod().equalsIgnoreCase("GET") && (staleWhileRevalidate > 0 || staleIfError > 0)) { response.removeHeader(response.getLastHeader("Cache-control")); } // Add X-cache header if (xCacheHeader) { if (context != null) { CacheResponseStatus cacheResponseStatus = (CacheResponseStatus) context .getAttribute(HttpCacheContext.CACHE_RESPONSE_STATUS); String xCacheString; if (cacheResponseStatus.equals(CacheResponseStatus.CACHE_HIT)) { xCacheString = "HIT"; } else if (cacheResponseStatus.equals(CacheResponseStatus.VALIDATED)) { xCacheString = "VALIDATED"; } else { xCacheString = "MISS"; } xCacheString += " from " + route.getTargetHost().toHostString(); xCacheString += " (" + request.getRequestLine().getMethod() + " " + request.getRequestLine().getUri() + ")"; response.addHeader("X-Cache", xCacheString); } } // Remove Via header if (!viaHeader && response.containsHeader("Via")) { response.removeHeaders("Via"); } return response; } }; }
From source file:org.apache.http.impl.client.cache.CachingExec.java
private void recordCacheUpdate(final HttpContext context) { cacheUpdates.getAndIncrement(); setResponseStatus(context, CacheResponseStatus.VALIDATED); }
From source file:org.apache.http.impl.client.cache.CachingHttpAsyncClient.java
private void recordCacheUpdate(final HttpCacheContext clientContext) { this.cacheUpdates.getAndIncrement(); setResponseStatus(clientContext, CacheResponseStatus.VALIDATED); }
From source file:org.apache.http.impl.client.cache.CachingHttpClient.java
private void recordCacheUpdate(HttpContext context) { cacheUpdates.getAndIncrement(); setResponseStatus(context, CacheResponseStatus.VALIDATED); }