Package: org.codehaus.groovy.runtime.memoize

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

- org.codehaus.groovy.runtime.memoize.CommonCache

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

      public class CommonCache
      extends Object

  Represents a simple key-value cache, which is NOT thread safe and backed by a Map instance

  Parameters:
    `` - type of the keys
    `` - type of the values
  Since:
    2.5.0

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static int` | `DEFAULT_INITIAL_CAPACITY` | The default initial capacity
    `static float` | `DEFAULT_LOAD_FACTOR` | The default load factor

  - ### Constructor Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

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

- - ### Field Detail

    - #### public static final int DEFAULT_INITIAL_CAPACITY

      The default initial capacity

    - #### public static final float DEFAULT_LOAD_FACTOR

      The default load factor

  - ### Constructor Detail

    - #### public CommonCache()

      Constructs a cache with unlimited size

    - #### public CommonCache(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 org.codehaus.groovy.runtime.memoize.EvictableCache.EvictionStrategy

    - #### public CommonCache(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

    - #### public CommonCache(int maxSize)

      Constructs a LRU cache with the default initial capacity

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

    - #### public CommonCache(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 void clear()

      Clear the cache

      See Also:
        clearAll()

    - #### @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}

    - #### 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 String toString()

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

      {@inheritDoc}