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 @NullMarked 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

    Modifier and Type
    Method
    Description
    Clears all entries of the cache map
    boolean
    Checks whether the specified key is contained in the cache map.
    delete(K key)
    Deletes the entry with the specified key from the cache map, if it exists.
    @Nullable CompletableFuture<V>
    get(K key)
    Gets the specified key from the cache map.
    Gets a collection of CompletableFutures from the cache map.
    set(K key, 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>
    Creates a new cache map, using the default implementation that is based on a LinkedHashMap.
  • Method Details

    • 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

      @Nullable 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

      Gets a collection of CompletableFutures from the cache map.
      Returns:
      the collection of cached values
    • set

      CacheMap<K,V> set(K key, 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