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
public class EhcacheHttpCacheStorage<T> extends AbstractSerializingCacheStorage<T,T>
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 providedCacheConfig.Please refer to the Ehcache documentation for details on how to configure the Ehcache itself.
- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description EhcacheHttpCacheStorage(org.ehcache.Cache<java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,T>bulkRestore(java.util.Collection<java.lang.String> storageKeys)static EhcacheHttpCacheStorage<HttpCacheStorageEntry>createObjectCache(org.ehcache.Cache<java.lang.String,HttpCacheStorageEntry> cache, CacheConfig config)Creates cache that storesHttpCacheStorageEntrys without direct serialization.static EhcacheHttpCacheStorage<byte[]>createSerializedCache(org.ehcache.Cache<java.lang.String,byte[]> cache, CacheConfig config)Creates cache that stores serializedHttpCacheStorageEntrys.protected voiddelete(java.lang.String storageKey)protected java.lang.StringdigestToStorageKey(java.lang.String key)protected TgetForUpdateCAS(java.lang.String storageKey)protected TgetStorageObject(T element)protected Trestore(java.lang.String storageKey)protected voidstore(java.lang.String storageKey, T storageObject)protected booleanupdateCAS(java.lang.String storageKey, T oldStorageObject, T storageObject)-
Methods inherited from class org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage
getEntries, getEntry, putEntry, removeEntry, updateEntry
-
-
-
-
Field Detail
-
cache
private final org.ehcache.Cache<java.lang.String,T> cache
-
-
Constructor Detail
-
EhcacheHttpCacheStorage
public EhcacheHttpCacheStorage(org.ehcache.Cache<java.lang.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 Detail
-
createObjectCache
public static EhcacheHttpCacheStorage<HttpCacheStorageEntry> createObjectCache(org.ehcache.Cache<java.lang.String,HttpCacheStorageEntry> cache, CacheConfig config)
Creates cache that storesHttpCacheStorageEntrys without direct serialization.- Since:
- 5.0
-
createSerializedCache
public static EhcacheHttpCacheStorage<byte[]> createSerializedCache(org.ehcache.Cache<java.lang.String,byte[]> cache, CacheConfig config)
Creates cache that stores serializedHttpCacheStorageEntrys.- Since:
- 5.0
-
digestToStorageKey
protected java.lang.String digestToStorageKey(java.lang.String key)
- Specified by:
digestToStorageKeyin classAbstractSerializingCacheStorage<T,T>
-
store
protected void store(java.lang.String storageKey, T storageObject) throws ResourceIOException- Specified by:
storein classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
restore
protected T restore(java.lang.String storageKey) throws ResourceIOException
- Specified by:
restorein classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
getForUpdateCAS
protected T getForUpdateCAS(java.lang.String storageKey) throws ResourceIOException
- Specified by:
getForUpdateCASin classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
getStorageObject
protected T getStorageObject(T element) throws ResourceIOException
- Specified by:
getStorageObjectin classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
updateCAS
protected boolean updateCAS(java.lang.String storageKey, T oldStorageObject, T storageObject) throws ResourceIOException- Specified by:
updateCASin classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
delete
protected void delete(java.lang.String storageKey) throws ResourceIOException- Specified by:
deletein classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
bulkRestore
protected java.util.Map<java.lang.String,T> bulkRestore(java.util.Collection<java.lang.String> storageKeys) throws ResourceIOException
- Specified by:
bulkRestorein classAbstractSerializingCacheStorage<T,T>- Throws:
ResourceIOException
-
-