Class NoCache<K,​V>

  • Type Parameters:
    K - The key type.
    V - The value type.
    All Implemented Interfaces:
    Cache<K,​V>

    public class NoCache<K,​V>
    extends java.lang.Object
    implements Cache<K,​V>
    A cache implementation that does not store any information.
    • Constructor Summary

      Constructors 
      Constructor Description
      NoCache()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete 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.
      static <expectedK,​expectedV>
      NoCache<expectedK,​expectedV>
      create()
      Create a new instance.
      java.util.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.
      • Methods inherited from class java.lang.Object

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

      • NoCache

        public NoCache()
    • Method Detail

      • create

        public static <expectedK,​expectedV> NoCache<expectedK,​expectedV> create()
        Create a new instance.
        Type Parameters:
        expectedK - The expected type for the key.
        expectedV - The expected type for the value.
        Returns:
        A newly created instance of NoCache.
      • put

        public void put​(K key,
                        V value)
        Description copied from interface: Cache
        Associates value with key in this cache.
        If the cache previously contained a value associated with key, the old value is replaced by value.
        Specified by:
        put in interface Cache<K,​V>
        Parameters:
        key - The key to be used as index.
        value - The value to be stored.
      • get

        public java.util.Optional<V> get​(K key)
        Description copied from interface: Cache
        Returns the value associated with key in this cache, or empty if there is no cached value for key.
        Specified by:
        get in interface Cache<K,​V>
        Parameters:
        key - The key to look for.
        Returns:
        The value stored in cache if present.
      • remove

        public void remove​(K key)
        Description copied from interface: Cache
        Discards any cached value for this key.
        Specified by:
        remove in interface Cache<K,​V>
        Parameters:
        key - The key to be discarded.
      • removeAll

        public void removeAll()
        Description copied from interface: Cache
        Discards all entries in the cache.
        Specified by:
        removeAll in interface Cache<K,​V>
      • contains

        public boolean contains​(K key)
        Description copied from interface: Cache
        Returns True if the cache contains a entry with the key, or False if there is none.
        Specified by:
        contains in interface Cache<K,​V>
        Parameters:
        key - The key to be verified.
        Returns:
        True if the key is present.
      • size

        public long size()
        Description copied from interface: Cache
        Returns the number of entries in this cache.
        Specified by:
        size in interface Cache<K,​V>
        Returns:
        The cache size.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Cache
        Returns True if the cache is empty, or False if there's at least a entry stored in cache.
        Specified by:
        isEmpty in interface Cache<K,​V>
        Returns:
        True if is empty.
      • stats

        public CacheStats stats()
        Description copied from interface: Cache
        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.
        Specified by:
        stats in interface Cache<K,​V>