T - Type of the value cachedpublic final class Memoizer<T>
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Memoizer<T> |
create(java.util.concurrent.Callable<T> getter,
long duration,
java.util.concurrent.TimeUnit unit)
Create a memoizer that caches the value produced by getter for a given duration.
|
T |
get()
Get or refresh and return the latest value.
|
public static <T> Memoizer<T> create(java.util.concurrent.Callable<T> getter, long duration, java.util.concurrent.TimeUnit unit)
T - type of the value produced by the gettergetter - A Callable that returns a new value. This should not throw.duration - how long we should keep the cached value before refreshing it.unit - unit of time for durationpublic T get()