LoadingCache.
Most implementations will only need to implement load. 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 this example doesn't support reloading or bulk loading, it can also be specified much more simply:
CacheLoader<Key, Graph> loader = CacheLoader.from(key -> createExpensiveGraph(key));
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static class | CacheLoader.InvalidCacheLoadException
Thrown to indicate that an invalid response was returned from a call to |
| private static class | |
| public static class | CacheLoader.UnsupportedLoadingOperationException
Exception thrown by |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static <K, V> CacheLoader | asyncReloading(final CacheLoader<K, V> loader, final Executor executor)
Returns a |
| public static <K, V> CacheLoader | |
| public static <V> CacheLoader | Returns: a cache loader that loads values by callingSupplier#get, irrespective of the
keythe supplier to be used for loading values; must never return supplier)nullReturns a cache loader based on an existing supplier instance. |
| public abstract V | Returns: the value associated withkey; must not be nullthe non-null key whose value should be loaded key)Computes or retrieves the value corresponding to |
| public Map | |
| public ListenableFuture | Returns: the future new value associated withkey; must not be null, must not return
nullthe non-null key whose value should be loaded key, V the non-null old value corresponding to oldValue)keyComputes or retrieves a replacement value corresponding to an already-cached |
| CacheLoader | back to summary |
|---|---|
| protected CacheLoader() Constructor for use by subclasses. | |
| asyncReloading | back to summary |
|---|---|
| public static <K, V> CacheLoader Returns a This method is useful only when
| |
| from | back to summary |
|---|---|
| public static <K, V> CacheLoader Returns a cache loader that uses The returned object is serializable if
| |
| from | back to summary |
|---|---|
| public static <V> CacheLoader 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 The returned object is serializable if
| |
| load | back to summary |
|---|---|
| public abstract V load(K key) throws Exception Computes or retrieves the value corresponding to
| |
| loadAll | back to summary |
|---|---|
| public Map Computes or retrieves the values corresponding to If the returned map doesn't contain all requested This method should be overridden when bulk retrieval is significantly more efficient than
many individual lookups. Note that
| |
| reload | back to summary |
|---|---|
| public ListenableFuture Computes or retrieves a replacement value corresponding to an already-cached This implementation synchronously delegates to Note all exceptions thrown by this method will be logged and then swallowed.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Function | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public V | load(K
the non-null key whose value should be loaded key)Implements abstract com. key.
|
| computingFunction | back to summary |
|---|---|
| private final Function<K, V> computingFunction | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| FunctionToCacheLoader | back to summary |
|---|---|
| public FunctionToCacheLoader(Function<K, V> computingFunction) | |
| load | back to summary |
|---|---|
| public V load(K key) Implements abstract com. Doc from com. Computes or retrieves the value corresponding to
| |
CacheLoader.
| Access | Constructor and Description |
|---|---|
| public |
| InvalidCacheLoadException | back to summary |
|---|---|
| public InvalidCacheLoadException(String message) | |
| Modifier and Type | Field and Description |
|---|---|
| private final Supplier | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public V | load(Object
the non-null key whose value should be loaded key)Implements abstract com. key.
|
| computingSupplier | back to summary |
|---|---|
| private final Supplier<V> computingSupplier | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| SupplierToCacheLoader | back to summary |
|---|---|
| public SupplierToCacheLoader(Supplier<V> computingSupplier) | |
| load | back to summary |
|---|---|
| public V load(Object key) Implements abstract com. Doc from com. Computes or retrieves the value corresponding to | |
loadAll() to indicate that it is not supported.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| UnsupportedLoadingOperationException | back to summary |
|---|---|
| pack-priv UnsupportedLoadingOperationException() | |