Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_DEADLINE_TIME_MILLIS
The default deadline to impose on loading elements.
|
static long |
UNLIMITED
A constant to indicate that an operation should not have a limit.
|
Constructor and Description |
---|
AsyncLoadingCache(long refreshTimeMillis) |
AsyncLoadingCache(long refreshTimeMillis,
long deadlineTimeMillis) |
AsyncLoadingCache(long refreshTimeMillis,
long deadlineTimeMillis,
long maxSize) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
long |
getMaxSize()
Get the maximum number of elements stored by the cache.
|
long |
getRefreshTimeSeconds() |
CompletableFuture<V> |
orElseGet(K key,
Supplier<CompletableFuture<V>> supplier)
If the cache does not contain an entry for
key , retrieve the value using the provided asynchronous
Supplier . |
String |
toString() |
public static final long DEFAULT_DEADLINE_TIME_MILLIS
public static final long UNLIMITED
public AsyncLoadingCache(long refreshTimeMillis)
public AsyncLoadingCache(long refreshTimeMillis, long deadlineTimeMillis)
public AsyncLoadingCache(long refreshTimeMillis, long deadlineTimeMillis, long maxSize)
@Nonnull public CompletableFuture<V> orElseGet(@Nonnull K key, @Nonnull Supplier<CompletableFuture<V>> supplier)
key
, retrieve the value using the provided asynchronous
Supplier
. If the value is not currently cached, then the Supplier
is used to load the value
asynchronously. If multiple callers ask for the same key at the same time, then they might duplicate
each other's work in that both callers will result in a future being created. Whichever future completes first
will insert its value into the cache, and all callers that then complete successfully are guaranteed to see that
object until such time as the value is expired from the cache.key
- the key in the cache to lookupsupplier
- an asynchronous operation to retrieve the desired value if the cache is emptypublic long getRefreshTimeSeconds()
public long getMaxSize()
Long.MAX_VALUE
if there
is no maximum size enforced by this cache.public void clear()