Interface Cache<K,​V>

  • Type Parameters:
    K - The type of the key.
    V - The type of the value.

    public interface Cache<K,​V>
    A contract that defines a semi-persistent mapping of keys and values.
    Cache entries are manually added using put(Cache, Cache), and are stored in the cache until either evicted or manually removed. After storing a value, it can be accessed using get(Cache).
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean contains​(K key)
      Returns True if the cache contains a entry with the key, or False if there is none.
      Optional<V> get​(K key)
      Returns the value associated with key in this cache, or empty if there is no cached value for key.
      boolean isEmpty()
      Returns True if the cache is empty, or False if there's at least a entry stored in cache.
      void put​(K key, V value)
      Associates value with key in this cache.
      void remove​(K key)
      Discards any cached value for this key.
      void removeAll()
      Discards all entries in the cache.
      long size()
      Returns the number of entries in this cache.
      CacheStats stats()
      Returns a current snapshot of this cache's cumulative statistics, or a set of default values if the cache is not recording statistics.
    • Method Detail

      • put

        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.
        Parameters:
        key - The key to be used as index.
        value - The value to be stored.
      • get

        Optional<V> get​(K key)
        Returns the value associated with key in this cache, or empty if there is no cached value for key.
        Parameters:
        key - The key to look for.
        Returns:
        The value stored in cache if present.
      • remove

        void remove​(K key)
        Discards any cached value for this key.
        Parameters:
        key - The key to be discarded.
      • removeAll

        void removeAll()
        Discards all entries in the cache.
      • contains

        boolean contains​(K key)
        Returns True if the cache contains a entry with the key, or False if there is none.
        Parameters:
        key - The key to be verified.
        Returns:
        True if the key is present.
      • size

        long size()
        Returns the number of entries in this cache.
        Returns:
        The cache size.
      • isEmpty

        boolean isEmpty()
        Returns True if the cache is empty, or False if there's at least a entry stored in cache.
        Returns:
        True if is empty.
      • stats

        CacheStats stats()
        Returns a current snapshot of this cache's cumulative statistics, or a set of default values if the cache is not recording statistics. All statistics begin at zero and never decrease over the lifetime of the cache.