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

## Class BasicHttpCacheStorage

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

- All Implemented Interfaces:
    HttpCacheStorage

      @Contract(threading=SAFE)
      public class BasicHttpCacheStorage
      extends Object
      implements HttpCacheStorage

  Basic `HttpCacheStorage` implementation backed by an instance of `LinkedHashMap`. In other words, cache entries and the cached response bodies are held in-memory. This cache does NOT deallocate resources associated with the cache entries; it is intended for use with `HeapResource` and similar. This is the default cache storage backend used by `CachingHttpClients`.
  Since:
    4.1

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicHttpCacheStorage(CacheConfig config)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Map<String,HttpCacheEntry>` | `getEntries(Collection<String> keys)` Retrieves multiple cache entries stored under the given keys.
    `HttpCacheEntry` | `getEntry(String url)` Gets an entry from the cache, if it exists
    `void` | `putEntry(String url, HttpCacheEntry entry)` Places a HttpCacheEntry in the cache
    `void` | `removeEntry(String url)` Removes a HttpCacheEntry from the cache
    `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

    - #### BasicHttpCacheStorage

          public BasicHttpCacheStorage(CacheConfig config)

  - ### Method Detail

    - #### putEntry

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

      Places a HttpCacheEntry in the cache
      Specified by:
        `putEntry` in interface `HttpCacheStorage`
      Parameters:
        `url` - Url to use as the cache key
        `entry` - HttpCacheEntry to place in the cache
      Throws:
        `ResourceIOException`

    - #### getEntry

          public HttpCacheEntry getEntry(String url)
                                  throws ResourceIOException

      Gets an entry from the cache, if it exists
      Specified by:
        `getEntry` in interface `HttpCacheStorage`
      Parameters:
        `url` - Url that is the cache key
      Returns:
        HttpCacheEntry if one exists, or null for cache miss
      Throws:
        `ResourceIOException`

    - #### removeEntry

          public void removeEntry(String url)
                           throws ResourceIOException

      Removes a HttpCacheEntry from the cache
      Specified by:
        `removeEntry` in interface `HttpCacheStorage`
      Parameters:
        `url` - Url that is the cache key
      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`

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