Class AsyncLoadingCache<K,V>
java.lang.Object
uk.co.spudsoft.jwtvalidatorvertx.impl.AsyncLoadingCache<K,V>
- Type Parameters:
K
- The key type for the cache.V
- The value type stored in the cache.
Class backed by a Guava Cache that returns a Future for all elements whilst
still ensuring that the loader is only called once at a time per element.
- Author:
- njt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(K key) Return true if the cache already contains a value for the provided key.io.vertx.core.Future<V>
Get an item from the cache, returning a Future in case the item is not already there.keySet()
Get an immutable view of the keys currently in the backing map.void
Associatesvalue
withkey
in this cache.
-
Constructor Details
-
AsyncLoadingCache
Constructor.- Parameters:
getExpiry
- Function to extract the expiry time (in ms since epoch) from a V type.
-
-
Method Details
-
containsKey
Return true if the cache already contains a value for the provided key.- Parameters:
key
- the key to check.- Returns:
- true if the cache already contains a value for the provided key.
-
put
Associatesvalue
withkey
in this cache. If the cache previously contained a value associated withkey
, the old value is replaced byvalue
. p>Preferget(Object, Callable)
when using the conventional "if cached, return; otherwise create, cache and return" pattern.- Parameters:
key
- the key to set.value
- the value to set.
-
get
Get an item from the cache, returning a Future in case the item is not already there.- Parameters:
key
- The key for the item in the cache.loader
- Callable that actually gets the value.- Returns:
- The value returned either by this Callable or some previous instance of it.
-
keySet
Get an immutable view of the keys currently in the backing map.- Returns:
- an immutable view of the keys currently in the backing map.
-