Class NoOpValueCache<K,V>

java.lang.Object
org.dataloader.impl.NoOpValueCache<K,V>
Type Parameters:
K - the type of cache keys
V - the type of cache values
All Implemented Interfaces:
ValueCache<K,V>

public class NoOpValueCache<K,V> extends Object implements ValueCache<K,V>
Implementation of 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.

  • Field Details

    • NOOP

      public static final NoOpValueCache<?,?> NOOP
      a no op value cache instance
  • Constructor Details

    • NoOpValueCache

      public NoOpValueCache()
  • Method Details

    • get

      public 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 cause DataLoader to load the key via batch loading instead.

      Specified by:
      get in interface ValueCache<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

      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 to 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.

      Specified by:
      getValues in interface ValueCache<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 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 interface ValueCache<K,V>
      Parameters:
      key - the key to store
      value - the value to store
      Returns:
      a future containing the stored value for fluent composition
    • setValues

      public CompletableFuture<List<V>> setValues(List<K> keys, 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 to ValueCache.set(Object, Object) for you
      Specified by:
      setValues in interface ValueCache<K,V>
      Parameters:
      keys - the keys to store
      values - 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 CompletableFuture<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 interface ValueCache<K,V>
      Parameters:
      key - the key to delete
      Returns:
      a void future for error handling and fluent composition
    • clear

      public CompletableFuture<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 interface ValueCache<K,V>
      Returns:
      a void future for error handling and fluent composition