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:
- jtalbut
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass for returned an expiry value along with the cache value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(K key) Return true if the cache already contains a value for the provided key.Factory method for cache entries.io.vertx.core.Future<V> get(K key, Callable<io.vertx.core.Future<AsyncLoadingCache.TimedObject<V>>> loader) 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.voidput(K key, AsyncLoadingCache.TimedObject<V> value) Associatesvaluewithkeyin this cache.
-
Constructor Details
-
AsyncLoadingCache
public AsyncLoadingCache()Constructor.
-
-
Method Details
-
entry
Factory method for cache entries.- Parameters:
value- The value to store in the cache.expiry- The time (ms since epoch) at which this item becomes invalid.- Returns:
- newly created TimedObject.
-
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
Associatesvaluewithkeyin 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
public io.vertx.core.Future<V> get(K key, Callable<io.vertx.core.Future<AsyncLoadingCache.TimedObject<V>>> loader) 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.
-