Class CaffeineLRUSoftCache<K,​V>

  • All Implemented Interfaces:
    com.github.benmanes.caffeine.cache.RemovalListener<K,​V>, Serializable, Map<K,​V>, org.apache.camel.support.LRUCache<K,​V>

    public class CaffeineLRUSoftCache<K,​V>
    extends CaffeineLRUCache<K,​V>
    A cache that uses a near optional LRU Cache using SoftReference.

    The Cache is implemented by Caffeine which provides an efficient cache.

    This implementation uses SoftReference for stored values in the cache, to support the JVM when it wants to reclaim objects when it's running out of memory. Therefore this implementation does not support all the Map methods.

    Only methods below should be used:

    • containsKey - To determine if the key is in the cache and refers to a value
    • entrySet - To return a set of all the entries (as key/value pairs)
    • get - To get a value from the cache
    • isEmpty - To determine if the cache contains any values
    • keySet - To return a set of the current keys which refers to a value
    • put - To add a value to the cache
    • putAll - To add values to the cache
    • remove - To remove a value from the cache by its key
    • size - To get the current size
    • values - To return a copy of all the value in a list

    The CaffeineLRUCache.containsValue(Object) method should not be used as it's not adjusted to check for the existence of a value without catering for the soft references.

    Notice that if the JVM reclaims memory, the content of this cache may be garbage collected without any eviction notifications.

    Use LRUCacheFactory to create a new instance (do not use the constructor).

    See Also:
    LRUCacheFactory, CaffeineLRUCache, CaffeineLRUWeakCache, Serialized Form
    • Constructor Detail

      • CaffeineLRUSoftCache

        public CaffeineLRUSoftCache​(int maximumCacheSize)
      • CaffeineLRUSoftCache

        public CaffeineLRUSoftCache​(int initialCapacity,
                                    int maximumCacheSize)
      • CaffeineLRUSoftCache

        public CaffeineLRUSoftCache​(int initialCapacity,
                                    int maximumCacheSize,
                                    boolean stopOnEviction)