org.apache.hc.client5.http.impl.cache

## Class ManagedHttpCacheStorage

- java.lang.Object
- - org.apache.hc.client5.http.impl.cache.ManagedHttpCacheStorage

- All Implemented Interfaces:
    Closeable, AutoCloseable, HttpCacheStorage

      @Contract(threading=SAFE)
      public class ManagedHttpCacheStorage
      extends Object
      implements HttpCacheStorage, 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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ManagedHttpCacheStorage(CacheConfig config)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cleanResources()`
    `void` | `close()`
    `Map<String,HttpCacheEntry>` | `getEntries(Collection<String> keys)` Retrieves multiple cache entries stored under the given keys.
    `HttpCacheEntry` | `getEntry(String url)` Retrieves the cache entry stored under the given key or null if no entry exists under that key.
    `void` | `putEntry(String url, HttpCacheEntry entry)` Store a given cache entry under the given key.
    `void` | `removeEntry(String url)` Deletes/invalidates/removes any cache entries currently stored under the given key.
    `void` | `shutdown()`
    `void` | `updateEntry(String url, HttpCacheCASOperation casOperation)` Atomically applies the given callback to processChallenge an existing cache entry under a given key.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ManagedHttpCacheStorage

          public ManagedHttpCacheStorage(CacheConfig config)

  - ### Method Detail

    - #### putEntry

          public void putEntry(String url,
                      HttpCacheEntry entry)
                        throws ResourceIOException

      Description copied from interface: `HttpCacheStorage`
      Store a given cache entry under the given key.
      Specified by:
        `putEntry` in interface `HttpCacheStorage`
      Parameters:
        `url` - where in the cache to store the entry
        `entry` - cached response to store
      Throws:
        `ResourceIOException`

    - #### getEntry

          public HttpCacheEntry getEntry(String url)
                                  throws ResourceIOException

      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 interface `HttpCacheStorage`
      Parameters:
        `url` - cache key
      Returns:
        an `HttpCacheEntry` or `null` if no entry exists
      Throws:
        `ResourceIOException`

    - #### removeEntry

          public void removeEntry(String url)
                           throws ResourceIOException

      Description copied from interface: `HttpCacheStorage`
      Deletes/invalidates/removes any cache entries currently stored under the given key.
      Specified by:
        `removeEntry` in interface `HttpCacheStorage`
      Throws:
        `ResourceIOException`

    - #### updateEntry

          public void updateEntry(String url,
                         HttpCacheCASOperation casOperation)
                           throws ResourceIOException

      Description copied from interface: `HttpCacheStorage`
      Atomically applies the given callback to processChallenge an existing cache entry under a given key.
      Specified by:
        `updateEntry` in interface `HttpCacheStorage`
      Parameters:
        `url` - indicates which entry to modify
        `casOperation` - the CAS operation to perform.
      Throws:
        `ResourceIOException`

    - #### getEntries

          public Map<String,HttpCacheEntry> getEntries(Collection<String> keys)
                                                throws ResourceIOException

      Description copied from interface: `HttpCacheStorage`
      Retrieves multiple cache entries stored under the given keys. Some implementations may use a single bulk operation to do the retrieval.
      Specified by:
        `getEntries` in interface `HttpCacheStorage`
      Parameters:
        `keys` - cache keys
      Returns:
        an map of `HttpCacheEntry`s.
      Throws:
        `ResourceIOException`

    - #### cleanResources

          public void cleanResources()

    - #### shutdown

          public void shutdown()

    - #### close

          public void close()

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.