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:
njt
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Return true if the cache already contains a value for the provided key.
    io.vertx.core.Future<V>
    get(K key, Callable<io.vertx.core.Future<V>> loader)
    Get an item from the cache, returning a Future in case the item is not already there.
    Get an immutable view of the keys currently in the backing map.
    void
    put(K key, V value)
    Associates value with key in this cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AsyncLoadingCache

      public AsyncLoadingCache(Function<V,Long> getExpiry)
      Constructor.
      Parameters:
      getExpiry - Function to extract the expiry time (in ms since epoch) from a V type.
  • Method Details

    • 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, 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<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.