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

## Class EhcacheHttpCacheStorage<T>

- java.lang.Object
- - org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage<T,T>
  - - org.apache.hc.client5.http.impl.cache.ehcache.EhcacheHttpCacheStorage<T>

- All Implemented Interfaces:
    HttpCacheStorage

      public class EhcacheHttpCacheStorage<T>
      extends AbstractSerializingCacheStorage<T,T>

  This class is a storage backend for cache entries that uses the popular Ehcache cache implementation. In particular, this backend allows for spillover to disk, where the cache can be effectively larger than memory, and cached responses are paged into and out of memory from disk as needed.

  N.B. Since the Ehcache is configured ahead of time with a maximum number of cache entries, this effectively ignores the `CacheConfig.getMaxCacheEntries()` maximum cache entries} specified by a provided `CacheConfig`.

  Please refer to the Ehcache documentation for details on how to configure the Ehcache itself.

  Since:
    4.1

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EhcacheHttpCacheStorage(org.ehcache.Cache<String,T> cache, CacheConfig config, HttpCacheEntrySerializer<T> serializer)` Constructs a storage backend using the provided Ehcache with the given configuration options, but using an alternative cache entry serialization strategy.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Map<String,T>` | `bulkRestore(Collection<String> storageKeys)`
    `static EhcacheHttpCacheStorage<HttpCacheStorageEntry>` | `createObjectCache(org.ehcache.Cache<String,HttpCacheStorageEntry> cache, CacheConfig config)` Creates cache that stores `HttpCacheStorageEntry`s without direct serialization.
    `static EhcacheHttpCacheStorage<byte[]>` | `createSerializedCache(org.ehcache.Cache<String,byte[]> cache, CacheConfig config)` Creates cache that stores serialized `HttpCacheStorageEntry`s.
    `protected void` | `delete(String storageKey)`
    `protected String` | `digestToStorageKey(String key)`
    `protected T` | `getForUpdateCAS(String storageKey)`
    `protected T` | `getStorageObject(T element)`
    `protected T` | `restore(String storageKey)`
    `protected void` | `store(String storageKey, T storageObject)`
    `protected boolean` | `updateCAS(String storageKey, T oldStorageObject, T storageObject)`

    - ### Methods inherited from class org.apache.hc.client5.http.impl.cache.AbstractSerializingCacheStorage

      `getEntries, getEntry, putEntry, removeEntry, updateEntry`

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

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

- - ### Constructor Detail

    - #### EhcacheHttpCacheStorage

          public EhcacheHttpCacheStorage(org.ehcache.Cache<String,T> cache,
                                 CacheConfig config,
                                 HttpCacheEntrySerializer<T> serializer)

      Constructs a storage backend using the provided Ehcache with the given configuration options, but using an alternative cache entry serialization strategy.
      Parameters:
        `cache` - where to store cached origin responses
        `config` - cache storage configuration options - note that the setting for max object size will be ignored and should be configured in the Ehcache instead.
        `serializer` - alternative serialization mechanism

  - ### Method Detail

    - #### createObjectCache

          public static EhcacheHttpCacheStorage<HttpCacheStorageEntry> createObjectCache(org.ehcache.Cache<String,HttpCacheStorageEntry> cache,
                                                                         CacheConfig config)

      Creates cache that stores `HttpCacheStorageEntry`s without direct serialization.
      Since:
        5.0

    - #### createSerializedCache

          public static EhcacheHttpCacheStorage<byte[]> createSerializedCache(org.ehcache.Cache<String,byte[]> cache,
                                                              CacheConfig config)

      Creates cache that stores serialized `HttpCacheStorageEntry`s.
      Since:
        5.0

    - #### digestToStorageKey

          protected String digestToStorageKey(String key)

      Specified by:
        `digestToStorageKey` in class `AbstractSerializingCacheStorage<T,T>`

    - #### store

          protected void store(String storageKey,
                   T storageObject)
                        throws ResourceIOException

      Specified by:
        `store` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### restore

          protected T restore(String storageKey)
                       throws ResourceIOException

      Specified by:
        `restore` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### getForUpdateCAS

          protected T getForUpdateCAS(String storageKey)
                               throws ResourceIOException

      Specified by:
        `getForUpdateCAS` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### getStorageObject

          protected T getStorageObject(T element)
                                throws ResourceIOException

      Specified by:
        `getStorageObject` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### updateCAS

          protected boolean updateCAS(String storageKey,
                          T oldStorageObject,
                          T storageObject)
                               throws ResourceIOException

      Specified by:
        `updateCAS` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### delete

          protected void delete(String storageKey)
                         throws ResourceIOException

      Specified by:
        `delete` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

    - #### bulkRestore

          protected Map<String,T> bulkRestore(Collection<String> storageKeys)
                                       throws ResourceIOException

      Specified by:
        `bulkRestore` in class `AbstractSerializingCacheStorage<T,T>`
      Throws:
        `ResourceIOException`

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