javadoc.com.google.common.cache.ForwardingLoadingCache.html Maven / Gradle / Ivy
ForwardingLoadingCache (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.cache
Class ForwardingLoadingCache<K,V>
java.lang.Object
com.google.common.collect.ForwardingObject
com.google.common.cache.ForwardingCache<K,V>
com.google.common.cache.ForwardingLoadingCache<K,V>
- All Implemented Interfaces:
- Function<K,V>, Cache<K,V>, LoadingCache<K,V>
- Direct Known Subclasses:
- ForwardingLoadingCache.SimpleForwardingLoadingCache
@Beta
public abstract class ForwardingLoadingCache<K,V>
- extends ForwardingCache<K,V>
- implements LoadingCache<K,V>
A cache which forwards all its method calls to another cache. Subclasses should override one or more methods to modify the behavior of the backing cache as desired per the decorator pattern.
Note that get(K)
, getUnchecked(K)
, and apply(K)
all expose the same
underlying functionality, so should probably be overridden as a group.
- Since:
- 11.0
- Author:
- Charles Fry
Nested Class Summary | |
---|---|
static class |
ForwardingLoadingCache.SimpleForwardingLoadingCache<K,V>
A simplified version of ForwardingLoadingCache where subclasses can pass in an already
constructed LoadingCache as the delegete. |
Nested classes/interfaces inherited from class com.google.common.cache.ForwardingCache |
---|
ForwardingCache.SimpleForwardingCache<K,V> |
Constructor Summary | |
---|---|
protected |
ForwardingLoadingCache()
Constructor for use by subclasses. |
Method Summary | |
---|---|
V |
apply(K key)
Discouraged. |
protected abstract LoadingCache<K,V> |
delegate()
Returns the backing delegate instance that methods are forwarded to. |
V |
get(K key)
Returns the value associated with key in this cache, first loading that value if
necessary. |
ImmutableMap<K,V> |
getAll(Iterable<? extends K> keys)
Returns a map of the values associated with keys , creating or retrieving those values
if necessary. |
V |
getUnchecked(K key)
Returns the value associated with key in this cache, first loading that value if
necessary. |
void |
refresh(K key)
Loads a new value for key key , possibly asynchronously. |
Methods inherited from class com.google.common.cache.ForwardingCache |
---|
asMap, cleanUp, get, getAllPresent, getIfPresent, invalidate, invalidateAll, invalidateAll, put, size, stats |
Methods inherited from class com.google.common.collect.ForwardingObject |
---|
toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.google.common.cache.LoadingCache |
---|
asMap |
Methods inherited from interface com.google.common.cache.Cache |
---|
cleanUp, get, getAllPresent, getIfPresent, invalidate, invalidateAll, invalidateAll, put, size, stats |
Methods inherited from interface com.google.common.base.Function |
---|
equals |
Constructor Detail |
---|
ForwardingLoadingCache
protected ForwardingLoadingCache()
- Constructor for use by subclasses.
Method Detail |
---|
delegate
protected abstract LoadingCache<K,V> delegate()
- Description copied from class:
ForwardingObject
- Returns the backing delegate instance that methods are forwarded to.
Abstract subclasses generally override this method with an abstract method
that has a more specific return type, such as
ForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingCache<K,V>
get
public V get(K key) throws ExecutionException
- Description copied from interface:
Cache
- Returns the value associated with
key
in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes.- Throws:
ExecutionException
- if a checked exception was thrown while loading the value
getUnchecked
public V getUnchecked(K key)
- Description copied from interface:
Cache
- Returns the value associated with
key
in this cache, first loading that value if necessary. No observable state associated with this cache is modified until computation completes. UnlikeCache.get(K, java.util.concurrent.Callable extends V>)
, this method does not throw a checked exception, and thus should only be used in situations where checked exceptions are not thrown by the cache loader.Warning: this method silently converts checked exceptions to unchecked exceptions, and should not be used with cache loaders which throw checked exceptions.
- Specified by:
getUnchecked
in interfaceCache<K,V>
- Specified by:
getUnchecked
in interfaceLoadingCache<K,V>
- Overrides:
getUnchecked
in classForwardingCache<K,V>
getAll
public ImmutableMap<K,V> getAll(Iterable<? extends K> keys) throws ExecutionException
- Description copied from interface:
LoadingCache
- Returns a map of the values associated with
keys
, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with newly loaded entries; it will never contain null keys or values.Caches loaded by a
CacheLoader
will issue a single request toCacheLoader.loadAll(java.lang.Iterable extends K>)
for all keys which are not already present in the cache. All entries returned byCacheLoader.loadAll(java.lang.Iterable extends K>)
will be stored in the cache, over-writing any previously cached values. This method will throw an exception ifCacheLoader.loadAll(java.lang.Iterable extends K>)
returnsnull
, returns a map containing null keys or values, or fails to return an entry for each requested key.Note that duplicate elements in
keys
, as determined byObject.equals(java.lang.Object)
, will be ignored.- Specified by:
getAll
in interfaceLoadingCache<K,V>
- Throws:
ExecutionException
- if a checked exception was thrown while loading the values
apply
public V apply(K key)
- Description copied from interface:
Cache
- Discouraged. Provided to satisfy the
Function
interface; useCache.get(K, java.util.concurrent.Callable extends V>)
orCache.getUnchecked(K)
instead.
refresh
public void refresh(K key)
- Description copied from interface:
LoadingCache
- Loads a new value for key
key
, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned byget(key)
unless it is evicted. If the new value is loaded successfully it will replace the previous value in the cache; if an exception is thrown while refreshing the previous value will remain, and the exception will be logged (usingLogger
) and swallowed.Caches loaded by a
CacheLoader
will callCacheLoader.reload(K, V)
if the cache currently contains a value forkey
, andCacheLoader.load(K)
otherwise.Returns without doing anything if another thread is currently loading the value for
key
. If the cache loader associated with this cache performs refresh asynchronously then this method may return before refresh completes.- Specified by:
refresh
in interfaceLoadingCache<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.