Class ManagedHttpCacheStorage
- All Implemented Interfaces:
Closeable,AutoCloseable,HttpCacheStorage
HttpCacheStorage implementation capable of deallocating resources associated with
the cache entries.
This cache keeps track of cache entries using
PhantomReference and maintains a collection of all resources that
are no longer in use. The cache, however, does not automatically deallocates associated
resources by invoking Resource.dispose() method. The consumer MUST periodically
call cleanResources() method to trigger resource deallocation. The cache can be
permanently shut down using shutdown() method. All resources associated with
the entries used by the cache will be deallocated.
This HttpCacheStorage implementation is intended for use with FileResource
and 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 the close() method
disposes only of those resources that have been explicitly removed from the cache with
removeEntry(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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanprivate final CacheMapprivate final ReferenceQueue<HttpCacheEntry> private final Set<ResourceReference> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()private booleanprivate voidgetEntries(Collection<String> keys) Retrieves multiple cache entries stored under the given keys.Retrieves the cache entry stored under the given key or null if no entry exists under that key.booleanisActive()Check if the cache is still active and has not shut down.private voidvoidputEntry(String url, HttpCacheEntry entry) Store a given cache entry under the given key.voidremoveEntry(String url) Deletes/invalidates/removes any cache entries currently stored under the given key.voidshutdown()voidupdateEntry(String url, HttpCacheCASOperation casOperation) Atomically applies the given callback to processChallenge an existing cache entry under a given key.
-
Field Details
-
entries
-
morque
-
resources
-
active
-
-
Constructor Details
-
ManagedHttpCacheStorage
-
-
Method Details
-
ensureValidState
private void ensureValidState() -
keepResourceReference
-
putEntry
Description 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:
ResourceIOException
-
getEntry
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:
ResourceIOException
-
removeEntry
Description copied from interface:HttpCacheStorageDeletes/invalidates/removes any cache entries currently stored under the given key.- Specified by:
removeEntryin interfaceHttpCacheStorage- Parameters:
url-- Throws:
ResourceIOException
-
updateEntry
Description copied from interface:HttpCacheStorageAtomically applies the given callback to processChallenge an existing cache entry under a given key.- Specified by:
updateEntryin interfaceHttpCacheStorage- Parameters:
url- indicates which entry to modifycasOperation- the CAS operation to perform.- Throws:
ResourceIOException
-
getEntries
Description copied from interface:HttpCacheStorageRetrieves multiple cache entries stored under the given keys. Some implementations may use a single bulk operation to do the retrieval.- Specified by:
getEntriesin interfaceHttpCacheStorage- Parameters:
keys- cache keys- Returns:
- an map of
HttpCacheEntrys. - Throws:
ResourceIOException
-
cleanResources
public void cleanResources() -
shutdown
public void shutdown() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isActive
public boolean isActive()Check if the cache is still active and has not shut down.- Returns:
trueif the cache is active, otherwise returnfalse.- Since:
- 5.2
-
compareAndSet
private boolean compareAndSet()
-