K
- The type of the key.V
- The type of the value.public interface Cache<K,V>
K
, V
),
and are stored in the cache until either evicted or manually removed.
After storing a value, it can be accessed using get(K
).Modifier and Type | Method and Description |
---|---|
boolean |
contains(K key)
Returns
True if the cache contains a entry with the key,
or False if there is none. |
Optional<V> |
get(K key)
Returns the value associated with
key in this cache,
or empty if there is no cached value for key . |
boolean |
isEmpty()
Returns
True if the cache is empty, or False
if there's at least a entry stored in cache. |
void |
put(K key,
V value)
Associates value with key in this cache.
|
void |
remove(K key)
Discards any cached value for this key.
|
void |
removeAll()
Discards all entries in the cache.
|
long |
size()
Returns the number of entries in this cache.
|
CacheStats |
stats()
Returns a current snapshot of this cache's cumulative statistics, or a set of default values if
the cache is not recording statistics.
|
void put(K key, V value)
key
- The key to be used as index.value
- The value to be stored.Optional<V> get(K key)
key
in this cache,
or empty if there is no cached value for key
.key
- The key to look for.void remove(K key)
key
- The key to be discarded.void removeAll()
boolean contains(K key)
True
if the cache contains a entry with the key,
or False
if there is none.key
- The key to be verified.True
if the key is present.long size()
boolean isEmpty()
True
if the cache is empty, or False
if there's at least a entry stored in cache.True
if is empty.CacheStats stats()
Copyright © 2007–2024. All rights reserved.