Class ConcurrentSoftCache<K,​V>

  • Type Parameters:
    K - key type
    V - real value type
    All Implemented Interfaces:
    java.io.Serializable, java.util.Map<K,​java.lang.ref.SoftReference<V>>, EvictableCache<K,​java.lang.ref.SoftReference<V>>, MemoizeCache<K,​java.lang.ref.SoftReference<V>>, ValueConvertable<java.lang.ref.SoftReference<V>,​java.lang.Object>

    public class ConcurrentSoftCache<K,​V>
    extends ConcurrentCommonCache<K,​java.lang.ref.SoftReference<V>>
    Represents concurrent cache holding SoftReference instance as value
    See Also:
    Serialized Form
    • Constructor Detail

      • ConcurrentSoftCache

        public ConcurrentSoftCache()
        Constructs a cache with unlimited size
      • ConcurrentSoftCache

        public ConcurrentSoftCache​(int initialCapacity,
                                   int maxSize,
                                   EvictableCache.EvictionStrategy evictionStrategy)
        Constructs a cache with limited size
        Parameters:
        initialCapacity - initial capacity of the cache
        maxSize - max size of the cache
        evictionStrategy - LRU or FIFO, see EvictableCache.EvictionStrategy
      • ConcurrentSoftCache

        public ConcurrentSoftCache​(int initialCapacity,
                                   int maxSize)
        Constructs a LRU cache with the specified initial capacity and max size. The LRU cache is slower than LRUCache
        Parameters:
        initialCapacity - initial capacity of the LRU cache
        maxSize - max size of the LRU cache
      • ConcurrentSoftCache

        public ConcurrentSoftCache​(int maxSize)
        Constructs a LRU cache with the default initial capacity(16)
        Parameters:
        maxSize - max size of the LRU cache
        See Also:
        ConcurrentSoftCache(int, int)
      • ConcurrentSoftCache

        public ConcurrentSoftCache​(java.util.Map<K,​java.lang.ref.SoftReference<V>> map)
        Constructs a cache backed by the specified Map instance
        Parameters:
        map - the Map instance
    • Method Detail

      • convertValue

        public java.lang.Object convertValue​(java.lang.ref.SoftReference<V> value)
        convert the original value to the target value
        Specified by:
        convertValue in interface ValueConvertable<K,​V>
        Overrides:
        convertValue in class ConcurrentCommonCache<K,​java.lang.ref.SoftReference<V>>
        Parameters:
        value - the original value
        Returns:
        the converted value