Package org.dataloader.impl
Class DefaultCacheMap<K,V>
java.lang.Object
org.dataloader.impl.DefaultCacheMap<K,V>
- Type Parameters:
K- type parameter indicating the type of the cache keysV- type parameter indicating the type of the data that is cached
- All Implemented Interfaces:
CacheMap<K,V>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear()Clears all entries of the cache mapbooleancontainsKey(K key) Checks whether the specified key is contained in the cache map.Deletes the entry with the specified key from the cache map, if it exists.@Nullable CompletableFuture<V> Gets the specified key from the cache map.getAll()Gets a collection of CompletableFutures from the cache map.@Nullable CompletableFuture<V> putIfAbsentAtomically(K key, CompletableFuture<V> value) Atomically creates a new cache map entry with the specified key and value, or updates the value if the key already exists.intsize()Returns the current size of the cache.
-
Constructor Details
-
DefaultCacheMap
public DefaultCacheMap()Default constructor
-
-
Method Details
-
containsKey
Checks whether the specified key is contained in the cache map.- Specified by:
containsKeyin interfaceCacheMap<K,V> - Parameters:
key- the key to check- Returns:
trueif the cache contains the key,falseotherwise
-
get
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.
-
getAll
Gets a collection of CompletableFutures from the cache map. -
putIfAbsentAtomically
Atomically creates a new cache map entry with the specified key and value, or updates the value if the key already exists.The data loader code using a Compare and Swap (CAS) algorithm to decide if a cache entry is present or not. If you write your own
CacheMapimplementation then you MUST provide atomic writes in this method to ensure that the same promise for a key is returned always.The default implementation of this method uses
ConcurrentHashMaphas its implementation so these CAS writes work as expected.- Specified by:
putIfAbsentAtomicallyin interfaceCacheMap<K,V> - Parameters:
key- the key to cachevalue- the value to cache- Returns:
- atomically the previous value for the key or null if the value is not present.
-
delete
Deletes the entry with the specified key from the cache map, if it exists. -
clear
Clears all entries of the cache map -
size
public int size()Description copied from interface:CacheMapReturns the current size of the cache. This is not used by DataLoader directly and intended for testing and debugging. If a cache doesn't support it, it can throw an Exception.
-