Interface Cache<K,V>
- All Known Subinterfaces:
LoadingCache<K,
V>
public interface Cache<K,V>
A semi-persistent mapping from keys to values. Cache entries are manually added using
#get(Object, Callable)
or put(Object, Object)
, and are stored in the cache until
either evicted or manually invalidated.
Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.
Note that while this class is still annotated as Beta
, the API is frozen from a
consumer's standpoint. In other words existing methods are all considered non-Beta
and
won't be changed without going through an 18 month deprecation cycle; however new methods may be
added at any time.
- Since:
- 10.0
- Author:
- Charles Fry
-
Method Summary
-
Method Details
-
getIfPresent
Returns the value associated withkey
in this cache, ornull
if there is no cached value forkey
.- Since:
- 11.0
-
put
Associatesvalue
withkey
in this cache. If the cache previously contained a value associated withkey
, the old value is replaced byvalue
.Prefer
#get(Object, Callable)
when using the conventional "if cached, return; otherwise create, cache and return" pattern.- Since:
- 11.0
-