public static < V > Closure < V > buildSoftReferenceMemoizeFunction ( final int protectedCacheSize , final MemoizeCache < Object , SoftReference < Object > > cache , final Closure < V > closure ) { final ProtectionStorage lruProtectionStorage = protectedCacheSize > 0 ? new LRUProtectionStorage ( protectedCacheSize ) : new NullProtectionStorage ( ) ; // Nothing should be done when no elements need protection against eviction final ReferenceQueue queue = new ReferenceQueue ( ) ; return new SoftReferenceMemoizeFunction < V > ( cache , closure , lruProtectionStorage , queue ) ; }
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 .