Class BasicHttpCache
- java.lang.Object
-
- org.apache.http.impl.client.cache.BasicHttpCache
-
-
Field Summary
Fields Modifier and Type Field Description private CacheEntryUpdatercacheEntryUpdaterprivate HttpCacheInvalidatorcacheInvalidatorprivate org.apache.commons.logging.Loglogprivate longmaxObjectSizeBytesprivate ResourceFactoryresourceFactoryprivate CachedHttpResponseGeneratorresponseGeneratorprivate static java.util.Set<java.lang.String>safeRequestMethodsprivate HttpCacheStoragestorageprivate CacheKeyGeneratoruriExtractor
-
Constructor Summary
Constructors Constructor Description BasicHttpCache()BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config)BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor)BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor, HttpCacheInvalidator cacheInvalidator)BasicHttpCache(CacheConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddVariantWithEtag(java.lang.String variantKey, java.lang.String variantCacheKey, java.util.Map<java.lang.String,Variant> variants)CloseableHttpResponsecacheAndReturnResponse(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, CloseableHttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived)Store aHttpResponsein the cache if possible, and returnorg.apache.http.HttpResponsecacheAndReturnResponse(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived)Store aHttpResponsein the cache if possible, and return(package private) HttpCacheEntrydoGetUpdatedParentEntry(java.lang.String requestId, HttpCacheEntry existing, HttpCacheEntry entry, java.lang.String variantKey, java.lang.String variantCacheKey)voidflushCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request)Clear all matchingHttpCacheEntrys.voidflushInvalidatedCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request)Clear invalidated matchingHttpCacheEntrysvoidflushInvalidatedCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, org.apache.http.HttpResponse response)Clear any entries that may be invalidated by the given response to a particular request.(package private) CloseableHttpResponsegenerateIncompleteResponseError(org.apache.http.HttpResponse response, Resource resource)HttpCacheEntrygetCacheEntry(org.apache.http.HttpHost host, org.apache.http.HttpRequest request)Retrieve matchingHttpCacheEntryfrom the cache if it exists(package private) SizeLimitedResponseReadergetResponseReader(org.apache.http.HttpRequest request, CloseableHttpResponse backEndResponse)java.util.Map<java.lang.String,Variant>getVariantCacheEntriesWithEtags(org.apache.http.HttpHost host, org.apache.http.HttpRequest request)Retrieve all variants from the cache, if there are no variants then an emptyMapis returned(package private) booleanisIncompleteResponse(org.apache.http.HttpResponse resp, Resource resource)voidreuseVariantEntryFor(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, Variant variant)Specifies cache should reuse the given cached variant to satisfy requests whose varying headers match those of the given client request.(package private) voidstoreInCache(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry entry)(package private) voidstoreNonVariantEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, HttpCacheEntry entry)(package private) voidstoreVariantEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, HttpCacheEntry entry)HttpCacheEntryupdateCacheEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry stale, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived)Update aHttpCacheEntryusing a 304HttpResponse.HttpCacheEntryupdateVariantCacheEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry stale, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived, java.lang.String cacheKey)Update a specificHttpCacheEntryrepresenting a cached variant using a 304HttpResponse.
-
-
-
Field Detail
-
safeRequestMethods
private static final java.util.Set<java.lang.String> safeRequestMethods
-
uriExtractor
private final CacheKeyGenerator uriExtractor
-
resourceFactory
private final ResourceFactory resourceFactory
-
maxObjectSizeBytes
private final long maxObjectSizeBytes
-
cacheEntryUpdater
private final CacheEntryUpdater cacheEntryUpdater
-
responseGenerator
private final CachedHttpResponseGenerator responseGenerator
-
cacheInvalidator
private final HttpCacheInvalidator cacheInvalidator
-
storage
private final HttpCacheStorage storage
-
log
private final org.apache.commons.logging.Log log
-
-
Constructor Detail
-
BasicHttpCache
public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor, HttpCacheInvalidator cacheInvalidator)
-
BasicHttpCache
public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config, CacheKeyGenerator uriExtractor)
-
BasicHttpCache
public BasicHttpCache(ResourceFactory resourceFactory, HttpCacheStorage storage, CacheConfig config)
-
BasicHttpCache
public BasicHttpCache(CacheConfig config)
-
BasicHttpCache
public BasicHttpCache()
-
-
Method Detail
-
flushCacheEntriesFor
public void flushCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request) throws java.io.IOExceptionDescription copied from interface:HttpCacheClear all matchingHttpCacheEntrys.- Specified by:
flushCacheEntriesForin interfaceHttpCache- Throws:
java.io.IOException
-
flushInvalidatedCacheEntriesFor
public void flushInvalidatedCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, org.apache.http.HttpResponse response)Description copied from interface:HttpCacheClear any entries that may be invalidated by the given response to a particular request.- Specified by:
flushInvalidatedCacheEntriesForin interfaceHttpCache
-
storeInCache
void storeInCache(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry entry) throws java.io.IOException- Throws:
java.io.IOException
-
storeNonVariantEntry
void storeNonVariantEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, HttpCacheEntry entry) throws java.io.IOException- Throws:
java.io.IOException
-
storeVariantEntry
void storeVariantEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, HttpCacheEntry entry) throws java.io.IOException- Throws:
java.io.IOException
-
reuseVariantEntryFor
public void reuseVariantEntryFor(org.apache.http.HttpHost target, org.apache.http.HttpRequest req, Variant variant) throws java.io.IOExceptionDescription copied from interface:HttpCacheSpecifies cache should reuse the given cached variant to satisfy requests whose varying headers match those of the given client request.- Specified by:
reuseVariantEntryForin interfaceHttpCache- Parameters:
target- host of the upstream client requestreq- request sent by upstream clientvariant- variant cache entry to reuse- Throws:
java.io.IOException- may be thrown during cache update
-
isIncompleteResponse
boolean isIncompleteResponse(org.apache.http.HttpResponse resp, Resource resource)
-
generateIncompleteResponseError
CloseableHttpResponse generateIncompleteResponseError(org.apache.http.HttpResponse response, Resource resource)
-
doGetUpdatedParentEntry
HttpCacheEntry doGetUpdatedParentEntry(java.lang.String requestId, HttpCacheEntry existing, HttpCacheEntry entry, java.lang.String variantKey, java.lang.String variantCacheKey) throws java.io.IOException
- Throws:
java.io.IOException
-
updateCacheEntry
public HttpCacheEntry updateCacheEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry stale, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived) throws java.io.IOException
Description copied from interface:HttpCacheUpdate aHttpCacheEntryusing a 304HttpResponse.- Specified by:
updateCacheEntryin interfaceHttpCache- Returns:
- the updated
HttpCacheEntry - Throws:
java.io.IOException
-
updateVariantCacheEntry
public HttpCacheEntry updateVariantCacheEntry(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, HttpCacheEntry stale, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived, java.lang.String cacheKey) throws java.io.IOException
Description copied from interface:HttpCacheUpdate a specificHttpCacheEntryrepresenting a cached variant using a 304HttpResponse.- Specified by:
updateVariantCacheEntryin interfaceHttpCache- Parameters:
target- host for client requestrequest- actual request from upstream clientstale- current variant cache entryoriginResponse- 304 response received from originrequestSent- when the validating request was sentresponseReceived- when the validating response was receivedcacheKey- where in the cache this entry is currently stored- Returns:
- the updated
HttpCacheEntry - Throws:
java.io.IOException
-
cacheAndReturnResponse
public org.apache.http.HttpResponse cacheAndReturnResponse(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, org.apache.http.HttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived) throws java.io.IOExceptionDescription copied from interface:HttpCacheStore aHttpResponsein the cache if possible, and return- Specified by:
cacheAndReturnResponsein interfaceHttpCache- Returns:
- the
HttpResponse - Throws:
java.io.IOException
-
cacheAndReturnResponse
public CloseableHttpResponse cacheAndReturnResponse(org.apache.http.HttpHost host, org.apache.http.HttpRequest request, CloseableHttpResponse originResponse, java.util.Date requestSent, java.util.Date responseReceived) throws java.io.IOException
Description copied from interface:HttpCacheStore aHttpResponsein the cache if possible, and return- Specified by:
cacheAndReturnResponsein interfaceHttpCache- Returns:
- the
HttpResponse - Throws:
java.io.IOException
-
getResponseReader
SizeLimitedResponseReader getResponseReader(org.apache.http.HttpRequest request, CloseableHttpResponse backEndResponse)
-
getCacheEntry
public HttpCacheEntry getCacheEntry(org.apache.http.HttpHost host, org.apache.http.HttpRequest request) throws java.io.IOException
Description copied from interface:HttpCacheRetrieve matchingHttpCacheEntryfrom the cache if it exists- Specified by:
getCacheEntryin interfaceHttpCache- Returns:
- the matching
HttpCacheEntryornull - Throws:
java.io.IOException
-
flushInvalidatedCacheEntriesFor
public void flushInvalidatedCacheEntriesFor(org.apache.http.HttpHost host, org.apache.http.HttpRequest request) throws java.io.IOExceptionDescription copied from interface:HttpCacheClear invalidated matchingHttpCacheEntrys- Specified by:
flushInvalidatedCacheEntriesForin interfaceHttpCache- Throws:
java.io.IOException
-
getVariantCacheEntriesWithEtags
public java.util.Map<java.lang.String,Variant> getVariantCacheEntriesWithEtags(org.apache.http.HttpHost host, org.apache.http.HttpRequest request) throws java.io.IOException
Description copied from interface:HttpCacheRetrieve all variants from the cache, if there are no variants then an emptyMapis returned- Specified by:
getVariantCacheEntriesWithEtagsin interfaceHttpCache- Returns:
- a
Mapmapping Etags to variant cache entries - Throws:
java.io.IOException
-
addVariantWithEtag
private void addVariantWithEtag(java.lang.String variantKey, java.lang.String variantCacheKey, java.util.Map<java.lang.String,Variant> variants) throws java.io.IOException- Throws:
java.io.IOException
-
-