Top Description Inners Constructors Methods
com.google.common.cache

public abstract Class ForwardingLoadingCache<K, V>

extends ForwardingCache<K, V>
implements LoadingCache<K, V>
Class Inheritance
All Implemented Interfaces
com.google.common.cache.LoadingCache, com.google.common.base.Function, java.util.function.Function, com.google.common.cache.Cache
Known Direct Subclasses
com.google.common.cache.ForwardingLoadingCache.SimpleForwardingLoadingCache
Annotations
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtIncompatible, com.google.common.base.Preconditions, com.google.common.collect.ImmutableMap, com.google.errorprone.annotations.CanIgnoreReturnValue, java.util.concurrent.ExecutionException

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, getUnchecked, and apply all expose the same underlying functionality, so should probably be overridden as a group.

Author
Charles Fry
Since
11.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
ForwardingLoadingCache.SimpleForwardingLoadingCache<K, V>

A simplified version of ForwardingLoadingCache where subclasses can pass in an already constructed LoadingCache as the delegate.

Constructor Summary

AccessConstructor and Description
protected
ForwardingLoadingCache()

Constructor for use by subclasses.

Method Summary

Modifier and TypeMethod and Description
public V
apply(K
the function argument
key
)

Implements com.google.common.cache.LoadingCache.apply.

Applies this function to the given argument.
protected abstract LoadingCache<K, V>
delegate()

Implements abstract com.google.common.cache.ForwardingCache.delegate.

Returns the backing delegate instance that methods are forwarded to.
public V
get(K key)

Implements com.google.common.cache.LoadingCache.get.

Returns the value associated with key in this cache, first loading that value if necessary.
public ImmutableMap<K, V>
getAll(Iterable<? extends K> keys)

Implements com.google.common.cache.LoadingCache.getAll.

Returns a map of the values associated with keys, creating or retrieving those values if necessary.
public V
getUnchecked(K key)

Implements com.google.common.cache.LoadingCache.getUnchecked.

Returns the value associated with key in this cache, first loading that value if necessary.
public void
refresh(K key)

Implements com.google.common.cache.LoadingCache.refresh.

Loads a new value for key, possibly asynchronously.
Inherited from com.google.common.cache.ForwardingCache:
asMapcleanUpgetgetAllPresentgetIfPresentinvalidateinvalidateAllinvalidateAllputputAllsizestats

Constructor Detail

ForwardingLoadingCacheback to summary
protected ForwardingLoadingCache()

Constructor for use by subclasses.

Method Detail

applyback to summary
public V apply(K key)

Implements com.google.common.cache.LoadingCache.apply.

Doc from java.util.function.Function.apply.

Applies this function to the given argument.

Parameters
key:K

the function argument

Returns:V

the function result

Annotations
@Override
delegateback to summary
protected abstract LoadingCache<K, V> delegate()

Implements abstract com.google.common.cache.ForwardingCache.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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.

Annotations
@Override
getback to summary
public V get(K key) throws ExecutionException

Implements com.google.common.cache.LoadingCache.get.

Doc from com.google.common.cache.LoadingCache.get.

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.

If another call to get or getUnchecked is currently loading the value for key, simply waits for that thread to finish and returns its loaded value. Note that multiple threads can concurrently load values for distinct keys.

Caches loaded by a CacheLoader will call CacheLoader#load to load new values into the cache. Newly loaded values are added to the cache using Cache.asMap().putIfAbsent after loading has completed; if another value was associated with key while the new value was loading then a removal notification will be sent for the new value.

If the cache loader associated with this cache is known not to throw checked exceptions, then prefer getUnchecked over this method.

Annotations
@CanIgnoreReturnValue
@Override
Exceptions
ExecutionException:
if a checked exception was thrown while loading the value. (ExecutionException is thrown even if computation was interrupted by an InterruptedException.)
getAllback to summary
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException

Implements com.google.common.cache.LoadingCache.getAll.

Doc from com.google.common.cache.LoadingCache.getAll.

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 to CacheLoader#loadAll for all keys which are not already present in the cache. All entries returned by CacheLoader#loadAll will be stored in the cache, over-writing any previously cached values. This method will throw an exception if CacheLoader#loadAll returns null, 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 by Object#equals, will be ignored.

Annotations
@CanIgnoreReturnValue
@Override
Exceptions
ExecutionException:
if a checked exception was thrown while loading the value. (ExecutionException is thrown even if computation was interrupted by an InterruptedException.)
getUncheckedback to summary
public V getUnchecked(K key)

Implements com.google.common.cache.LoadingCache.getUnchecked.

Doc from com.google.common.cache.LoadingCache.getUnchecked.

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. Unlike get, 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.

If another call to get or getUnchecked is currently loading the value for key, simply waits for that thread to finish and returns its loaded value. Note that multiple threads can concurrently load values for distinct keys.

Caches loaded by a CacheLoader will call CacheLoader#load to load new values into the cache. Newly loaded values are added to the cache using Cache.asMap().putIfAbsent after loading has completed; if another value was associated with key while the new value was loading then a removal notification will be sent for the new value.

Warning

this method silently converts checked exceptions to unchecked exceptions, and should not be used with cache loaders which throw checked exceptions. In such cases use get instead.

Annotations
@CanIgnoreReturnValue
@Override
refreshback to summary
public void refresh(K key)

Implements com.google.common.cache.LoadingCache.refresh.

Doc from com.google.common.cache.LoadingCache.refresh.

Loads a new value for key, possibly asynchronously. While the new value is loading the previous value (if any) will continue to be returned by get(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 (using java.util.logging.Logger) and swallowed.

Caches loaded by a CacheLoader will call CacheLoader#reload if the cache currently contains a value for key, and CacheLoader#load otherwise. Loading is asynchronous only if CacheLoader#reload was overridden with an asynchronous implementation.

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.

Annotations
@Override
com.google.common.cache back to summary

public abstract Class ForwardingLoadingCache.SimpleForwardingLoadingCache<K, V>

extends ForwardingLoadingCache<K, V>
Class Inheritance

A simplified version of ForwardingLoadingCache where subclasses can pass in an already constructed LoadingCache as the delegate.
Since
10.0

Field Summary

Modifier and TypeField and Description
private final LoadingCache<K, V>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected final LoadingCache<K, V>
delegate()

Implements abstract com.google.common.cache.ForwardingLoadingCache.delegate.

Returns the backing delegate instance that methods are forwarded to.
Inherited from com.google.common.cache.ForwardingLoadingCache:
applygetgetAllgetUncheckedrefresh

Field Detail

delegateback to summary
private final LoadingCache<K, V> delegate

Constructor Detail

SimpleForwardingLoadingCacheback to summary
protected SimpleForwardingLoadingCache(LoadingCache<K, V> delegate)

Method Detail

delegateback to summary
protected final LoadingCache<K, V> delegate()

Implements abstract com.google.common.cache.ForwardingLoadingCache.delegate.

Doc from com.google.common.collect.ForwardingObject.delegate.

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.

Annotations
@Override