K
- uniqueKey for Value V, not nullV
- value, not null.public interface LRUCachingMap<K,V>
null
and implement "equals(Object)" and "hashcode()" methods.null
ValueManager
,
LRUCachingMapConfiguration
Modifier and Type | Method and Description |
---|---|
int |
cleanup()
Cleanup the cache to uphold expire time and maxSize.
If maxSize is exceeded than the oldest must be remove until maxSize threshold is below limit. This method must call the value manager flush method when is done. |
boolean |
exists(K key)
Validates if the key exists in the map, if its expired the key/value pair is removed.
|
void |
extend(K key)
Extends a key expire time with "getExtendTime()"
|
void |
extend(K key,
long extendTime)
Extends a key expire time with an extendTime still, and the "getMaxExtendCount()" will have no effect.
|
V |
get(K key)
Gets a Value for a corresponding Key.
|
LRUCachingMapConfiguration |
getConfiguration()
Gets the configuration instance
|
Date |
getExpirationDateTime(K key)
When do the key expire.
|
TimeSpan |
getExpirationTimeSpan()
The timespan in milliseconds, between the oldest and youngest key
|
TimeSpan |
getExpirationTimeSpan(K key)
Gets the expiration timespan for a key.
|
Iterator<K> |
getKeys()
Get the keys in a iterator.
|
Date |
getLastCleanupDateTime()
Gets the last time the cleanup method was performed
|
Logger |
getLogger()
A logger for getting metrics on how the caching is performing.
|
K |
getNextToExpire()
Gets the next key which has the lowest expiration date time.
|
Date |
getStoreDateTime(K key)
When was the Key stored in the cache.
|
ValueManager<K,V> |
getValueManager()
The manager class which handles the wrapped values, so it either can be stored in memory, file, db, etc...
|
boolean |
isExpired(K key)
Is the key is expired.
|
boolean |
isPersisted()
Determine if ValueManager persists the the values.
|
V |
peek(K key)
Peek at the value with the key, but it do not remove the key/value if it is expired or extend its expiration datetime.
|
V |
put(K key,
V value)
Puts a key value pair in the cache.
|
int |
reload()
Will perform a complete reload of the cached elements if they are persisted, if not persisted nothing will happend.
|
V |
remove(K key)
Removes the key and its value form the cache.
|
int |
removeAll()
Remove all key/values from the cache, and delete the values if persisted.
|
void |
restoreCacheElement(K key,
AbstractValueWrapper<K,V> valueWrapper,
Date expireDateTime)
Used by ValueManager.initialize(LRUCachingMap) to initialize the caching structure, after an reload.
|
int |
size()
The number of unique keys in the cache.
|
Logger getLogger()
int size()
int removeAll()
size()
V put(K key, V value) throws NullPointerException
key
- the keyvalue
- the value if the value is null
the key is removed.null
.NullPointerException
- if the key is null
.LRUCachingMapConfiguration.getExtendTime()
,
LRUCachingMapConfiguration.getMaxExtendCount()
,
LRUCachingMapConfiguration.getMaxSize()
,
ValueManager.storeValue(AbstractValueWrapper, Object, Object, Date)
,
ValueManager.constructWrapper(Object, Object)
void restoreCacheElement(K key, AbstractValueWrapper<K,V> valueWrapper, Date expireDateTime)
key
- the reconstructed keyvalueWrapper
- the value wrapped.expireDateTime
- the datetime for when the key expires.ValueManager.restore(LRUCachingMap)
int reload()
isPersisted()
V get(K key) throws NullPointerException
null
returned.key
- the keynull
is returned.NullPointerException
- if key is null
.LRUCachingMapConfiguration
V peek(K key) throws NullPointerException
key
- the keynull
.NullPointerException
- if key is null
.Date getExpirationDateTime(K key) throws NullPointerException
key
- the keynull
.NullPointerException
- if key is null
.TimeSpan getExpirationTimeSpan(K key) throws NullPointerException
key
- theTimeSpan.ZERO
is returned.NullPointerException
- if key s null
.TimeSpan.ZERO
boolean isExpired(K key) throws NullPointerException
key
- the keytrue
if the key is expired or the key is not found, otherwise false
.NullPointerException
- if key is null
.Date getStoreDateTime(K key) throws NullPointerException
key
- the keynull
is returned, otherwise the new Date(long) for when the key was registered in the cache.NullPointerException
- if key is null
.V remove(K key) throws NullPointerException
key
- the keyNullPointerException
- if key is null
.ValueManager.removeValue(AbstractValueWrapper)
TimeSpan getExpirationTimeSpan()
ValueManager<K,V> getValueManager()
boolean exists(K key) throws NullPointerException
key
- the keytrue
if key is exists and is not expired, otherwise false
.NullPointerException
- if key is null
.get(Object)
Iterator<K> getKeys()
Iterator
LRUCachingMapConfiguration getConfiguration()
DefaultLRUCachingMapConfiguration
void extend(K key, long extendTime) throws NullPointerException
key
- the keyextendTime
- how many milliseconds the keys expire time must be extended, must be greather than zero, otherwise nothing happens.NullPointerException
- if key is null
.LRUCachingMapConfiguration.getMaxExtendCount()
void extend(K key) throws NullPointerException
key
- the keyNullPointerException
- if key is null
.LRUCachingMapConfiguration.getMaxExtendCount()
,
LRUCachingMapConfiguration.getExtendTime()
K getNextToExpire()
null
is returned.int cleanup()
LRUCachingMapConfiguration.getExpireTime()
,
LRUCachingMapConfiguration.getMaxSize()
,
getNextToExpire()
,
ValueManager.flush()
,
getValueManager()
boolean isPersisted()
true
if value is stored in a persistence storage an can be recovered after "reboot", otherwise false
.ValueManager.isPersisted()
Date getLastCleanupDateTime()
Copyright © 2016. All rights reserved.