K - the keyV - the valuepublic class DefaultLRUCachingMap<K,V> extends Object implements LRUCachingMap<K,V>, Serializable
LRUCachingMap,
Serialized Form| Constructor and Description |
|---|
DefaultLRUCachingMap()
Default constructor, using DefaultLRUCachingMapConfiguration and DefaultMemoryValueManager.
|
DefaultLRUCachingMap(LRUCachingMapConfiguration configuration,
ValueManager<K,V> valueManager)
Constructor.
|
| 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.
|
protected void |
extend(K key,
long extendTime,
int maxExtendCount) |
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...
|
protected AbstractValueWrapper<K,V> |
getValueWrapper(K key)
Gets the "AbstractValueWrapper<K,V>" for the value.
|
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.
|
public DefaultLRUCachingMap()
public DefaultLRUCachingMap(LRUCachingMapConfiguration configuration, ValueManager<K,V> valueManager) throws NullPointerException
getConfiguration().getCleanupIntervalTime()>0 than an CleanupTimerRunnable will be created inside a thread to do periodically cleanup. configuration - the confiuration.valueManager - valueManager the instance of a ValueManager which handles how the values is stored.NullPointerException - if either configuration or valueManager is null.LRUCachingMapConfiguration.getCleanupIntervalTime(),
CleanupTimerRunnablepublic LRUCachingMapConfiguration getConfiguration()
LRUCachingMapgetConfiguration in interface LRUCachingMap<K,V>DefaultLRUCachingMapConfigurationpublic final Logger getLogger()
LRUCachingMapgetLogger in interface LRUCachingMap<K,V>public final ValueManager<K,V> getValueManager()
LRUCachingMapgetValueManager in interface LRUCachingMap<K,V>public final int size()
LRUCachingMapsize in interface LRUCachingMap<K,V>public final int removeAll()
LRUCachingMapremoveAll in interface LRUCachingMap<K,V>LRUCachingMap.size()public final int reload()
LRUCachingMapreload in interface LRUCachingMap<K,V>LRUCachingMap.isPersisted()public V put(K key, V value) throws NullPointerException
LRUCachingMapput in interface LRUCachingMap<K,V>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)public final void restoreCacheElement(K key, AbstractValueWrapper<K,V> valueWrapper, Date expireDateTime)
LRUCachingMaprestoreCacheElement in interface LRUCachingMap<K,V>key - the reconstructed keyvalueWrapper - the value wrapped.expireDateTime - the datetime for when the key expires.ValueManager.restore(LRUCachingMap)public final V get(K key) throws NullPointerException
LRUCachingMapnull returned.get in interface LRUCachingMap<K,V>key - the keynull is returned.NullPointerException - if key is null.LRUCachingMapConfigurationpublic final V peek(K key) throws NullPointerException
LRUCachingMappeek in interface LRUCachingMap<K,V>key - the keynull.NullPointerException - if key is null.public final boolean isExpired(K key) throws NullPointerException
LRUCachingMapisExpired in interface LRUCachingMap<K,V>key - the keytrue if the key is expired or the key is not found, otherwise false.NullPointerException - if key is null.public final Date getStoreDateTime(K key) throws NullPointerException
LRUCachingMapgetStoreDateTime in interface LRUCachingMap<K,V>key - the keynull is returned, otherwise the new Date(long) for when the key was registered in the cache.NullPointerException - if key is null.public final V remove(K key) throws NullPointerException
LRUCachingMapremove in interface LRUCachingMap<K,V>key - the keyNullPointerException - if key is null.ValueManager.removeValue(AbstractValueWrapper)public final boolean exists(K key) throws NullPointerException
LRUCachingMapexists in interface LRUCachingMap<K,V>key - the keytrue if key is exists and is not expired, otherwise false.NullPointerException - if key is null.LRUCachingMap.get(Object)public final Iterator<K> getKeys()
LRUCachingMapgetKeys in interface LRUCachingMap<K,V>Iteratorpublic void extend(K key, long extendTime) throws NullPointerException, IllegalArgumentException
LRUCachingMapextend in interface LRUCachingMap<K,V>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.IllegalArgumentExceptionLRUCachingMapConfiguration.getMaxExtendCount()public void extend(K key) throws NullPointerException, IllegalArgumentException
LRUCachingMapextend in interface LRUCachingMap<K,V>key - the keyNullPointerException - if key is null.IllegalArgumentExceptionLRUCachingMapConfiguration.getMaxExtendCount(),
LRUCachingMapConfiguration.getExtendTime()protected final void extend(K key, long extendTime, int maxExtendCount) throws NullPointerException, IllegalArgumentException
public final Date getExpirationDateTime(K key) throws NullPointerException
LRUCachingMapgetExpirationDateTime in interface LRUCachingMap<K,V>key - the keynull.NullPointerException - if key is null.public final TimeSpan getExpirationTimeSpan(K key) throws NullPointerException
LRUCachingMapgetExpirationTimeSpan in interface LRUCachingMap<K,V>key - theTimeSpan.ZERO is returned.NullPointerException - if key s null.TimeSpan.ZEROpublic final int cleanup()
LRUCachingMapcleanup in interface LRUCachingMap<K,V>LRUCachingMapConfiguration.getExpireTime(),
LRUCachingMapConfiguration.getMaxSize(),
LRUCachingMap.getNextToExpire(),
ValueManager.flush(),
LRUCachingMap.getValueManager()public final TimeSpan getExpirationTimeSpan()
LRUCachingMapgetExpirationTimeSpan in interface LRUCachingMap<K,V>public final K getNextToExpire()
LRUCachingMapgetNextToExpire in interface LRUCachingMap<K,V>null is returned.public final boolean isPersisted()
LRUCachingMapisPersisted in interface LRUCachingMap<K,V>true if value is stored in a persistence storage an can be recovered after "reboot", otherwise false.ValueManager.isPersisted()public final Date getLastCleanupDateTime()
LRUCachingMapgetLastCleanupDateTime in interface LRUCachingMap<K,V>protected final AbstractValueWrapper<K,V> getValueWrapper(K key)
key - the keyCopyright © 2016. All rights reserved.