Package: org.codehaus.groovy.runtime.memoize

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

- org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache

- All Implemented Interfaces and Traits:
    EvictableCache, Serializable

      @ThreadSafe
      public final class UnlimitedConcurrentCache<K, V>
      extends Object
      implements EvictableCache, Serializable

  A cache backed by a ConcurrentHashMap

- - ### Constructor Summary

    Constructors
    Constructor and description
    `UnlimitedConcurrentCache()` Constructs a cache with unlimited size
    `UnlimitedConcurrentCache(int initialCapacity)` Constructs a cache with unlimited size and set its initial capacity
    `UnlimitedConcurrentCache(Map<? extends K, ? extends V> m)` Constructs a cache and initialize the cache with the specified map

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `cleanUpNullReferences()` Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.
    `` | `public Map<K, V>` | `clearAll()` Clear the cache
    `` | `public boolean` | `containsKey(Object key)` Determines if the cache contains an entry for the specified key.
    `` | `public boolean` | `containsValue(Object value)` Determines whether the cache contains the specified stored value.
    `` | `public Set<Entry<K, V>>` | `entrySet()` Returns a live view of the cache entries.
    `` | `public V` | `get(Object key)` Gets a value from the cache
    `` | `public V` | `getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider)` Try to get the value from cache.
    `` | `public boolean` | `isEmpty()` Returns whether the cache currently holds no entries.
    `` | `public Set<K>` | `keySet()` Returns a live view of the keys in this cache.
    `` | `public Set<K>` | `keys()` Get all keys associated to cached values
    `` | `public V` | `put(K key, V value)` Associates the specified value with the specified key in the cache.
    `` | `public void` | `putAll(Map<? extends K, ? extends V> m)` Copies all mappings from the supplied map into this cache.
    `` | `public V` | `remove(Object key)` Remove the cached value by the key
    `` | `public int` | `size()` Get the size of the cache
    `` | `public Collection<V>` | `values()` Get all cached values

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public UnlimitedConcurrentCache()

      Constructs a cache with unlimited size

    - #### public UnlimitedConcurrentCache(int initialCapacity)

      Constructs a cache with unlimited size and set its initial capacity

      Parameters:
        `initialCapacity` - the initial capacity

    - #### public UnlimitedConcurrentCache(Map<? extends K, ? extends V> m)

      Constructs a cache and initialize the cache with the specified map

      Parameters:
        `m` - the map to initialize the cache

  - ### Method Detail

    - #### public void cleanUpNullReferences()

      Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.

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

      Clear the cache

      Returns:
        returns the content of the cleared map

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

      Determines if the cache contains an entry for the specified key.

      Parameters:
        `key` - key whose presence in this cache is to be tested.
      Returns:
        true if the cache contains a mapping for the specified key

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

      Determines whether the cache contains the specified stored value.

      Parameters:
        `value` - the value whose presence should be tested
      Returns:
        `true` if the cache contains the value

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

      Returns a live view of the cache entries.

      Returns:
        the cache entries

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

      Gets a value from the cache

      Parameters:
        `key` - the key whose associated value is to be returned
      Returns:
        the value, or null, if it does not exist.

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

      Try to get the value from cache. If not found, create the value by MemoizeCache.ValueProvider and put it into the cache, at last return the value.

      Parameters:
        `key` - the key to look up
        `valueProvider` - provide the value if the associated value not found
      Returns:
        the cached or newly created value

    - #### public boolean isEmpty()

      Returns whether the cache currently holds no entries.

      Returns:
        `true` if the cache is empty

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

      Returns a live view of the keys in this cache.

      Returns:
        the cache keys

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

      Get all keys associated to cached values

      Returns:
        all keys

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

      Associates the specified value with the specified key in the cache.

      Parameters:
        `key` - key with which the specified value is to be associated
        `value` - value to be associated with the specified key
      Returns:
        null, or the old value if the key associated with the specified key.

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

      Copies all mappings from the supplied map into this cache.

      Parameters:
        `m` - the mappings to copy

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

      Remove the cached value by the key

      Parameters:
        `key` - the key whose mapping should be removed
      Returns:
        returns the removed value

    - #### public int size()

      Get the size of the cache

      Returns:
        the size of the cache

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

      Get all cached values

      Returns:
        all cached values