Groovy Documentation

org.codehaus.groovy.runtime.memoize
[Java] Class Memoize

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

public abstract class Memoize
extends java.lang.Object

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

Authors:
Vaclav Pech


Method Summary
static Closure buildMemoizeFunction(MemoizeCache cache, Closure closure)

Creates a new closure delegating to the supplied one and memoizing all return values by the arguments.

static Closure buildSoftReferenceMemoizeFunction(int protectedCacheSize, MemoizeCache cache, Closure 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
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

buildMemoizeFunction

public static Closure buildMemoizeFunction(MemoizeCache cache, Closure 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


buildSoftReferenceMemoizeFunction

public static Closure buildSoftReferenceMemoizeFunction(int protectedCacheSize, MemoizeCache cache, Closure 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


 

Groovy Documentation