Package org.dataloader
Interface CacheMap<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 Known Implementing Classes:
DefaultCacheMap
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 TypeMethodDescriptionclear()
Clears all entries of the cache mapboolean
containsKey
(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.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 aLinkedHashMap
.
-
Method Details
-
simpleMap
Creates a new cache map, using the default implementation that is based on aLinkedHashMap
.- Type Parameters:
K
- type parameter indicating the type of the cache keysV
- type parameter indicating the type of the data that is cached- Returns:
- the cache map
-
containsKey
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
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
Collection<CompletableFuture<V>> getAll()Gets a collection of CompletableFutures from the cache map.- Returns:
- the collection of cached values
-
set
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 cachevalue
- the value to cache- Returns:
- the cache map for fluent coding
-
delete
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
Clears all entries of the cache map- Returns:
- the cache map for fluent coding
-