Class ManagedHttpCacheStorage
- java.lang.Object
-
- org.apache.http.impl.client.cache.ManagedHttpCacheStorage
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,HttpCacheStorage
@Contract(threading=SAFE) public class ManagedHttpCacheStorage extends java.lang.Object implements HttpCacheStorage, java.io.Closeable
HttpCacheStorageimplementation capable of deallocating resources associated with the cache entries.This cache keeps track of cache entries using
PhantomReferenceand maintains a collection of all resources that are no longer in use. The cache, however, does not automatically deallocates associated resources by invokingResource.dispose()method. The consumer MUST periodically callcleanResources()method to trigger resource deallocation. The cache can be permanently shut down usingshutdown()method. All resources associated with the entries used by the cache will be deallocated.This
HttpCacheStorageimplementation is intended for use withFileResourceand similar.Compatibility note. Prior to version 4.4 this storage implementation used to dispose of all resource entries upon
close(). As of version 4.4 theclose()method disposes only of those resources that have been explicitly removed from the cache withremoveEntry(String)method.The
shutdown()()} method can still be used to shut down the storage and dispose of all resources currently managed by it.- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description ManagedHttpCacheStorage(CacheConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanResources()voidclose()HttpCacheEntrygetEntry(java.lang.String url)Retrieves the cache entry stored under the given key or null if no entry exists under that key.voidputEntry(java.lang.String url, HttpCacheEntry entry)Store a given cache entry under the given key.voidremoveEntry(java.lang.String url)Deletes/invalidates/removes any cache entries currently stored under the given key.voidshutdown()voidupdateEntry(java.lang.String url, HttpCacheUpdateCallback callback)Atomically applies the given callback to update an existing cache entry under a given key.
-
-
-
Constructor Detail
-
ManagedHttpCacheStorage
public ManagedHttpCacheStorage(CacheConfig config)
-
-
Method Detail
-
putEntry
public void putEntry(java.lang.String url, HttpCacheEntry entry) throws java.io.IOExceptionDescription copied from interface:HttpCacheStorageStore a given cache entry under the given key.- Specified by:
putEntryin interfaceHttpCacheStorage- Parameters:
url- where in the cache to store the entryentry- cached response to store- Throws:
java.io.IOException
-
getEntry
public HttpCacheEntry getEntry(java.lang.String url) throws java.io.IOException
Description copied from interface:HttpCacheStorageRetrieves the cache entry stored under the given key or null if no entry exists under that key.- Specified by:
getEntryin interfaceHttpCacheStorage- Parameters:
url- cache key- Returns:
- an
HttpCacheEntryornullif no entry exists - Throws:
java.io.IOException
-
removeEntry
public void removeEntry(java.lang.String url) throws java.io.IOExceptionDescription copied from interface:HttpCacheStorageDeletes/invalidates/removes any cache entries currently stored under the given key.- Specified by:
removeEntryin interfaceHttpCacheStorage- Throws:
java.io.IOException
-
updateEntry
public void updateEntry(java.lang.String url, HttpCacheUpdateCallback callback) throws java.io.IOExceptionDescription copied from interface:HttpCacheStorageAtomically applies the given callback to update an existing cache entry under a given key.- Specified by:
updateEntryin interfaceHttpCacheStorage- Parameters:
url- indicates which entry to modifycallback- performs the update; seeHttpCacheUpdateCallbackfor 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
-
cleanResources
public void cleanResources()
-
shutdown
public void shutdown()
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-