Top Description Inners Methods
org.codehaus.groovy.runtime.memoize

public Interface MemoizeCache<K, V>

Known Direct Subinterfaces
org.codehaus.groovy.runtime.memoize.EvictableCache
Known Direct Implementers
org.codehaus.groovy.runtime.memoize.LRUCache
Type Parameters
<K>
type of the keys
<V>
type of the values

Represents a memoize cache with its essential methods

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
MemoizeCache.ValueProvider<
type of the key
K
,
type of the value
V
>

Represents a provider used to create value

Method Summary

Modifier and TypeMethod and Description
public void
cleanUpNullReferences()

Invoked when some of the held SoftReferences have been evicted by the garbage collector and so should be removed from the cache.

public V

Returns:

the value, or null, if it does not exist.
get
(K
the key whose associated value is to be returned
key
)

Gets a value from the cache

public default V

Returns:

the cached value
getAndPut
(K key, MemoizeCache.ValueProvider<? super K, ? extends V>
provide the value if the associated value not found
valueProvider
)

Try to get the value from cache.

public V

Returns:

null, or the old value if the key associated with the specified key.
put
(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

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

Method Detail

cleanUpNullReferencesback to summary
public void cleanUpNullReferences()

Invoked when some of the held SoftReferences have been evicted by the garbage collector and so should be removed from the cache. The implementation must ensure that concurrent invocations of all methods on the cache may occur from other threads and thus should protect any shared resources.

getback to summary
public V get(K key)

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.

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

Try to get the value from cache. If not found, create the value by ValueProvider and put it into the cache, at last return the value.

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

provide the value if the associated value not found

Returns:V

the cached value

putback to summary
public V put(K key, V value)

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.

org.codehaus.groovy.runtime.memoize back to summary

public Interface MemoizeCache.ValueProvider<K, V>

Annotations
@FunctionalInterface
Type Parameters
<K>
type of the key
<V>
type of the value

Represents a provider used to create value

Method Summary

Modifier and TypeMethod and Description
public V
provide(K key)

Provide the created value

Method Detail

provideback to summary
public V provide(K key)

Provide the created value