Class Caches.ClearableCache<K,​V>

  • All Implemented Interfaces:
    Cache<K,​V>
    Enclosing class:
    Caches

    public static class Caches.ClearableCache<K,​V>
    extends java.lang.Object
    A cache that tracks keys that have been inserted into the cache and supports clearing them.

    The set of keys that are tracked are only those provided to peek(K) and computeIfAbsent(K, java.util.function.Function<K, V>).

    • Nested Class Summary

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all tracked keys from the cache.
      V computeIfAbsent​(K key, java.util.function.Function<K,​V> loadingFunction)
      Looks up the specified key and returns the associated value.
      void put​(K key, V value)
      Inserts a new value associated with the given key or updates an existing association of the same key with the new value.
      void remove​(K key)
      Removes the mapping for a key from the cache if it is present.
      • Methods inherited from class java.lang.Object

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

      • ClearableCache

        public ClearableCache​(Cache<K,​V> cache)
    • Method Detail

      • computeIfAbsent

        public V computeIfAbsent​(K key,
                                 java.util.function.Function<K,​V> loadingFunction)
        Description copied from interface: Cache
        Looks up the specified key and returns the associated value.

        If the key is not present in the cache, the specified function will be used to load and populate the cache.

        Specified by:
        computeIfAbsent in interface Cache<K,​V>
      • put

        public void put​(K key,
                        V value)
        Description copied from interface: Cache
        Inserts a new value associated with the given key or updates an existing association of the same key with the new value.
        Specified by:
        put in interface Cache<K,​V>
      • remove

        public void remove​(K key)
        Description copied from interface: Cache
        Removes the mapping for a key from the cache if it is present.
        Specified by:
        remove in interface Cache<K,​V>
      • clear

        public void clear()
        Removes all tracked keys from the cache.