Class Cache<K,V>

java.lang.Object
org.apache.juneau.internal.Cache<K,V>
Type Parameters:
K - The key type.
V - The value type.

public class Cache<K,V> extends Object
Simple in-memory cache of objects.

Essentially just a wrapper around a ConcurrentHashMap.

See Also:
  • Constructor Details

    • Cache

      protected Cache(Cache.Builder<K,V> builder)
      Constructor
      Parameters:
      builder - The builder for this object.
  • Method Details

    • of

      public static <K, V> Cache.Builder<K,V> of(Class<K> key, Class<V> type)
      Static creator.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      key - The key type.
      type - The value type.
      Returns:
      A new builder for this object.
    • get

      public V get(K key, Supplier<V> supplier)
      Retrieves the value with the specified key from this cache.
      Parameters:
      key - The key.
      supplier - The supplier for creating this object if it's not found in the cache.
      Returns:
      The value.