public abstract class AbstractCacheMap<K,V> extends java.lang.Object implements Cache<K,V>
prune
strategyReentrantReadWriteLock
to synchronize access.
Since upgrading from a read lock to the write lock is not possible,
be careful withing get(Object)
method.Modifier and Type | Field and Description |
---|---|
protected java.util.Map<K,jodd.cache.AbstractCacheMap.CacheObject<K,V>> |
cacheMap |
protected int |
cacheSize |
protected boolean |
existCustomTimeout
Identifies if objects has custom timeouts.
|
protected int |
hitCount |
protected int |
missCount |
protected long |
timeout |
Constructor and Description |
---|
AbstractCacheMap() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears current cache.
|
protected jodd.cache.AbstractCacheMap.CacheObject<K,V> |
createCacheObject(K key,
V object,
long timeout) |
V |
get(K key)
Retrieves an object from the cache.
|
int |
getHitCount()
Returns hit count.
|
int |
getMissCount()
Returns miss count.
|
boolean |
isEmpty()
Returns
true if cache is empty. |
boolean |
isFull()
Returns
true if max cache capacity has been reached
only if cache is size limited. |
protected boolean |
isPruneExpiredActive()
Returns
true if prune of expired objects should be invoked. |
protected boolean |
isReallyFull(K key) |
int |
limit()
Returns cache size or
0 if there is no size limit. |
protected void |
onRemove(K key,
V cachedObject)
Callback called on item removal.
|
int |
prune()
Prunes objects from cache and returns the number of removed objects.
|
protected abstract int |
pruneCache()
Prune implementation.
|
void |
put(K key,
V object)
Adds an object to the cache with default timeout.
|
void |
put(K key,
V object,
long timeout)
Adds an object to the cache with specified timeout after which it becomes expired.
|
V |
remove(K key)
Removes an object from the cache and returns removed value of
null
if object was not in the cache or was expired. |
int |
size()
Returns current cache size.
|
java.util.Map<K,V> |
snapshot(boolean peek)
Creates a snapshot from current cache values.
|
long |
timeout()
Returns default cache timeout or
0 if it is not set. |
protected int cacheSize
protected long timeout
protected boolean existCustomTimeout
protected int hitCount
protected int missCount
public int limit()
0
if there is no size limit.public long timeout()
0
if it is not set.
Timeout can be set individually for each object.protected boolean isPruneExpiredActive()
true
if prune of expired objects should be invoked.
For internal use.public void put(K key, V object)
put
in interface Cache<K,V>
Cache.put(Object, Object, long)
public void put(K key, V object, long timeout)
Cache.prune()
is invoked to make room for new object.
Cached value must be non-null.protected jodd.cache.AbstractCacheMap.CacheObject<K,V> createCacheObject(K key, V object, long timeout)
public int getHitCount()
public int getMissCount()
public V get(K key)
null
if object
is not longer in cache or if it is expired.protected abstract int pruneCache()
public final int prune()
public boolean isFull()
true
if max cache capacity has been reached
only if cache is size limited.protected boolean isReallyFull(K key)
public V remove(K key)
null
if object was not in the cache or was expired.public boolean isEmpty()
true
if cache is empty.public java.util.Map<K,V> snapshot(boolean peek)
Copyright © 2003-present Jodd Team