Class Cache<K,V>
java.lang.Object
nl.colorize.util.Cache<K,V>
Data structure for key/value pairs, where the value for each key is based on
an underlying compute function. The cache is lazy: values are only computed
when first requested. If the cache capacity has been exceeded, the oldest
values are removed. Note that "oldest" means the values that were least
recently *calculated*, not the values that were least recently *accessed*.
Instances of this class are thread-safe, it is safe to access the cache from different threads.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> Cache <K, V> Creates a lookup table based on the specified function.static <K,V> Cache <K, V> Creates a lookup table based on the specified function.Returns the value mapped to the specified key.voidForgets all cached key/value pairs in this cache.voidinvalidate(K key) Forgets a cached key/value pairs in this cache.protected booleanReturns true if the value for the specified key is currently cached, and false if the value still needs to be computed.voidprecompute(Iterable<K> keys) Precomputes the values for the specified keys, so the cached values are used when the key/value pairs are retrieved at a later time.voidprecompute(K key) Precomputes the value for the specified key, so the cached value is used when the key/value pair is retrieved at a later time.toString()
-
Method Details
-
get
-
precompute
Precomputes the value for the specified key, so the cached value is used when the key/value pair is retrieved at a later time. -
precompute
-
invalidate
Forgets a cached key/value pairs in this cache. If the key/value pair was not yet computed this method does nothing. -
invalidate
public void invalidate()Forgets all cached key/value pairs in this cache. -
isCached
Returns true if the value for the specified key is currently cached, and false if the value still needs to be computed. -
toString
-
from
-
from
-