Package io.fluxcapacitor.common
Interface MemoizingSupplier<T>
- Type Parameters:
T
- the result type
- All Superinterfaces:
Supplier<T>
- All Known Implementing Classes:
DefaultMemoizingSupplier
A
Supplier
that memoizes (caches) the result of a single computation.
The first time the supplier is called, the result is stored and reused for all subsequent calls until cleared.
Instances of this interface are typically created using:
io.fluxcapacitor.javaclient.common.ClientUtils#memoize(Supplier)
MemoizingSupplier<Config> configSupplier = ClientUtils.memoize(this::loadConfig);
Config config = configSupplier.get(); // computes and caches
boolean cached = configSupplier.isCached(); // true
configSupplier.clear(); // clears the cached value
Time-bound memoization is also supported:
MemoizingSupplier<Token> tokenSupplier =
ClientUtils.memoize(this::fetchToken, Duration.ofMinutes(15));
-
Method Summary
-
Method Details
-
isCached
boolean isCached()Returns whether this supplier has already cached a value. -
clear
void clear()Clears the cached value, forcing the next call to recompute.
-