Package org.codehaus.groovy.runtime.memoize

# Interface FlexibleCache<K,V>

All Superinterfaces:
  `EvictableCache<K,V>`, `Map<K,V>`, `MemoizeCache<K,V>`

All Known Implementing Classes:
  `CommonCache`, `ConcurrentCommonCache`, `ConcurrentSoftCache`, `StampedCommonCache`

public interface FlexibleCache<K,V> extends EvictableCache<K,V>
An EvictableCache supporting a getAndPut variant with additional control over caching.

Since:
  5.0.0

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.EvictableCache

  `EvictableCache.Action<K,V,R>, EvictableCache.EvictionStrategy`

  ## Nested classes/interfaces inherited from interface java.util.Map

  `Map.Entry<K extends Object,V extends Object>`

  ## Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.MemoizeCache

  `MemoizeCache.ValueProvider<K,V>`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `V`
  `getAndPut(K key, MemoizeCache.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.

  ### Methods inherited from interface org.codehaus.groovy.runtime.memoize.EvictableCache

  `clear, clearAll, containsKey, keys, remove, size, values`

  ### Methods inherited from interface java.util.Map

  `compute, computeIfAbsent, computeIfPresent, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll`

  ### Methods inherited from interface org.codehaus.groovy.runtime.memoize.MemoizeCache

  `cleanUpNullReferences, get, getAndPut, put`

- ## Method Details

  - ### getAndPut

    V getAndPut(K key, MemoizeCache.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