Class CachingExec
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cache.CachingExecBase
-
- org.apache.hc.client5.http.impl.cache.CachingExec
-
- All Implemented Interfaces:
ExecChainHandler
class CachingExec extends CachingExecBase implements ExecChainHandler
Request executor in the request execution chain that is responsible for transparent client-side caching.
The current implementation is conditionally compliant with HTTP/1.1 (meaning all the MUST and MUST NOTs are obeyed), although quite a lot, though not all, of the SHOULDs and SHOULD NOTs are obeyed too.
Folks that would like to experiment with alternative storage backends should look at the
HttpCacheStorage
interface and the related package documentation there. You may also be interested in the providedEhCache
andmemcached
storage backends.Further responsibilities such as communication with the opposite endpoint is delegated to the next executor in the request execution chain.
- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description private DefaultCacheRevalidator
cacheRevalidator
private ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest>
conditionalRequestBuilder
private static org.slf4j.Logger
LOG
private HttpCache
responseCache
-
Fields inherited from class org.apache.hc.client5.http.impl.cache.CachingExecBase
cacheableRequestPolicy, cacheConfig, cacheHits, cacheMisses, cacheUpdates, requestCompliance, responseCachingPolicy, responseCompliance, responseGenerator, suitabilityChecker, SUPPORTS_RANGE_AND_CONTENT_RANGE_HEADERS, validityPolicy, viaHeaders
-
-
Constructor Summary
Constructors Constructor Description CachingExec(ResourceFactory resourceFactory, HttpCacheStorage storage, java.util.concurrent.ScheduledExecutorService executorService, SchedulingStrategy schedulingStrategy, CacheConfig config)
CachingExec(HttpCache cache, java.util.concurrent.ScheduledExecutorService executorService, SchedulingStrategy schedulingStrategy, CacheConfig config)
CachingExec(HttpCache responseCache, CacheValidityPolicy validityPolicy, ResponseCachingPolicy responseCachingPolicy, CachedHttpResponseGenerator responseGenerator, CacheableRequestPolicy cacheableRequestPolicy, CachedResponseSuitabilityChecker suitabilityChecker, ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance, DefaultCacheRevalidator cacheRevalidator, ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest> conditionalRequestBuilder, CacheConfig config)
CachingExec(HttpCache cache, DefaultCacheRevalidator cacheRevalidator, CacheConfig config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) org.apache.hc.core5.http.ClassicHttpResponse
cacheAndReturnResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.ClassicHttpResponse backendResponse, ExecChain.Scope scope, java.time.Instant requestSent, java.time.Instant responseReceived)
(package private) org.apache.hc.core5.http.ClassicHttpResponse
callBackend(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain)
private static org.apache.hc.core5.http.ClassicHttpResponse
convert(SimpleHttpResponse cacheResponse, ExecChain.Scope scope)
org.apache.hc.core5.http.ClassicHttpResponse
execute(org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain)
Executes the actual HTTP request.(package private) org.apache.hc.core5.http.ClassicHttpResponse
handleBackendResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, java.time.Instant requestDate, java.time.Instant responseDate, org.apache.hc.core5.http.ClassicHttpResponse backendResponse)
private org.apache.hc.core5.http.ClassicHttpResponse
handleCacheHit(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, HttpCacheEntry entry)
private org.apache.hc.core5.http.ClassicHttpResponse
handleCacheMiss(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain)
(package private) org.apache.hc.core5.http.ClassicHttpResponse
negotiateResponseFromVariants(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, java.util.Map<java.lang.String,Variant> variants)
(package private) org.apache.hc.core5.http.ClassicHttpResponse
revalidateCacheEntry(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, HttpCacheEntry cacheEntry)
-
Methods inherited from class org.apache.hc.client5.http.impl.cache.CachingExecBase
clientRequestsOurOptions, explicitFreshnessRequest, generateCachedResponse, generateGatewayTimeout, generateViaHeader, getCacheHits, getCacheMisses, getCacheUpdates, getCurrentDate, getFatallyNonCompliantResponse, handleRevalidationFailure, mayCallBackend, recordCacheFailure, recordCacheHit, recordCacheMiss, recordCacheUpdate, revalidationResponseIsTooOld, setResponseStatus, shouldSendNotModifiedResponse, staleIfErrorAppliesTo, staleResponseNotAllowed, storeRequestIfModifiedSinceFor304Response, supportsRangeAndContentRangeHeaders, unvalidatedCacheHit
-
-
-
-
Field Detail
-
responseCache
private final HttpCache responseCache
-
cacheRevalidator
private final DefaultCacheRevalidator cacheRevalidator
-
conditionalRequestBuilder
private final ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest> conditionalRequestBuilder
-
LOG
private static final org.slf4j.Logger LOG
-
-
Constructor Detail
-
CachingExec
CachingExec(HttpCache cache, DefaultCacheRevalidator cacheRevalidator, CacheConfig config)
-
CachingExec
CachingExec(HttpCache responseCache, CacheValidityPolicy validityPolicy, ResponseCachingPolicy responseCachingPolicy, CachedHttpResponseGenerator responseGenerator, CacheableRequestPolicy cacheableRequestPolicy, CachedResponseSuitabilityChecker suitabilityChecker, ResponseProtocolCompliance responseCompliance, RequestProtocolCompliance requestCompliance, DefaultCacheRevalidator cacheRevalidator, ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest> conditionalRequestBuilder, CacheConfig config)
-
CachingExec
CachingExec(HttpCache cache, java.util.concurrent.ScheduledExecutorService executorService, SchedulingStrategy schedulingStrategy, CacheConfig config)
-
CachingExec
CachingExec(ResourceFactory resourceFactory, HttpCacheStorage storage, java.util.concurrent.ScheduledExecutorService executorService, SchedulingStrategy schedulingStrategy, CacheConfig config)
-
-
Method Detail
-
execute
public org.apache.hc.core5.http.ClassicHttpResponse execute(org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws java.io.IOException, org.apache.hc.core5.http.HttpException
Description copied from interface:ExecChainHandler
Executes the actual HTTP request. The handler can choose to return a response message or delegate request execution to the next element in the execution chain.- Specified by:
execute
in interfaceExecChainHandler
- Parameters:
request
- the actual request.scope
- the execution scope .chain
- the next element in the request execution chain.- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
convert
private static org.apache.hc.core5.http.ClassicHttpResponse convert(SimpleHttpResponse cacheResponse, ExecChain.Scope scope)
-
callBackend
org.apache.hc.core5.http.ClassicHttpResponse callBackend(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws java.io.IOException, org.apache.hc.core5.http.HttpException
- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
handleCacheHit
private org.apache.hc.core5.http.ClassicHttpResponse handleCacheHit(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, HttpCacheEntry entry) throws java.io.IOException, org.apache.hc.core5.http.HttpException
- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
revalidateCacheEntry
org.apache.hc.core5.http.ClassicHttpResponse revalidateCacheEntry(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, HttpCacheEntry cacheEntry) throws java.io.IOException, org.apache.hc.core5.http.HttpException
- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
handleBackendResponse
org.apache.hc.core5.http.ClassicHttpResponse handleBackendResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, java.time.Instant requestDate, java.time.Instant responseDate, org.apache.hc.core5.http.ClassicHttpResponse backendResponse) throws java.io.IOException
- Throws:
java.io.IOException
-
cacheAndReturnResponse
org.apache.hc.core5.http.ClassicHttpResponse cacheAndReturnResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.ClassicHttpResponse backendResponse, ExecChain.Scope scope, java.time.Instant requestSent, java.time.Instant responseReceived) throws java.io.IOException
- Throws:
java.io.IOException
-
handleCacheMiss
private org.apache.hc.core5.http.ClassicHttpResponse handleCacheMiss(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws java.io.IOException, org.apache.hc.core5.http.HttpException
- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
negotiateResponseFromVariants
org.apache.hc.core5.http.ClassicHttpResponse negotiateResponseFromVariants(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, java.util.Map<java.lang.String,Variant> variants) throws java.io.IOException, org.apache.hc.core5.http.HttpException
- Throws:
java.io.IOException
org.apache.hc.core5.http.HttpException
-
-