Package io.fluxcapacitor.common
Class DefaultMemoizingSupplier<T>
java.lang.Object
io.fluxcapacitor.common.DefaultMemoizingSupplier<T>
- Type Parameters:
T
- the type of the value supplied and memoized
- All Implemented Interfaces:
MemoizingSupplier<T>
,Supplier<T>
A default implementation of the
MemoizingSupplier
interface that memoizes (caches)
the result of a computation performed by a supplied Supplier
.
The result is computed the first time get()
is called and then cached for subsequent calls
until explicitly cleared with clear()
. This implementation also supports an optional expiration
duration for the cached value.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMemoizingSupplier
(Supplier<T> delegate) DefaultMemoizingSupplier
(Supplier<T> delegate, Duration lifespan, Clock clock) -
Method Summary
-
Constructor Details
-
DefaultMemoizingSupplier
-
DefaultMemoizingSupplier
-
-
Method Details
-
get
-
isCached
public boolean isCached()Description copied from interface:MemoizingSupplier
Returns whether this supplier has already cached a value.- Specified by:
isCached
in interfaceMemoizingSupplier<T>
-
clear
public void clear()Description copied from interface:MemoizingSupplier
Clears the cached value, forcing the next call to recompute.- Specified by:
clear
in interfaceMemoizingSupplier<T>
-