Package: org.codehaus.groovy.runtime.memoize

## [Java] Class Memoize

- org.codehaus.groovy.runtime.memoize.Memoize

- Implements memoize for Closures. It is supposed to be used by the Closure class itself to implement the memoize() family of methods.

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `static 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 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.

  - ### Inherited Methods Summary

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

- - ### Method Detail

    - #### public static 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.

      Parameters:
        `cache` - A map to hold memoized return values
        `closure` - The closure to memoize
        `` - The closure's return type
      Returns:
        A new memoized closure

    - #### public static 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.

      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
        `` - The closure's return type
      Returns:
        A new memoized closure