|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.common.cache.AbstractCache<K,V>
@Beta public abstract class AbstractCache<K,V>
This class provides a skeletal implementation of the Cache
interface to minimize the
effort required to implement this interface.
To implement a cache, the programmer needs only to extend this class and provide an
implementation for the get
method. This implementation throws an
UnsupportedOperationException
on calls to size()
, invalidate(java.lang.Object)
,
invalidateAll()
, stats()
, and asMap()
. The methods
getUnchecked(K)
and apply(K)
are implemented in terms of Cache.get(K)
. The method
cleanUp()
is a no-op.
Nested Class Summary | |
---|---|
static class |
AbstractCache.SimpleStatsCounter
A thread-safe AbstractCache.StatsCounter implementation for use by Cache implementors. |
static interface |
AbstractCache.StatsCounter
Accumulates statistics during the operation of a Cache for presentation by Cache.stats() . |
Constructor Summary | |
---|---|
protected |
AbstractCache()
Constructor for use by subclasses. |
Method Summary | |
---|---|
V |
apply(K key)
Discouraged. |
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. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.google.common.cache.Cache |
---|
get |
Methods inherited from interface com.google.common.base.Function |
---|
equals |
Constructor Detail |
---|
protected AbstractCache()
Method Detail |
---|
public V getUnchecked(K key)
Cache
Cache.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>
public final V apply(K key)
Cache
Function
interface; use Cache.get(K)
or
Cache.getUnchecked(K)
instead.
apply
in interface Function<K,V>
apply
in interface Cache<K,V>
public void cleanUp()
Cache
cleanUp
in interface Cache<K,V>
public long size()
Cache
size
in interface Cache<K,V>
public void invalidate(Object key)
Cache
key
, 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 CacheStats stats()
Cache
stats
in interface Cache<K,V>
public ConcurrentMap<K,V> asMap()
Cache
Operations 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>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |