public abstract class CacheLoader<K,V>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CacheLoader.InvalidCacheLoadException
Thrown to indicate that an invalid response was returned from a call to
CacheLoader. |
static class |
CacheLoader.UnsupportedLoadingOperationException
Exception thrown by
loadAll() to indicate that it is not supported. |
| Modifier | Constructor and Description |
|---|---|
protected |
CacheLoader()
Constructor for use by subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
static <K,V> CacheLoader<K,V> |
from(Function<K,V> function)
Returns a cache loader based on an existing function instance.
|
static <V> CacheLoader<java.lang.Object,V> |
from(Supplier<V> supplier)
Returns a cache loader based on an existing supplier instance.
|
abstract V |
load(K key)
Computes or retrieves the value corresponding to
key. |
java.util.Map<K,V> |
loadAll(java.lang.Iterable<? extends K> keys) |
ListenableFuture<V> |
reload(K key,
V oldValue) |
@Nullable public abstract V load(K key) throws java.lang.Exception
key.key - the non-null key whose value should be loadedkey; must not be nulljava.lang.Exception - if unable to load the resultjava.lang.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@Nullable public ListenableFuture<V> reload(@Nonnull K key, @Nonnull V oldValue) throws java.lang.Exception
java.lang.Exception@Nonnull public java.util.Map<K,V> loadAll(java.lang.Iterable<? extends K> keys) throws java.lang.Exception
java.lang.Exception@Nonnull public static <K,V> CacheLoader<K,V> from(@Nonnull Function<K,V> function)
CacheLoader and
implement load instead.function - the function to be used for loading values; must never return nullfunction@Nonnull public static <V> CacheLoader<java.lang.Object,V> from(@Nonnull Supplier<V> supplier)
CacheLoader and
implement load instead.supplier - the supplier to be used for loading values; must never return nullSupplier.get(), irrespective of the
key