public interface Cache<K,V>
A cache from keys to values.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V> Cache<K,V>
    bounded(int capacity)
    Returns new bounded cache.
    computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
    Returns the cached value associated with the provided key.
    get(K key)
    Returns the cached value associated with the provided key if present, or null otherwise.
    void
    put(K key, V value)
    Puts the value into the cache for the key.
    void
    remove(K key)
    Removes a value for key if present.
    static <K, V> Cache<K,V>
    Returns new unbounded cache
  • Method Details

    • weak

      static <K, V> Cache<K,V> weak()
      Returns new unbounded cache

      Keys are referenced weakly and compared using identity comparison, not Object.equals(Object).

    • bounded

      static <K, V> Cache<K,V> bounded(int capacity)
      Returns new bounded cache.

      Both keys and values are strongly referenced.

    • computeIfAbsent

      V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
      Returns the cached value associated with the provided key. If no value is cached yet, computes the value using mappingFunction, stores the result, and returns it.
    • get

      @Nullable V get(K key)
      Returns the cached value associated with the provided key if present, or null otherwise.
    • put

      void put(K key, V value)
      Puts the value into the cache for the key.
    • remove

      void remove(K key)
      Removes a value for key if present.