Class EhcacheHttpCacheStorage
- java.lang.Object
-
- org.apache.http.impl.client.cache.ehcache.EhcacheHttpCacheStorage
-
- All Implemented Interfaces:
HttpCacheStorage
public class EhcacheHttpCacheStorage extends java.lang.Object implements 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
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(net.sf.ehcache.Ehcache cache)
Constructs a storage backend using the provided Ehcache with default configuration options.EhcacheHttpCacheStorage(net.sf.ehcache.Ehcache cache, CacheConfig config)
Constructs a storage backend using the provided Ehcache with the given configuration options.EhcacheHttpCacheStorage(net.sf.ehcache.Ehcache cache, CacheConfig config, HttpCacheEntrySerializer 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 Instance Methods Concrete Methods Modifier and Type Method Description HttpCacheEntry
getEntry(java.lang.String key)
Retrieves the cache entry stored under the given key or null if no entry exists under that key.void
putEntry(java.lang.String key, HttpCacheEntry entry)
Store a given cache entry under the given key.void
removeEntry(java.lang.String key)
Deletes/invalidates/removes any cache entries currently stored under the given key.void
updateEntry(java.lang.String key, HttpCacheUpdateCallback callback)
Atomically applies the given callback to update an existing cache entry under a given key.
-
-
-
Constructor Detail
-
EhcacheHttpCacheStorage
public EhcacheHttpCacheStorage(net.sf.ehcache.Ehcache cache)
Constructs a storage backend using the provided Ehcache with default configuration options.- Parameters:
cache
- where to store cached origin responses
-
EhcacheHttpCacheStorage
public EhcacheHttpCacheStorage(net.sf.ehcache.Ehcache cache, CacheConfig config)
Constructs a storage backend using the provided Ehcache with the given configuration options.- 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.
-
EhcacheHttpCacheStorage
public EhcacheHttpCacheStorage(net.sf.ehcache.Ehcache cache, CacheConfig config, HttpCacheEntrySerializer 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
-
putEntry
public void putEntry(java.lang.String key, HttpCacheEntry entry) throws java.io.IOException
Description copied from interface:HttpCacheStorage
Store a given cache entry under the given key.- Specified by:
putEntry
in interfaceHttpCacheStorage
- Parameters:
key
- where in the cache to store the entryentry
- cached response to store- Throws:
java.io.IOException
-
getEntry
public HttpCacheEntry getEntry(java.lang.String key) throws java.io.IOException
Description copied from interface:HttpCacheStorage
Retrieves the cache entry stored under the given key or null if no entry exists under that key.- Specified by:
getEntry
in interfaceHttpCacheStorage
- Parameters:
key
- cache key- Returns:
- an
HttpCacheEntry
ornull
if no entry exists - Throws:
java.io.IOException
-
removeEntry
public void removeEntry(java.lang.String key)
Description copied from interface:HttpCacheStorage
Deletes/invalidates/removes any cache entries currently stored under the given key.- Specified by:
removeEntry
in interfaceHttpCacheStorage
-
updateEntry
public void updateEntry(java.lang.String key, HttpCacheUpdateCallback callback) throws java.io.IOException, HttpCacheUpdateException
Description copied from interface:HttpCacheStorage
Atomically applies the given callback to update an existing cache entry under a given key.- Specified by:
updateEntry
in interfaceHttpCacheStorage
- Parameters:
key
- indicates which entry to modifycallback
- performs the update; seeHttpCacheUpdateCallback
for details, but roughly the callback expects to be handed the current entry and will return the new value for the entry.- Throws:
java.io.IOException
HttpCacheUpdateException
-
-