Memoize (Groovy 5.0.8)
Description: declaration: package: org.codehaus.groovy.runtime.memoize, class: Memoize

Package org.codehaus.groovy.runtime.memoize

# Class Memoize

java.lang.Object
org.codehaus.groovy.runtime.memoize.Memoize

public abstract class Memoize extends Object
Implements memoize for Closures. It is supposed to be used by the Closure class itself to implement the memoize() family of methods.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Memoize()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <V> Closure<V>`
  `buildMemoizeFunction(MemoizeCache<Object,Object> cache, Closure<V> closure)`
  Creates a new closure delegating to the supplied one and memoizing all return values by the arguments.
  `static <V> Closure<V>`
  `buildSoftReferenceMemoizeFunction(int protectedCacheSize, MemoizeCache<Object,SoftReference<Object>> cache, Closure<V> closure)`
  Creates a new closure delegating to the supplied one and memoizing all return values by the arguments.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Memoize

    public Memoize()

- ## Method Details

  - ### buildMemoizeFunction

    public static <V> Closure<V> buildMemoizeFunction(MemoizeCache<Object,Object> cache, Closure<V> closure)
    Creates a new closure delegating to the supplied one and memoizing all return values by the arguments. The supplied cache is used to store the memoized values and it is the cache's responsibility to put limits on the cache size or implement cache eviction strategy. The LRUCache, for example, allows to set the maximum cache size constraint and implements the LRU (Last Recently Used) eviction strategy.
    Type Parameters:
      `V` - The closure's return type
    Parameters:
      `cache` - A map to hold memoized return values
      `closure` - The closure to memoize
    Returns:
      A new memoized closure

  - ### buildSoftReferenceMemoizeFunction

    public static <V> Closure<V> buildSoftReferenceMemoizeFunction(int protectedCacheSize, MemoizeCache<Object,SoftReference<Object>> cache, Closure<V> closure)
    Creates a new closure delegating to the supplied one and memoizing all return values by the arguments. The memoizing closure will use SoftReferences to remember the return values allowing the garbage collector to reclaim the memory, if needed. The supplied cache is used to store the memoized values and it is the cache's responsibility to put limits on the cache size or implement cache eviction strategy. The LRUCache, for example, allows to set the maximum cache size constraint and implements the LRU (Last Recently Used) eviction strategy. If the protectedCacheSize argument is greater than 0 an optional LRU (Last Recently Used) cache of hard references is maintained to protect recently touched memoized values against eviction by the garbage collector.
    Type Parameters:
      `V` - The closure's return type
    Parameters:
      `protectedCacheSize` - The number of hard references to keep in order to prevent some (LRU) memoized return values from eviction
      `cache` - A map to hold memoized return values
      `closure` - The closure to memoize
    Returns:
      A new memoized closure