Interface CacheMap<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 Known Implementing Classes:
    DefaultCacheMap

    @PublicSpi
    public interface CacheMap<K,​V>
    CacheMap is used by data loaders that use caching promises to values aka CompletableFuture<V>. A better name for this class might have been FutureCache but that is history now.

    The default implementation used by the data loader is based on a LinkedHashMap.

    This is really a cache of completed CompletableFuture<V> values in memory. It is used, when caching is enabled, to give back the same future to any code that may call it. If you need a cache of the underlying values that is possible external to the JVM then you will want to use {ValueCache} which is designed for external cache access.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract 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.
      static <K,​V>
      CacheMap<K,​V>
      simpleMap()
      Creates a new cache map, using the default implementation that is based on a LinkedHashMap.
    • Method Detail

      • simpleMap

        static <K,​V> CacheMap<K,​V> simpleMap()
        Creates a new cache map, using the default implementation that is based on a LinkedHashMap.
        Type Parameters:
        K - type parameter indicating the type of the cache keys
        V - type parameter indicating the type of the data that is cached
        Returns:
        the cache map
      • containsKey

        boolean containsKey​(K key)
        Checks whether the specified key is contained in the cache map.
        Parameters:
        key - the key to check
        Returns:
        true if the cache contains the key, false otherwise
      • get

        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.

        Parameters:
        key - the key to retrieve
        Returns:
        the cached value, or null if not found (depends on cache implementation)
      • getAll

        java.util.Collection<java.util.concurrent.CompletableFuture<V>> getAll()
        Gets a collection of CompletableFutures from the cache map.
        Returns:
        the collection of cached values
      • set

        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.
        Parameters:
        key - the key to cache
        value - the value to cache
        Returns:
        the cache map for fluent coding
      • delete

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

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