Class DefaultMemoizingFunction<K,V>
java.lang.Object
io.fluxzero.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 TypeMethodDescriptionvoidclear()Removes all cached values from this function.voidApplies the given consumer to all currently cached values.booleanChecks if the given key has a cached value.Removes and returns the cached result for the given key, if present.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MemoizingFunction
compose
-
Constructor Details
-
DefaultMemoizingFunction
-
-
Method Details
-
apply
-
clear
public void clear()Description copied from interface:MemoizingFunctionRemoves all cached values from this function.- Specified by:
clearin interfaceMemoizingFunction<K,V>
-
remove
Description copied from interface:MemoizingFunctionRemoves and returns the cached result for the given key, if present.- Specified by:
removein interfaceMemoizingFunction<K,V> - Parameters:
key- the key whose cached result should be removed- Returns:
- the previously cached value, or
nullif not present
-
isCached
Description copied from interface:MemoizingFunctionChecks if the given key has a cached value.- Specified by:
isCachedin interfaceMemoizingFunction<K,V> - Parameters:
key- the key to test- Returns:
trueif the value is cached, otherwisefalse
-
forEach
Description copied from interface:MemoizingFunctionApplies the given consumer to all currently cached values.- Specified by:
forEachin interfaceMemoizingFunction<K,V> - Parameters:
consumer- a consumer to operate on cached values
-