Class ValueCache
The cache will return a CompletableFuture for your value. If the value was already present, this future may already be completed. If another caller has already asked for this value and is calculating it, you may receive the future they also have, thus piggy-backing on the ongoing calculation. If no suitable value or ongoing fetch attempt is in the cache, then your fetch function will be invoked to create a new value.
There are three important rules for using this cache: 1. Your params object P
must be immutable, and suitable as a map key, and contain everything needed for fetching. 2. Your
fetch f(P): V function must be a pure function of P. It will be stored, and must not
leak references to other objects outside of P. It is recommended to use static functions for f(P)
to ensure this rule is satisfied.
Notes. It is not expected that subsequent invocations of f(P) return the same values.
Values will be removed from the cache after one minute if not used again. This can be changed
with system property MAX_AGE_SYSPROP_KEY, specified in milliseconds.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
MAX_AGE_SYSPROP_KEY
-
MAX_AGE
public static final long MAX_AGE
-
-
Constructor Details
-
ValueCache
-
-
Method Details
-
getValue
public <P,V> CompletableFuture<V> getValue(P params, Function<P, V> fetchFunction, long maxAge, TimeUnit timeUnit) -
invalidateValue
public <P> void invalidateValue(P params)
-