public interface Cache<K,V>
#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.
Modifier and Type | Method and Description |
---|---|
V |
getIfPresent(Object key)
Returns the value associated with
key in this cache, or null if there is no
cached value for key . |
void |
put(K key,
V value)
Associates
value with key in this cache. |
V getIfPresent(Object key)
key
in this cache, or null
if there is no
cached value for key
.void put(K key, V value)
value
with key
in this cache. If the cache previously contained a
value associated with key
, the old value is replaced by value
.
Prefer #get(Object, Callable)
when using the conventional "if cached, return;
otherwise create, cache and return" pattern.
Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.