Class LRUCache<K,V>
java.lang.Object
org.codehaus.groovy.runtime.memoize.LRUCache<K,V>
- All Implemented Interfaces:
MemoizeCache<K,V>
A cache backed by a ConcurrentLinkedHashMap
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.MemoizeCache
MemoizeCache.ValueProvider<K,V> -
Constructor Summary
ConstructorsConstructorDescriptionLRUCache(int maxCacheSize) Creates an LRU cache with the supplied maximum size. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemove all entries holding SoftReferences to gc-evicted objects.Returns the value associated with the supplied key.getAndPut(K key, MemoizeCache.ValueProvider<? super K, ? extends V> valueProvider) Try to get the value from cache.Associates the specified value with the specified key in this cache.
-
Constructor Details
-
LRUCache
public LRUCache(int maxCacheSize) Creates an LRU cache with the supplied maximum size.- Parameters:
maxCacheSize- the maximum number of cached entries
-
-
Method Details
-
put
Associates the specified value with the specified key in this cache.- Specified by:
putin interfaceMemoizeCache<K,V> - Parameters:
key- the key with which the value is to be associatedvalue- the value to cache- Returns:
- the previous value associated with
key, ornull
-
get
Returns the value associated with the supplied key.- Specified by:
getin interfaceMemoizeCache<K,V> - Parameters:
key- the key to look up- Returns:
- the cached value, or
nullif none is present
-
getAndPut
Try to get the value from cache. If not found, create the value byMemoizeCache.ValueProviderand put it into the cache, at last return the value. The operation is completed atomically.- Specified by:
getAndPutin interfaceMemoizeCache<K,V> - Parameters:
key- the key to look upvalueProvider- provide the value if the associated value not found- Returns:
- the cached or newly created value
-
cleanUpNullReferences
public void cleanUpNullReferences()Remove all entries holding SoftReferences to gc-evicted objects.- Specified by:
cleanUpNullReferencesin interfaceMemoizeCache<K,V>
-