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.
Type Params | Return Type | Name and description |
---|---|---|
<V> |
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. |
<V> |
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. |
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.
cache
- A map to hold memoized return valuesclosure
- The closure to memoizeV
- The closure's return typeCreates 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.
protectedCacheSize
- The number of hard references to keep in order to prevent some (LRU) memoized return values from evictioncache
- A map to hold memoized return valuesclosure
- The closure to memoizeV
- The closure's return type