|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@Beta public interface Cache<K,V>
A semi-persistent mapping from keys to values. Values are automatically loaded by the cache, and are stored in the cache until either evicted or manually invalidated.
All methods other than get(K)
and getUnchecked(K)
are optional.
When evaluated as a Function
, a cache yields the same result as invoking getUnchecked(K)
.
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 |
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 interface com.google.common.base.Function |
---|
equals |
Method Detail |
---|
V get(K key) throws ExecutionException
null
.
ExecutionException
- if a checked exception was thrown while loading the response
UncheckedExecutionException
- if an unchecked exception was thrown while loading the
response
ExecutionError
- if an error was thrown while loading the responseV getUnchecked(K key)
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 get(K)
method should be preferred for cache loaders which throw checked exceptions.
UncheckedExecutionException
- if an exception was thrown while loading the response,
regardless of whether the exception was checked or unchecked
ExecutionError
- if an error was thrown while loading the responseV apply(K key)
Function
interface; use get(K)
or
getUnchecked(K)
instead.
apply
in interface Function<K,V>
UncheckedExecutionException
- if an exception was thrown while loading the response,
regardless of whether the exception was checked or unchecked
ExecutionError
- if an error was thrown while loading the responsevoid invalidate(Object key)
key
, possibly asynchronously, so that a future
invocation of get(key)
will result in a cache miss and reload.
UnsupportedOperationException
- if this operation is not supported by the cache
implementationvoid invalidateAll()
UnsupportedOperationException
- if this operation is not supported by the cache
implementationlong size()
UnsupportedOperationException
- if this operation is not supported by the cache
implementationCacheStats stats()
UnsupportedOperationException
- if this operation is not supported by the cache
implementationConcurrentMap<K,V> asMap()
Operations on the returned map will never cause new values to be loaded into the cache. So,
unlike get(K)
and getUnchecked(K)
, this map's get
method will
always return null
for a key that is not already cached.
UnsupportedOperationException
- if this operation is not supported by the cache
implementationvoid cleanUp()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |