Class DefaultCacheMap<K,​V>

  • Type Parameters:
    K - type parameter indicating the type of the cache keys
    V - type parameter indicating the type of the data that is cached
    All Implemented Interfaces:
    CacheMap<K,​V>

    public class DefaultCacheMap<K,​V>
    extends java.lang.Object
    implements CacheMap<K,​V>
    Default implementation of CacheMap that is based on a regular HashMap.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultCacheMap()
      Default constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CacheMap<K,​V> clear()
      Clears all entries of the cache map
      boolean containsKey​(K key)
      Checks whether the specified key is contained in the cache map.
      CacheMap<K,​V> delete​(K key)
      Deletes the entry with the specified key from the cache map, if it exists.
      java.util.concurrent.CompletableFuture<V> get​(K key)
      Gets the specified key from the cache map.
      java.util.Collection<java.util.concurrent.CompletableFuture<V>> getAll()
      Gets a collection of CompletableFutures from the cache map.
      CacheMap<K,​V> set​(K key, java.util.concurrent.CompletableFuture<V> value)
      Creates a new cache map entry with the specified key and value, or updates the value if the key already exists.
      • Methods inherited from class java.lang.Object

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

      • DefaultCacheMap

        public DefaultCacheMap()
        Default constructor
    • Method Detail

      • containsKey

        public boolean containsKey​(K key)
        Checks whether the specified key is contained in the cache map.
        Specified by:
        containsKey in interface CacheMap<K,​V>
        Parameters:
        key - the key to check
        Returns:
        true if the cache contains the key, false otherwise
      • get

        public java.util.concurrent.CompletableFuture<V> get​(K key)
        Gets the specified key from the cache map.

        May throw an exception if the key does not exist, depending on the cache map implementation that is used.

        Specified by:
        get in interface CacheMap<K,​V>
        Parameters:
        key - the key to retrieve
        Returns:
        the cached value, or null if not found (depends on cache implementation)
      • getAll

        public java.util.Collection<java.util.concurrent.CompletableFuture<V>> getAll()
        Gets a collection of CompletableFutures from the cache map.
        Specified by:
        getAll in interface CacheMap<K,​V>
        Returns:
        the collection of cached values
      • set

        public CacheMap<K,​V> set​(K key,
                                       java.util.concurrent.CompletableFuture<V> value)
        Creates a new cache map entry with the specified key and value, or updates the value if the key already exists.
        Specified by:
        set in interface CacheMap<K,​V>
        Parameters:
        key - the key to cache
        value - the value to cache
        Returns:
        the cache map for fluent coding
      • delete

        public CacheMap<K,​V> delete​(K key)
        Deletes the entry with the specified key from the cache map, if it exists.
        Specified by:
        delete in interface CacheMap<K,​V>
        Parameters:
        key - the key to delete
        Returns:
        the cache map for fluent coding
      • clear

        public CacheMap<K,​V> clear()
        Clears all entries of the cache map
        Specified by:
        clear in interface CacheMap<K,​V>
        Returns:
        the cache map for fluent coding