Class JCacheLoaderAdapter<K,V>

java.lang.Object
com.github.benmanes.caffeine.jcache.integration.JCacheLoaderAdapter<K,V>
All Implemented Interfaces:
AsyncCacheLoader<K, Expirable<V>>, CacheLoader<K, Expirable<V>>

public final class JCacheLoaderAdapter<K,V> extends Object implements CacheLoader<K, Expirable<V>>
An adapter from a JCache cache loader to Caffeine's.
Author:
ben.manes@gmail.com (Ben Manes)
  • Constructor Details

  • Method Details

    • setCache

      public void setCache(CacheProxy<K,V> cache)
      Sets the cache instance that was created with this loader.
      Parameters:
      cache - the cache that uses this loader
    • load

      public @Nullable Expirable<V> load(K key)
      Description copied from interface: CacheLoader
      Computes or retrieves the value corresponding to key.

      Warning: loading must not attempt to update any mappings of this cache directly.

      Specified by:
      load in interface CacheLoader<K,V>
      Parameters:
      key - the non-null key whose value should be loaded
      Returns:
      the value associated with key or null if not found
    • loadAll

      public Map<K, Expirable<V>> loadAll(Iterable<? extends K> keys)
      Description copied from interface: CacheLoader
      Computes or retrieves the values corresponding to keys. This method is called by LoadingCache.getAll(Iterable).

      If the returned map doesn't contain all requested keys then the entries it does contain will be cached and getAll will return the partial results. If the returned map contains extra keys not present in keys then all returned entries will be cached, but only the entries for keys will be returned from getAll.

      This method should be overridden when bulk retrieval is significantly more efficient than many individual lookups. Note that LoadingCache.getAll(Iterable) will defer to individual calls to LoadingCache.get(K) if this method is not overridden.

      Warning: loading must not attempt to update any mappings of this cache directly.

      Specified by:
      loadAll in interface CacheLoader<K,V>
      Parameters:
      keys - the unique, non-null keys whose values should be loaded
      Returns:
      a map from each key in keys to the value associated with that key; may not contain null values