Class 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

    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 Detail

      • entries

        private final CacheMap entries
      • morque

        private final java.lang.ref.ReferenceQueue<HttpCacheEntry> morque
      • active

        private final java.util.concurrent.atomic.AtomicBoolean active
    • Constructor Detail

      • ManagedHttpCacheStorage

        public ManagedHttpCacheStorage​(CacheConfig config)
    • Method Detail

      • ensureValidState

        private void ensureValidState()
      • keepResourceReference

        private void keepResourceReference​(HttpCacheEntry entry)
      • cleanResources

        public void cleanResources()
      • shutdown

        public void shutdown()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • isActive

        public boolean isActive()
        Check if the cache is still active and has not shut down.
        Returns:
        true if the cache is active, otherwise return false.
        Since:
        5.2
      • compareAndSet

        private boolean compareAndSet()