Package com.apple.foundationdb.record
Class AsyncLoadingCache<K,V>
- java.lang.Object
-
- com.apple.foundationdb.record.AsyncLoadingCache<K,V>
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description AsyncLoadingCache(long refreshTimeMillis)
AsyncLoadingCache(long refreshTimeMillis, long deadlineTimeMillis)
AsyncLoadingCache(long refreshTimeMillis, long deadlineTimeMillis, long maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 forkey
, retrieve the value using the provided asynchronousSupplier
.String
toString()
-
-
-
Field Detail
-
DEFAULT_DEADLINE_TIME_MILLIS
public static final long DEFAULT_DEADLINE_TIME_MILLIS
The default deadline to impose on loading elements.- See Also:
- Constant Field Values
-
UNLIMITED
public static final long UNLIMITED
A constant to indicate that an operation should not have a limit. For example, this can be provided to the cache as the deadline time or the max size to indicate that no deadline should be imposed on futures loading entries into the cache or that there should not be a maximum number of cached elements.- See Also:
- Constant Field Values
-
-
Method Detail
-
orElseGet
@Nonnull public CompletableFuture<V> orElseGet(@Nonnull K key, @Nonnull Supplier<CompletableFuture<V>> supplier)
If the cache does not contain an entry forkey
, retrieve the value using the provided asynchronousSupplier
. If the value is not currently cached, then theSupplier
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.- Parameters:
key
- the key in the cache to lookupsupplier
- an asynchronous operation to retrieve the desired value if the cache is empty- Returns:
- a future containing either the cached value or the result from the supplier
-
getRefreshTimeSeconds
public long getRefreshTimeSeconds()
-
getMaxSize
public long getMaxSize()
Get the maximum number of elements stored by the cache. This will returnLong.MAX_VALUE
if there is no maximum size enforced by this cache.- Returns:
- the maximum number of elements stored by the cache
-
clear
public void clear()
-
-