Package: org.codehaus.groovy.runtime.memoize

## [Java] Class StampedCommonCache<K, V>

- org.codehaus.groovy.runtime.memoize.StampedCommonCache

- All Implemented Interfaces and Traits:
    FlexibleCache, ValueConvertable, Serializable

      @ThreadSafe
      public class StampedCommonCache<K, V>
      extends Object
      implements FlexibleCache, ValueConvertable, Serializable

  Represents a simple key-value cache, which is thread safe and backed by a Map instance. StampedCommonCache has better performance than ConcurrentCommonCache, but it is not reentrant, in other words, it may cause deadlock if getAndPut(Object, MemoizeCache.ValueProvider) or getAndPut(Object, MemoizeCache.ValueProvider, boolean) is called recursively: readlock -> upgrade to writelock -> readlock (fails to get and waits forever)

  Type Parameters:
    `K` - type of the keys
    `V` - type of the values
  Since:
    3.0.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `StampedCommonCache()` Constructs a cache with unlimited size
    `StampedCommonCache(int initialCapacity, int maxSize, EvictionStrategy evictionStrategy)` Constructs a cache with limited size
    `StampedCommonCache(int initialCapacity, int maxSize)` Constructs an LRU cache with the specified initial capacity and max size.
    `StampedCommonCache(int maxSize)` Constructs an LRU cache with the default initial capacity(16)
    `StampedCommonCache(Map<K, V> map)` Constructs a cache backed by the specified Map instance

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `cleanUpNullReferences()` {@inheritDoc}
    `` | `public Map<K, V>` | `clearAll()` {@inheritDoc}
    `` | `public boolean` | `containsKey(Object key)` {@inheritDoc}
    `` | `public boolean` | `containsValue(Object value)`
    `` | `public Object` | `convertValue(V value)` {@inheritDoc}
    `` | `public Set<Entry<K, V>>` | `entrySet()`
    `` | `public V` | `get(Object key)` {@inheritDoc}
    `` | `public V` | `getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider)` {@inheritDoc}
    `` | `public V` | `getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider, boolean shouldCache)`
    `` | `public boolean` | `isEmpty()`
    `` | `public Set<K>` | `keySet()`
    `` | `public Set<K>` | `keys()` {@inheritDoc}
    `` | `public V` | `put(K key, V value)` {@inheritDoc}
    `` | `public void` | `putAll(Map<? extends K, ? extends V> m)`
    `` | `public V` | `remove(Object key)` {@inheritDoc}
    `` | `public int` | `size()` {@inheritDoc}
    `` | `public Collection<V>` | `values()` {@inheritDoc}

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### public StampedCommonCache()

      Constructs a cache with unlimited size

    - #### public StampedCommonCache(int initialCapacity, int maxSize, 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

    - #### public StampedCommonCache(int initialCapacity, int maxSize)

      Constructs an 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

    - #### public StampedCommonCache(int maxSize)

      Constructs an LRU cache with the default initial capacity(16)

      Parameters:
        `maxSize` - max size of the LRU cache
      See Also:
        StampedCommonCache(int, int)

    - #### public StampedCommonCache(Map<K, V> map)

      Constructs a cache backed by the specified Map instance

      Parameters:
        `map` - the Map instance

  - ### Method Detail

    - #### @Override
      public void cleanUpNullReferences()

      {@inheritDoc}

    - #### @Override
      public Map<K, V> clearAll()

      {@inheritDoc}

    - #### @Override
      public boolean containsKey(Object key)

      {@inheritDoc}

    - #### @Override
      public boolean containsValue(Object value)

    - #### @Override
      public Object convertValue(V value)

      {@inheritDoc}

    - #### @Override
      public Set<Entry<K, V>> entrySet()

    - #### @Override
      public V get(Object key)

      {@inheritDoc}

    - #### @Override
      public V getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider)

      {@inheritDoc}

    - #### @Override
      public V getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider, boolean shouldCache)

    - #### @Override
      public boolean isEmpty()

    - #### @Override
      public Set<K> keySet()

    - #### @Override
      public Set<K> keys()

      {@inheritDoc}

    - #### @Override
      public V put(K key, V value)

      {@inheritDoc}

    - #### @Override
      public void putAll(Map<? extends K, ? extends V> m)

    - #### @Override
      public V remove(Object key)

      {@inheritDoc}

    - #### @Override
      public int size()

      {@inheritDoc}

    - #### @Override
      public Collection<V> values()

      {@inheritDoc}