K
- the type of cache keysV
- the type of cache valuespublic class NoOpValueCache<K,V> extends java.lang.Object implements ValueCache<K,V>
ValueCache
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.
ValueCache.ValueCachingNotSupported
Modifier and Type | Field and Description |
---|---|
static NoOpValueCache<?,?> |
NOOP
a no op value cache instance
|
Constructor and Description |
---|
NoOpValueCache() |
Modifier and Type | Method and 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
defaultValueCache
public static final NoOpValueCache<?,?> NOOP
public java.util.concurrent.CompletableFuture<V> get(K key)
DataLoader
to load the key via batch loading
instead.
get
in interface ValueCache<K,V>
key
- the key to retrievepublic java.util.concurrent.CompletableFuture<java.util.List<Try<V>>> getValues(java.util.List<K> keys) throws ValueCache.ValueCachingNotSupported
ValueCache
ValueCache.get(Object)
for you
Each 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.
getValues
in interface ValueCache<K,V>
keys
- the list of keys to get cached values for.Try
cached values for each key passed in.ValueCache.ValueCachingNotSupported
- if this cache wants to short-circuit this method completelypublic java.util.concurrent.CompletableFuture<V> set(K key, V value)
set
in interface ValueCache<K,V>
key
- the key to storevalue
- the value to storepublic java.util.concurrent.CompletableFuture<java.util.List<V>> setValues(java.util.List<K> keys, java.util.List<V> values) throws ValueCache.ValueCachingNotSupported
ValueCache
ValueCache.set(Object, Object)
for yousetValues
in interface ValueCache<K,V>
keys
- the keys to storevalues
- the values to storeValueCache.ValueCachingNotSupported
- if this cache wants to short-circuit this method completelypublic java.util.concurrent.CompletableFuture<java.lang.Void> delete(K key)
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.
delete
in interface ValueCache<K,V>
key
- the key to deletepublic java.util.concurrent.CompletableFuture<java.lang.Void> clear()
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.
clear
in interface ValueCache<K,V>