Class CacheLoader<K,V>

java.lang.Object
com.google.common.cache.CacheLoader<K,V>

@GwtCompatible(emulated=true) @Deprecated(since="2022-12-01") public abstract class CacheLoader<K,V> extends Object
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
Computes or retrieves values, based on a key, for use in populating a LoadingCache.

Most implementations will only need to implement load(K). Other methods may be overridden as desired.

Usage example:

   

    CacheLoader<Key, Graph> loader = new CacheLoader<Key, Graph>() {
      public Graph load(Key key) throws AnyException {
        return createExpensiveGraph(key);
      }
    };
    LoadingCache<Key, Graph> cache = CacheBuilder.newBuilder().build(loader);
Since:
10.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Deprecated.
    The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V> CacheLoader<K,V>
    from(Function<K,V> function)
    Deprecated.
    Returns a cache loader based on an existing function instance.
    static <V> CacheLoader<Object,V>
    from(Supplier<V> supplier)
    Deprecated.
    Returns a cache loader based on an existing supplier instance.
    abstract V
    load(K key)
    Deprecated.
    Computes or retrieves the value corresponding to key.
    loadAll(Iterable<? extends K> keys)
    Deprecated.
    Computes or retrieves the values corresponding to keys.
    reload(K key, V oldValue)
    Deprecated.
    Computes or retrieves a replacement value corresponding to an already-cached key.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • load

      public abstract V load(K key) throws Exception
      Deprecated.
      Computes or retrieves the value corresponding to key.
      Parameters:
      key - the non-null key whose value should be loaded
      Returns:
      the value associated with key; must not be null
      Throws:
      Exception - if unable to load the result
      InterruptedException - if this method is interrupted. InterruptedException is treated like any other Exception in all respects except that, when it is caught, the thread's interrupt status is set
    • reload

      @GwtIncompatible("Futures") public ListenableFuture<V> reload(K key, V oldValue) throws Exception
      Deprecated.
      Computes or retrieves a replacement value corresponding to an already-cached key. This method is called when an existing cache entry is refreshed by CacheBuilder.refreshAfterWrite(long, java.util.concurrent.TimeUnit), or through a call to LoadingCache.refresh(K).

      This implementation synchronously delegates to load(K). It is recommended that it be overridden with an asynchronous implementation when using CacheBuilder.refreshAfterWrite(long, java.util.concurrent.TimeUnit).

      Note: all exceptions thrown by this method will be logged and then swallowed.

      Parameters:
      key - the non-null key whose value should be loaded
      oldValue - the non-null old value corresponding to key
      Returns:
      the future new value associated with key; must not be null, must not return null
      Throws:
      Exception - if unable to reload the result
      InterruptedException - if this method is interrupted. InterruptedException is treated like any other Exception in all respects except that, when it is caught, the thread's interrupt status is set
      Since:
      11.0
    • loadAll

      public Map<K,V> loadAll(Iterable<? extends K> keys) throws Exception
      Deprecated.
      Computes or retrieves the values corresponding to keys. This method is called by LoadingCache.getAll(java.lang.Iterable<? extends K>).

      If the returned map doesn't contain all requested keys then the entries it does contain will be cached, but getAll will throw an exception. 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 overriden when bulk retrieval is significantly more efficient than many individual lookups. Note that LoadingCache.getAll(java.lang.Iterable<? extends K>) will defer to individual calls to LoadingCache.get(K) if this method is not overriden.

      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
      Throws:
      Exception - if unable to load the result
      InterruptedException - if this method is interrupted. InterruptedException is treated like any other Exception in all respects except that, when it is caught, the thread's interrupt status is set
      Since:
      11.0
    • from

      @Beta public static <K, V> CacheLoader<K,V> from(Function<K,V> function)
      Deprecated.
      Returns a cache loader based on an existing function instance. Note that there's no need to create a new function just to pass it in here; just subclass CacheLoader and implement load instead.
      Parameters:
      function - the function to be used for loading values; must never return null
      Returns:
      a cache loader that loads values by passing each key to function
    • from

      @Beta public static <V> CacheLoader<Object,V> from(Supplier<V> supplier)
      Deprecated.
      Returns a cache loader based on an existing supplier instance. Note that there's no need to create a new supplier just to pass it in here; just subclass CacheLoader and implement load instead.
      Parameters:
      supplier - the supplier to be used for loading values; must never return null
      Returns:
      a cache loader that loads values by calling Supplier.get(), irrespective of the key