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
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 provided
and
invalid reference
EhCache
storage backends.
invalid reference
memcached
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
FieldsModifier and TypeFieldDescriptionprivate final DefaultCacheRevalidatorprivate final ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest> private static final org.slf4j.Loggerprivate final HttpCacheFields inherited from class CachingExecBase
cacheableRequestPolicy, cacheConfig, cacheHits, cacheMisses, cacheUpdates, responseCachingPolicy, responseGenerator, suitabilityChecker, validityPolicy -
Constructor Summary
ConstructorsConstructorDescriptionCachingExec(HttpCache cache, DefaultCacheRevalidator cacheRevalidator, CacheConfig config) -
Method Summary
Modifier and TypeMethodDescription(package private) org.apache.hc.core5.http.ClassicHttpResponsecacheAndReturnResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request, ExecChain.Scope scope, org.apache.hc.core5.http.ClassicHttpResponse backendResponse, Instant requestSent, Instant responseReceived) (package private) org.apache.hc.core5.http.ClassicHttpResponsecallBackend(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.ClassicHttpResponseconvert(SimpleHttpResponse cacheResponse) (package private) org.apache.hc.core5.http.ClassicHttpResponsedoExecute(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) org.apache.hc.core5.http.ClassicHttpResponseexecute(org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) Executes the actual HTTP request.(package private) org.apache.hc.core5.http.ClassicHttpResponsehandleBackendResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, Instant requestDate, Instant responseDate, org.apache.hc.core5.http.ClassicHttpResponse backendResponse) private org.apache.hc.core5.http.ClassicHttpResponsehandleCacheHit(RequestCacheControl requestCacheControl, ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) private org.apache.hc.core5.http.ClassicHttpResponsehandleCacheMiss(RequestCacheControl requestCacheControl, CacheHit partialMatch, 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.ClassicHttpResponsenegotiateResponseFromVariants(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain, List<CacheHit> variants) (package private) org.apache.hc.core5.http.ClassicHttpResponserevalidateCacheEntry(ResponseCacheControl responseCacheControl, CacheHit hit, 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.ClassicHttpResponserevalidateCacheEntryWithFallback(RequestCacheControl requestCacheControl, ResponseCacheControl responseCacheControl, CacheHit hit, 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.ClassicHttpResponserevalidateCacheEntryWithoutFallback(ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain)
-
Field Details
-
responseCache
-
cacheRevalidator
-
conditionalRequestBuilder
private final ConditionalRequestBuilder<org.apache.hc.core5.http.ClassicHttpRequest> conditionalRequestBuilder -
LOG
private static final org.slf4j.Logger LOG
-
-
Constructor Details
-
CachingExec
CachingExec(HttpCache cache, DefaultCacheRevalidator cacheRevalidator, CacheConfig config)
-
-
Method Details
-
execute
public org.apache.hc.core5.http.ClassicHttpResponse execute(org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException Description copied from interface:ExecChainHandlerExecutes 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:
executein interfaceExecChainHandler- Parameters:
request- the actual request.scope- the execution scope .chain- the next element in the request execution chain.- Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-
doExecute
org.apache.hc.core5.http.ClassicHttpResponse doExecute(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-
convert
private static org.apache.hc.core5.http.ClassicHttpResponse convert(SimpleHttpResponse cacheResponse) -
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 IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-
handleCacheHit
private org.apache.hc.core5.http.ClassicHttpResponse handleCacheHit(RequestCacheControl requestCacheControl, ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-
revalidateCacheEntry
org.apache.hc.core5.http.ClassicHttpResponse revalidateCacheEntry(ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-
revalidateCacheEntryWithoutFallback
org.apache.hc.core5.http.ClassicHttpResponse revalidateCacheEntryWithoutFallback(ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws org.apache.hc.core5.http.HttpException - Throws:
org.apache.hc.core5.http.HttpException
-
revalidateCacheEntryWithFallback
org.apache.hc.core5.http.ClassicHttpResponse revalidateCacheEntryWithFallback(RequestCacheControl requestCacheControl, ResponseCacheControl responseCacheControl, CacheHit hit, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws org.apache.hc.core5.http.HttpException, IOException - Throws:
org.apache.hc.core5.http.HttpExceptionIOException
-
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, Instant requestDate, Instant responseDate, org.apache.hc.core5.http.ClassicHttpResponse backendResponse) throws IOException - Throws:
IOException
-
cacheAndReturnResponse
org.apache.hc.core5.http.ClassicHttpResponse cacheAndReturnResponse(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.HttpRequest request, ExecChain.Scope scope, org.apache.hc.core5.http.ClassicHttpResponse backendResponse, Instant requestSent, Instant responseReceived) throws IOException - Throws:
IOException
-
handleCacheMiss
private org.apache.hc.core5.http.ClassicHttpResponse handleCacheMiss(RequestCacheControl requestCacheControl, CacheHit partialMatch, org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, ExecChain.Scope scope, ExecChain chain) throws IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.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, List<CacheHit> variants) throws IOException, org.apache.hc.core5.http.HttpException - Throws:
IOExceptionorg.apache.hc.core5.http.HttpException
-