|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.collect.ForwardingObject
com.google.common.cache.ForwardingCache<K,V>
@Beta public abstract class ForwardingCache<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.
| Nested Class Summary | |
|---|---|
static class |
ForwardingCache.SimpleForwardingCache<K,V>
A simplified version of ForwardingCache where subclasses can pass in an already
constructed Cache as the delegete. |
| Constructor Summary | |
|---|---|
protected |
ForwardingCache()
Constructor for use by subclasses. |
| Method Summary | |
|---|---|
V |
apply(K key)
Deprecated. |
ConcurrentMap<K,V> |
asMap()
Returns a view of the entries stored in this cache as a thread-safe map. |
void |
cleanUp()
Performs any pending maintenance operations needed by the cache. |
protected abstract Cache<K,V> |
delegate()
Returns the backing delegate instance that methods are forwarded to. |
V |
get(K key)
Returns the value associated with the given key, creating or retrieving that value if necessary, and throwing an execution exception on failure. |
V |
getUnchecked(K key)
Returns the value associated with the given key, loading that value if necessary. |
void |
invalidate(Object key)
Discards any cached value for key key, possibly asynchronously, so that a future
invocation of get(key) will result in a cache miss and reload. |
void |
invalidateAll()
Discards all entries in the cache, possibly asynchronously. |
long |
size()
Returns the approximate number of entries in this cache. |
CacheStats |
stats()
Returns a current snapshot of this cache's cumulative statistics. |
| 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.base.Function |
|---|
equals |
| Constructor Detail |
|---|
protected ForwardingCache()
| Method Detail |
|---|
protected abstract Cache<K,V> delegate()
ForwardingObjectForwardingSet.delegate(). Concrete subclasses override this method to supply
the instance being decorated.
delegate in class ForwardingObject
@Nullable
public V get(@Nullable
K key)
throws ExecutionException
Cachenull.
get in interface Cache<K,V>ExecutionException - if a checked exception was thrown while loading the response
@Nullable
public V getUnchecked(@Nullable
K key)
CacheCache.get(K), 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. Note that this method will never return
null.
Warning: this method silently converts checked exceptions to unchecked exceptions.
The Cache.get(K) method should be preferred for cache loaders which throw checked exceptions.
getUnchecked in interface Cache<K,V>
@Deprecated
@Nullable
public V apply(@Nullable
K key)
CacheFunction interface; use Cache.get(K) or
Cache.getUnchecked(K) instead.
apply in interface Function<K,V>apply in interface Cache<K,V>
public void invalidate(@Nullable
Object key)
Cachekey, possibly asynchronously, so that a future
invocation of get(key) will result in a cache miss and reload.
invalidate in interface Cache<K,V>public void invalidateAll()
Cache
invalidateAll in interface Cache<K,V>public long size()
Cache
size in interface Cache<K,V>public CacheStats stats()
Cache
stats in interface Cache<K,V>public ConcurrentMap<K,V> asMap()
CacheOperations on the returned map will never cause new values to be loaded into the cache. So,
unlike Cache.get(K) and Cache.getUnchecked(K), this map's get method will
always return null for a key that is not already cached.
asMap in interface Cache<K,V>public void cleanUp()
Cache
cleanUp in interface Cache<K,V>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||