K
- The type of the key.V
- The type of the value.public class InMemoryCache<K,V> extends Object implements Cache<K,V>
WeakHashMap
.Constructor and Description |
---|
InMemoryCache() |
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. |
static <expectedK,expectedV> |
create()
Create a new instance for a cache in memory.
|
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.
|
public static <expectedK,expectedV> InMemoryCache<expectedK,expectedV> create()
expectedK
- The expected type for the key.expectedV
- The expected type for the value.InMemoryCache
.public void put(K key, V value)
Cache
public Optional<V> get(K key)
Cache
key
in this cache,
or empty if there is no cached value for key
.public void remove(K key)
Cache
public void removeAll()
Cache
public boolean contains(K key)
Cache
True
if the cache contains a entry with the key,
or False
if there is none.public long size()
Cache
Copyright © 2007–2023. All rights reserved.