Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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, 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 memoize
- 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 memoize
- The closure's return type