Class NoOpValueCache<K,V>
- java.lang.Object
-
- org.dataloader.impl.NoOpValueCache<K,V>
-
- Type Parameters:
K
- the type of cache keysV
- the type of cache values
- All Implemented Interfaces:
ValueCache<K,V>
public class NoOpValueCache<K,V> extends java.lang.Object implements ValueCache<K,V>
Implementation ofValueCache
that does nothing.We don't want to store values in memory twice, so when using the default store we just say we never have the key and complete the other methods by doing nothing.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.dataloader.ValueCache
ValueCache.ValueCachingNotSupported
-
-
Field Summary
Fields Modifier and Type Field Description static NoOpValueCache<?,?>
NOOP
a no op value cache instance
-
Constructor Summary
Constructors Constructor Description NoOpValueCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Void>
clear()
Clears all entries from the value cache.java.util.concurrent.CompletableFuture<java.lang.Void>
delete(K key)
Deletes the entry with the specified key from the value cache, if it exists.java.util.concurrent.CompletableFuture<V>
get(K key)
Gets the specified key from the value cache.java.util.concurrent.CompletableFuture<java.util.List<Try<V>>>
getValues(java.util.List<K> keys)
Gets the specified keys from the value cache, in a batch call.java.util.concurrent.CompletableFuture<V>
set(K key, V value)
Stores the value with the specified key, or updates it if the key already exists.java.util.concurrent.CompletableFuture<java.util.List<V>>
setValues(java.util.List<K> keys, java.util.List<V> values)
Stores the value with the specified keys, or updates it if the keys if they already exist.
-
-
-
Field Detail
-
NOOP
public static final NoOpValueCache<?,?> NOOP
a no op value cache instance
-
-
Method Detail
-
get
public java.util.concurrent.CompletableFuture<V> get(K key)
Gets the specified key from the value cache. If the key is not present, then the implementation MUST return an exceptionally completed future and not null because null is a valid cacheable value. An exceptionally completed future will causeDataLoader
to load the key via batch loading instead.- Specified by:
get
in interfaceValueCache<K,V>
- Parameters:
key
- the key to retrieve- Returns:
- a future containing the cached value (which maybe null) or exceptionally completed future if the key does not exist in the cache.
-
getValues
public java.util.concurrent.CompletableFuture<java.util.List<Try<V>>> getValues(java.util.List<K> keys) throws ValueCache.ValueCachingNotSupported
Description copied from interface:ValueCache
Gets the specified keys from the value cache, in a batch call. If your underlying cache cannot do batch caching retrieval then do not implement this method, and it will delegate back toValueCache.get(Object)
for youEach item in the returned list of values is a
Try
. If the key could not be found then a failed Try just be returned otherwise a successful Try contain the cached value is returned.You MUST return a List that is the same size as the keys passed in. The code will assert if you do not.
If your cache does not have anything in it at all, and you want to quickly short-circuit this method and avoid any object allocation then throw
ValueCache.ValueCachingNotSupported
and the code will know there is nothing in cache at this time.- Specified by:
getValues
in interfaceValueCache<K,V>
- Parameters:
keys
- the list of keys to get cached values for.- Returns:
- a future containing a list of
Try
cached values for each key passed in. - Throws:
ValueCache.ValueCachingNotSupported
- if this cache wants to short-circuit this method completely
-
set
public java.util.concurrent.CompletableFuture<V> set(K key, V value)
Stores the value with the specified key, or updates it if the key already exists.- Specified by:
set
in interfaceValueCache<K,V>
- Parameters:
key
- the key to storevalue
- the value to store- Returns:
- a future containing the stored value for fluent composition
-
setValues
public java.util.concurrent.CompletableFuture<java.util.List<V>> setValues(java.util.List<K> keys, java.util.List<V> values) throws ValueCache.ValueCachingNotSupported
Description copied from interface:ValueCache
Stores the value with the specified keys, or updates it if the keys if they already exist. If your underlying cache can't do batch caching setting then do not implement this method, and it will delegate back toValueCache.set(Object, Object)
for you- Specified by:
setValues
in interfaceValueCache<K,V>
- Parameters:
keys
- the keys to storevalues
- the values to store- Returns:
- a future containing the stored values for fluent composition
- Throws:
ValueCache.ValueCachingNotSupported
- if this cache wants to short-circuit this method completely
-
delete
public java.util.concurrent.CompletableFuture<java.lang.Void> delete(K key)
Deletes the entry with the specified key from the value cache, if it exists.NOTE: Your implementation MUST not throw exceptions, rather it should return a CompletableFuture that has completed exceptionally. Failure to do this may cause the
DataLoader
code to not run properly.- Specified by:
delete
in interfaceValueCache<K,V>
- Parameters:
key
- the key to delete- Returns:
- a void future for error handling and fluent composition
-
clear
public java.util.concurrent.CompletableFuture<java.lang.Void> clear()
Clears all entries from the value cache.NOTE: Your implementation MUST not throw exceptions, rather it should return a CompletableFuture that has completed exceptionally. Failure to do this may cause the
DataLoader
code to not run properly.- Specified by:
clear
in interfaceValueCache<K,V>
- Returns:
- a void future for error handling and fluent composition
-
-