Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.memoize

public final Class LRUCache<K, V>

extends Object
implements MemoizeCache<K, V>
Class Inheritance
All Implemented Interfaces
org.codehaus.groovy.runtime.memoize.MemoizeCache
Annotations
@ThreadSafe
Imports
org.apache.groovy.util.concurrent.concurrentlinkedhashmap.ConcurrentLinkedHashMap, javax.annotation.concurrent.ThreadSafe, java.lang.ref.SoftReference, java.util.Iterator, .Map, java.util.concurrent.ConcurrentMap

A cache backed by a ConcurrentLinkedHashMap

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<K, V>

Constructor Summary

AccessConstructor and Description
public
LRUCache(final int maxCacheSize)

Method Summary

Modifier and TypeMethod and Description
public void
cleanUpNullReferences()

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.cleanUpNullReferences.

Remove all entries holding SoftReferences to gc-evicted objects.
public V
get(final K
the key whose associated value is to be returned
key
)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.get.

Gets a value from the cache
public V
getAndPut(K key, MemoizeCache.ValueProvider<? super K, ? extends V>
provide the value if the associated value not found
valueProvider
)

Overrides default org.codehaus.groovy.runtime.memoize.MemoizeCache.getAndPut.

Try to get the value from cache.
public V
put(final K
key with which the specified value is to be associated
key
,
final V
value to be associated with the specified key
value
)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.put.

Associates the specified value with the specified key in the cache.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private final ConcurrentMap<K, V> map

Constructor Detail

LRUCacheback to summary
public LRUCache(final int maxCacheSize)

Method Detail

cleanUpNullReferencesback to summary
public void cleanUpNullReferences()

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.cleanUpNullReferences.

Remove all entries holding SoftReferences to gc-evicted objects.

getback to summary
public V get(final K key)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.get.

Doc from org.codehaus.groovy.runtime.memoize.MemoizeCache.get.

Gets a value from the cache

Parameters
key:K

the key whose associated value is to be returned

Returns:V

the value, or null, if it does not exist.

Annotations
@Override
getAndPutback to summary
public V getAndPut(K key, MemoizeCache.ValueProvider<? super K, ? extends V> valueProvider)

Overrides default org.codehaus.groovy.runtime.memoize.MemoizeCache.getAndPut.

Try to get the value from cache. If not found, create the value by MemoizeCache.ValueProvider and put it into the cache, at last return the value. The operation is completed atomically.

Parameters
valueProvider:MemoizeCache.ValueProvider<? super K, ? extends V>

provide the value if the associated value not found

Returns:V

Doc from org.codehaus.groovy.runtime.memoize.MemoizeCache.getAndPut.

the cached value

Annotations
@Override
putback to summary
public V put(final K key, final V value)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.put.

Doc from org.codehaus.groovy.runtime.memoize.MemoizeCache.put.

Associates the specified value with the specified key in the cache.

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

null, or the old value if the key associated with the specified key.

Annotations
@Override