Package: org.codehaus.groovy.runtime.memoize

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

- org.codehaus.groovy.runtime.memoize.LRUCache

- All Implemented Interfaces and Traits:
    MemoizeCache

      @ThreadSafe
      public final class LRUCache<K, V>
      extends Object
      implements MemoizeCache

  A cache backed by a ConcurrentLinkedHashMap

- - ### Constructor Summary

    Constructors
    Constructor and description
    `LRUCache(int maxCacheSize)` Creates an LRU cache with the supplied maximum size.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `cleanUpNullReferences()` Remove all entries holding SoftReferences to gc-evicted objects.
    `` | `public V` | `get(K key)` Returns the value associated with the supplied key.
    `` | `public V` | `getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider)` Try to get the value from cache.
    `` | `public V` | `put(K key, V value)` Associates the specified value with the specified key in this cache.

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public LRUCache(int maxCacheSize)

      Creates an LRU cache with the supplied maximum size.

      Parameters:
        `maxCacheSize` - the maximum number of cached entries

  - ### Method Detail

    - #### public void cleanUpNullReferences()

      Remove all entries holding SoftReferences to gc-evicted objects.

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

      Returns the value associated with the supplied key.

      Parameters:
        `key` - the key to look up
      Returns:
        the cached value, or `null` if none is present

    - #### 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. The operation is completed atomically.

      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 V put(K key, V value)

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

      Parameters:
        `key` - the key with which the value is to be associated
        `value` - the value to cache
      Returns:
        the previous value associated with `key`, or `null`