|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjodd.cache.AbstractCacheMap<K,V>
public abstract class AbstractCacheMap<K,V>
Default implementation of timed and size cache map. Implementations should:
prune strategy
| Field Summary | |
|---|---|
protected java.lang.Object |
cacheLock
|
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 long |
timeout
|
| Constructor Summary | |
|---|---|
AbstractCacheMap()
|
|
| Method Summary | |
|---|---|
void |
clear()
Clears current cache. |
V |
get(K key)
Retrieves an object from the cache. |
int |
getCacheSize()
Returns cache size or 0 if there is no size limit. |
long |
getCacheTimeout()
Returns default cache timeout or 0 if it is not set. |
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. |
java.util.Iterator<V> |
iterator()
Returns iterator over non-expired values. |
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. |
void |
remove(K key)
Removes an object from the cache. |
int |
size()
Returns current cache size. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Map<K,jodd.cache.AbstractCacheMap.CacheObject<K,V>> cacheMap
protected final java.lang.Object cacheLock
protected int cacheSize
protected long timeout
protected boolean existCustomTimeout
| Constructor Detail |
|---|
public AbstractCacheMap()
| Method Detail |
|---|
public int getCacheSize()
0 if there is no size limit.
getCacheSize in interface Cache<K,V>public long getCacheTimeout()
0 if it is not set.
Timeout can be set individually for each object.
getCacheTimeout in interface Cache<K,V>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.
put in interface Cache<K,V>public V get(K key)
null if object
is not longer in cache or if it is expired.
get in interface Cache<K,V>public java.util.Iterator<V> iterator()
iterator in interface Cache<K,V>protected abstract int pruneCache()
public final int prune()
prune in interface Cache<K,V>public boolean isFull()
true if max cache capacity has been reached
only if cache is size limited.
isFull in interface Cache<K,V>public void remove(K key)
remove in interface Cache<K,V>public void clear()
clear in interface Cache<K,V>public int size()
size in interface Cache<K,V>public boolean isEmpty()
true if cache is empty.
isEmpty in interface Cache<K,V>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||