Class DefaultCacheMap<K,V>

java.lang.Object
org.dataloader.impl.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 Object implements CacheMap<K,V>
Default implementation of CacheMap that is based on a regular HashMap.
  • Field Details

  • Constructor Details

    • DefaultCacheMap

      public DefaultCacheMap()
      Default constructor
  • Method Details

    • 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 CompletableFuture<V> get(K key)
      Gets the specified key from the cache map.

      May throw an exception if the key does not exists, depending on the cache map implementation that is used, so be sure to check CacheMap.containsKey(Object) first.

      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 Collection<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, 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