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)orput(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 considerednon-Betaand 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description VgetIfPresent(Object key)Returns the value associated withkeyin this cache, ornullif there is no cached value forkey.voidput(K key, V value)Associatesvaluewithkeyin this cache.
-
-
-
Method Detail
-
getIfPresent
V getIfPresent(Object key)
Returns the value associated withkeyin this cache, ornullif there is no cached value forkey.- Since:
- 11.0
-
put
void put(K key, V value)
Associatesvaluewithkeyin 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
-
-