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.

public class AsyncLoadingCache<K,V> extends Object
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
  • Constructor Details

    • AsyncLoadingCache

      public AsyncLoadingCache()
      Constructor.
  • Method Details

    • entry

      public AsyncLoadingCache.TimedObject<V> entry(V value, long expiry)
      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

      public boolean containsKey(K key)
      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

      public void put(K key, AsyncLoadingCache.TimedObject<V> value)
      Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value. p>Prefer get(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

      public Set<K> 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.