Package com.sun.appserv.util.cache
Class LruCache
java.lang.Object
com.sun.appserv.util.cache.BaseCache
com.sun.appserv.util.cache.LruCache
- All Implemented Interfaces:
Cache
LRUCache
in-memory bounded cache with an LRU list
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classdefault CacheItem class implementationNested classes/interfaces inherited from class com.sun.appserv.util.cache.BaseCache
BaseCache.CacheItem -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected LruCache.LruCacheItemprotected booleanprotected intstatic final longprotected LruCache.LruCacheItemprotected longprotected intFields inherited from class com.sun.appserv.util.cache.BaseCache
bucketLocks, buckets, entryCount, hitCount, listeners, maxBuckets, maxEntries, missCount, refreshFlags, removalCount, threshold -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BaseCache.CacheItemcreateItem(int hashCode, Object key, Object value, int size) create new itemgetStatByName(String key) get the desired statistic countergetStats()get the stats snapshotvoidinit(int maxEntries, long timeout, float loadFactor, Properties props) initialize the cacheprotected voidthis item is accessedprotected BaseCache.CacheItemitemAdded(BaseCache.CacheItem item) /** this item is just added to the cacheprotected voiditemRefreshed(BaseCache.CacheItem item, int oldSize) item value has been refreshedprotected voiditem value has been removed from the cachevoidsetTimeout(long timeout) sets the timeout valuevoidtrimExpiredEntries(int maxCount) trim the expired entries from the cache.protected BaseCache.CacheItemtrimLru(long currentTime) trim one item from the LRU listMethods inherited from class com.sun.appserv.util.cache.BaseCache
_put, _remove, _removeItem, add, add, addCacheListener, clear, clearStats, contains, decrementEntryCount, destroy, elements, eq, get, get, getAll, getEntryCount, getIndex, getIndex, handleOverflow, hash, incrementAddCount, incrementEntryCount, incrementHitCount, incrementMissCount, incrementOverflowCount, incrementRefreshCount, incrementRemovalCount, init, init, isEmpty, isThresholdReached, keys, loadValue, notifyRefresh, put, put, remove, remove, remove, removeAll, trimItem, values, waitRefresh
-
Field Details
-
NO_TIMEOUT
public static final long NO_TIMEOUT- See Also:
-
head
-
tail
-
trimCount
protected int trimCount -
listSize
protected int listSize -
timeout
protected long timeout -
defaultMaxEntries
protected int defaultMaxEntries -
isUnbounded
protected boolean isUnbounded
-
-
Constructor Details
-
LruCache
public LruCache()default constructor -
LruCache
public LruCache(int defaultMaxEntries) constructor with specified max entries.- Parameters:
defaultMaxEntries- specifies the default max entries to use when the maxEntries is invalid input: '<'= 0.
-
-
Method Details
-
init
initialize the cache- Parameters:
maxEntries- maximum number of entries expected in the cachetimeout- to be used to trim the expired entriesloadFactor- the load factorprops- opaque list of properties for a given cache implementation
-
setTimeout
public void setTimeout(long timeout) sets the timeout value- Parameters:
timeout- to be used to trim the expired entries
-
createItem
create new item- Overrides:
createItemin classBaseCache- Parameters:
hashCode- for the entrykey-Objectkeyvalue-Objectvaluesize- size in bytes of the item subclasses may override to provide their own CacheItem extensions e.g. one that permits persistence.
-
trimLru
trim one item from the LRU list- Parameters:
currentTime- of this operation- Returns:
- the item trimmed from cache list synchronization is handled by the caller
-
itemAdded
/** this item is just added to the cache -
itemAccessed
this item is accessed- Overrides:
itemAccessedin classBaseCache- Parameters:
item-CacheItemaccessed Cache bucket is already synchronized by the caller
-
itemRefreshed
item value has been refreshed- Overrides:
itemRefreshedin classBaseCache- Parameters:
item-CacheItemthat was refreshedoldSize- size of the previous value that was refreshed Cache bucket is already synchronized by the caller
-
itemRemoved
item value has been removed from the cache- Overrides:
itemRemovedin classBaseCache- Parameters:
item-CacheItemthat was just removed Cache bucket is already synchronized by the caller
-
trimExpiredEntries
public void trimExpiredEntries(int maxCount) trim the expired entries from the cache.- Specified by:
trimExpiredEntriesin interfaceCache- Overrides:
trimExpiredEntriesin classBaseCache- Parameters:
maxCount- maximum number of invalid entries to trim specify Integer.MAX_VALUE to trim all invalid entries This call is to be scheduled by a thread managed by the container. NOTE: this algorithm assumes that all the entries in the cache have identical timeout (otherwise traversing from tail won't be right).
-
getStatByName
get the desired statistic counter- Specified by:
getStatByNamein interfaceCache- Overrides:
getStatByNamein classBaseCache- Parameters:
key- to corresponding stat- Returns:
- an Object corresponding to the stat See also: Constant.java for the key
-
getStats
Description copied from class:BaseCacheget the stats snapshot
-