Class EhcacheHttpCacheStorage<T>
java.lang.Object
org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage<T,T>
org.apache.hc.client5.http.impl.cache.ehcache.EhcacheHttpCacheStorage<T>
- All Implemented Interfaces:
HttpCacheStorage
This class is a storage backend for cache entries that uses the popular Ehcache cache implementation. In particular, this backend allows for spillover to disk, where the cache can be effectively larger than memory, and cached responses are paged into and out of memory from disk as needed.
N.B. Since the Ehcache is configured ahead of time with a
maximum number of cache entries, this effectively ignores the
CacheConfig.getMaxCacheEntries() maximum cache entries}
specified by a provided CacheConfig.
Please refer to the Ehcache documentation for details on how to configure the Ehcache itself.
- Since:
- 4.1
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEhcacheHttpCacheStorage(org.ehcache.Cache<String, T> cache, CacheConfig config, HttpCacheEntrySerializer<T> serializer) Constructs a storage backend using the provided Ehcache with the given configuration options, but using an alternative cache entry serialization strategy. -
Method Summary
Modifier and TypeMethodDescriptionbulkRestore(Collection<String> storageKeys) createObjectCache(org.ehcache.Cache<String, HttpCacheStorageEntry> cache, CacheConfig config) Creates cache that storesHttpCacheStorageEntrys without direct serialization.static EhcacheHttpCacheStorage<byte[]>createSerializedCache(org.ehcache.Cache<String, byte[]> cache, CacheConfig config) Creates cache that stores serializedHttpCacheStorageEntrys.protected voidprotected StringdigestToStorageKey(String key) protected TgetForUpdateCAS(String storageKey) protected TgetStorageObject(T element) protected Tprotected voidprotected booleanMethods inherited from class org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage
getEntries, getEntry, putEntry, removeEntry, updateEntry
-
Field Details
-
cache
-
-
Constructor Details
-
EhcacheHttpCacheStorage
public EhcacheHttpCacheStorage(org.ehcache.Cache<String, T> cache, CacheConfig config, HttpCacheEntrySerializer<T> serializer) Constructs a storage backend using the provided Ehcache with the given configuration options, but using an alternative cache entry serialization strategy.- Parameters:
cache- where to store cached origin responsesconfig- cache storage configuration options - note that the setting for max object size will be ignored and should be configured in the Ehcache instead.serializer- alternative serialization mechanism
-
-
Method Details
-
createObjectCache
public static EhcacheHttpCacheStorage<HttpCacheStorageEntry> createObjectCache(org.ehcache.Cache<String, HttpCacheStorageEntry> cache, CacheConfig config) Creates cache that storesHttpCacheStorageEntrys without direct serialization.- Since:
- 5.0
-
createSerializedCache
public static EhcacheHttpCacheStorage<byte[]> createSerializedCache(org.ehcache.Cache<String, byte[]> cache, CacheConfig config) Creates cache that stores serializedHttpCacheStorageEntrys.- Since:
- 5.0
-
digestToStorageKey
- Specified by:
digestToStorageKeyin classAbstractSerializingCacheStorage<T,T>
-
store
- Specified by:
storein classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
restore
- Specified by:
restorein classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
getForUpdateCAS
- Specified by:
getForUpdateCASin classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
getStorageObject
- Specified by:
getStorageObjectin classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
updateCAS
protected boolean updateCAS(String storageKey, T oldStorageObject, T storageObject) throws ResourceIOException - Specified by:
updateCASin classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
delete
- Specified by:
deletein classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-
bulkRestore
- Specified by:
bulkRestorein classAbstractSerializingCacheStorage<T,T> - Throws:
ResourceIOException
-