Package: org.codehaus.groovy.runtime.memoize

## [Java] Interface FlexibleCache<K, V>

- org.codehaus.groovy.runtime.memoize.MemoizeCache

- All Superinterfaces:
    EvictableCache, MemoizeCache

      public interface FlexibleCache<K, V>
      extends EvictableCache

  An EvictableCache supporting a getAndPut variant with additional control over caching.

  Since:
    5.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public V` | `getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider, boolean shouldCache)` Returns the value associated with `key`, creating it with the supplied provider when necessary and optionally caching the result.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface EvictableCache` | `clear, clearAll, containsKey, keys, remove, size, values`
    `interface MemoizeCache` | `cleanUpNullReferences, get, getAndPut, put`

- - ### Method Detail

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

      Returns the value associated with `key`, creating it with the supplied provider when necessary and optionally caching the result.

      Parameters:
        `key` - the key to look up
        `valueProvider` - supplies a value when the key is not cached
        `shouldCache` - whether a newly created value should be stored
      Returns:
        the cached or newly created value