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> |
buildMemoizeFunction(Supplier<? extends MemoizeCache<Object, Object>> cacheFactory, 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. |
<V> |
public static Closure<V> |
buildSoftReferenceMemoizeFunction(int protectedCacheSize, Supplier<? extends MemoizeCache<Object, SoftReference<Object>>> cacheFactory, 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.
A copy made by dehydrate or rehydrate calls the dehydrated or rehydrated closure and shares
the supplied cache.
cache - A map to hold memoized return valuesclosure - The closure to memoizeV - The closure's return type Creates a new closure delegating to the supplied one and memoizing all return values by the arguments.
The supplied factory creates the cache that stores the memoized values, and it is the cache's responsibility
to put limits on the cache size or implement cache eviction strategy.
A copy made by dehydrate or rehydrate calls the dehydrated or rehydrated closure and starts
with an empty cache created by the same factory, as the cached values were computed against the old owner,
delegate and this object. The factory has to be serializable for the memoized closure to be serializable.
cacheFactory - Creates the map to hold memoized return valuesclosure - The closure to memoizeV - The closure's return type 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.
A copy made by dehydrate or rehydrate calls the dehydrated or rehydrated closure and shares
the supplied cache.
The memoized values are not serialized with the memoizing closure, which is deserialized with the cache
emptied of them.
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 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 factory creates the cache that stores the memoized values, and it is the cache's responsibility
to put limits on the cache size or implement cache eviction strategy.
A copy made by dehydrate or rehydrate calls the dehydrated or rehydrated closure and starts
with an empty cache created by the same factory and the same protected cache size, as the cached values were
computed against the old owner, delegate and this object.
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 evictioncacheFactory - Creates the map to hold memoized return valuesclosure - The closure to memoizeV - The closure's return type