K - The type of the keyV - The type of the valuepublic class MemoryCache<K,V> extends AbstractCache<K,V> implements WritableCache<K,V>
Cache implementation.| Constructor and Description |
|---|
MemoryCache(ValueRetriever<K,V> valueRetriever)
Creates a new memory-based cache.
|
MemoryCache(ValueRetriever<K,V> valueRetriever,
int cacheSize)
Creates a new memory-based cache.
|
MemoryCache(ValueRetriever<K,V> valueRetriever,
Map<K,CacheItem<V>> storage)
Creates a new memory cache, using the given map as storage backend.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all cached values.
|
boolean |
contains(K key)
Checks whether this cache contains a value for the given key.
|
V |
get(K key)
Returns a value from the cache.
|
void |
put(K key,
V value)
Stores the given key-value pair in this cache without updating any
backends.
|
void |
remove(K key)
Removes the cached value for the given key.
|
static void |
setLogger(Logger logger)
Sets the logger to use.
|
int |
size()
Returns the number of currently cached values.
|
retrieveValuepublic MemoryCache(ValueRetriever<K,V> valueRetriever)
valueRetriever - The value retrieverpublic MemoryCache(ValueRetriever<K,V> valueRetriever, int cacheSize)
valueRetriever - The value retrievercacheSize - The number of values to cachepublic static void setLogger(Logger logger)
logger - The logger to usepublic void clear()
Cacheclear in interface Cache<K,V>Cache.clear()public boolean contains(K key)
CacheValueRetriever will be made! Note that it is legal
for this method to return true but for a following
Cache.get(Object) to return null (see WeakHashMap) for
a possible explanation).contains in interface Cache<K,V>key - The key to check fortrue if this cache contains a value for the given key,
false otherwiseCache.contains(java.lang.Object)public V get(K key) throws CacheException
CacheValueRetriever is asked to
retrieve the value. This operation may result in a CacheException
to be thrown. The returned value is cached if it is non-null.get in interface Cache<K,V>key - The key to get the value fornull if there is no value for
the keyCacheException - if an error occurs retrieving the value from the underlying
ValueRetrieverCache.get(java.lang.Object)public void remove(K key)
public void put(K key, V value)
put in interface WritableCache<K,V>key - The key of the pairvalue - The value of the pairCopyright © 2026. All rights reserved.