Package io.fluxcapacitor.common
Class DefaultMemoizingFunction<K,V>
java.lang.Object
io.fluxcapacitor.common.DefaultMemoizingFunction<K,V>
- Type Parameters:
K
- the type of input keysV
- the type of values produced by applying the delegate function
- All Implemented Interfaces:
MemoizingFunction<K,
,V> Function<K,
V>
A default implementation of the
MemoizingFunction
interface that provides caching functionality for computed
function results. The results are cached by key, and can be optionally configured with a time-based expiration
policy.
This class uses a ConcurrentHashMap
internally for thread-safe storage of cached entries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all cached values from this function.void
Applies the given consumer to all currently cached values.boolean
Checks if the given key has a cached value.Removes and returns the cached result for the given key, if present.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.MemoizingFunction
compose
-
Constructor Details
-
DefaultMemoizingFunction
-
-
Method Details
-
apply
-
clear
public void clear()Description copied from interface:MemoizingFunction
Removes all cached values from this function.- Specified by:
clear
in interfaceMemoizingFunction<K,
V>
-
remove
Description copied from interface:MemoizingFunction
Removes and returns the cached result for the given key, if present.- Specified by:
remove
in interfaceMemoizingFunction<K,
V> - Parameters:
key
- the key whose cached result should be removed- Returns:
- the previously cached value, or
null
if not present
-
isCached
Description copied from interface:MemoizingFunction
Checks if the given key has a cached value.- Specified by:
isCached
in interfaceMemoizingFunction<K,
V> - Parameters:
key
- the key to test- Returns:
true
if the value is cached, otherwisefalse
-
forEach
Description copied from interface:MemoizingFunction
Applies the given consumer to all currently cached values.- Specified by:
forEach
in interfaceMemoizingFunction<K,
V> - Parameters:
consumer
- a consumer to operate on cached values
-