public class RecreatingLeastRecentlyUsedCache<K,V> extends LeastRecentlyUsedCache<K,V>
A good way to use it is construction with a function which is able to recreate
the value for a given key and calling only the get(Object) method.
map| Constructor and Description |
|---|
RecreatingLeastRecentlyUsedCache(int mostRecentLimit,
FragileFunction1<V,? extends java.lang.Exception,K> recreator,
Procedure2<K,java.lang.Exception> errorHandler)
Constructor.
|
RecreatingLeastRecentlyUsedCache(int mostRecentLimit,
java.util.function.Function<K,V> recreator)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Remove all key-value pairs which are no longer available.
|
V |
get(K key)
Get the value for the given key.
|
int |
getNumRecreations()
Get the number of times the recreation function was called.
|
V |
remove(K key)
Remove a key-value pair from this cache.
|
clear, computeIfAbsent, getLeastRecentCacheDepth, getLeastRecentlyUsed, getNumGarbageCollected, getNumHits, getNumMisses, isEmpty, keys, put, sizepublic RecreatingLeastRecentlyUsedCache(int mostRecentLimit,
@NotNull
java.util.function.Function<K,V> recreator)
mostRecentLimit - maximal number of cached values, non-negativerecreator - creator for values which are currently not presentpublic RecreatingLeastRecentlyUsedCache(int mostRecentLimit,
@NotNull
FragileFunction1<V,? extends java.lang.Exception,K> recreator,
@NotNull
Procedure2<K,java.lang.Exception> errorHandler)
This allows to use an recreator which might throw an exception.
In case of exceptions obviously nothing is created, but the errorHandler
will be called with the key an exception.
mostRecentLimit - maximal number of cached values, non-negativerecreator - creator for values which are currently not presenterrorHandler - error handler for exceptions during the recreation@Nullable public V get(@NotNull K key)
LeastRecentlyUsedCacheget in class LeastRecentlyUsedCache<K,V>key - key associated with the requested valuenull when the required value was never added to this cache
or when it was garbage collected in the meantime, otherwise the cached object
associated with the given keypublic void cleanup()
LeastRecentlyUsedCachecleanup in class LeastRecentlyUsedCache<K,V>@Nullable public V remove(K key)
LeastRecentlyUsedCacheremove in class LeastRecentlyUsedCache<K,V>key - key of the key-value pairnull if the object was either never cached at all
or has been garbage collectedpublic int getNumRecreations()