public abstract class Cache
extends java.lang.Object
com.eibus.cache.CacheKey
,
com.eibus.cache.CacheValue
Constructor and Description |
---|
Cache(long maxSize) |
Cache(long maxSize,
java.util.Hashtable<?,?> initValues) |
Cache(long maxSize,
java.util.Map<K,V> initValues,
java.util.Comparator<K> comparator) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
cleanCacheValueInternal(CacheKey key,
CacheValue value)
Release all claimed resources.
|
protected void |
finalize() |
CacheValue |
get(CacheKey key)
Get the object (and load when not in the cache).
|
static <K extends CacheKey & java.lang.Comparable<K>> |
getKeyComparator(java.lang.Class<K> theClass) |
protected java.util.Enumeration |
getKeys()
Returns an thread-safe enumeration the key's in the cache.
|
protected <K extends CacheKey> |
getKeys(K fromKey,
boolean fromInclusive,
K toKey,
boolean toInclusive)
Returns a thread-safe read only view to the specified key range in the cache.
|
protected long |
getSize() |
void |
invalidate(CacheKey key)
Invalidate the key (dirty event, pruning), when all locks are released,
the value will be cleaned.
|
void |
invalidate(CacheValue value)
Invalidate the value (pruning), when all locks are released,
the value will be cleaned.
|
protected abstract CacheValue |
loadCacheValueInternal(CacheKey key)
Load the object from an external source.
|
protected void |
notifyCacheHit()
Extension point for sub-classes that want to maintain statistics about cache hits and misses.
|
protected void |
notifyCacheHit(CacheKey key)
Extension point for sub-classes that want to maintain statistics about
cache hits.
|
protected void |
notifyCacheMiss()
Extension point for sub-classes that want to maintain statistics about cache hits and misses.
|
protected void |
notifyCacheMiss(CacheKey key)
Extension point for sub-classes that want to maintain statistics about
cache misses.
|
protected void |
prune()
Prune the cache: invalidate Least-Recently-Used objects until size <= maxSize.
|
void |
releaseValue(CacheValue value)
Release the value
|
void |
reset()
Reset the cache by removing all cached data, and releasing all claimed resources.
|
void |
setExpiration(long expiration)
Data will be invalidated within a period of time (To be used when cache updating is too expensive
or not possible, e.g.
|
void |
setMaxIdleTime(long maxIdleTime)
Free resources when an entry is not used in a period of time.
|
void |
setMaxSize(long maxSize)
Sets the maximum cacheSize.
|
public Cache(long maxSize)
public Cache(long maxSize, java.util.Hashtable<?,?> initValues)
public Cache(long maxSize, java.util.Map<K,V> initValues, java.util.Comparator<K> comparator)
public static <K extends CacheKey & java.lang.Comparable<K>> java.util.Comparator<K> getKeyComparator(java.lang.Class<K> theClass)
public void reset()
protected java.util.Enumeration getKeys()
protected <K extends CacheKey> java.util.Collection<K> getKeys(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
public void setMaxSize(long maxSize)
maxSize
- public CacheValue get(CacheKey key) throws CacheLoadingException
readLock
- key
- CacheLoadingException
protected void notifyCacheMiss()
protected void notifyCacheHit()
protected void notifyCacheMiss(CacheKey key)
notifyCacheMiss()
w.r.t parameter.
Now, sub-classes know for which key it was a cache miss.cache
- key for which a miss is to be notifiedprotected void notifyCacheHit(CacheKey key)
notifyCacheHit()
w.r.t parameter.
Now, sub-classes know for which key it was a cache hit.cache
- key for which a hit is to be notifiedpublic void releaseValue(CacheValue value)
value
- protected abstract void cleanCacheValueInternal(CacheKey key, CacheValue value)
key
- value
- protected abstract CacheValue loadCacheValueInternal(CacheKey key) throws CacheLoadingException
key
- CacheLoadingException
protected long getSize()
public void invalidate(CacheValue value)
key
- public void invalidate(CacheKey key) throws CorruptCacheError
key
- CorruptCacheError
protected void prune()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
Object.finalize()
public void setMaxIdleTime(long maxIdleTime)
maxIdleTime
- maximum idle time in millis.public void setExpiration(long expiration)
expiration
- expiry period in millis.