Package com.sun.appserv.util.cache
Class MultiLruCache
java.lang.Object
com.sun.appserv.util.cache.BaseCache
com.sun.appserv.util.cache.MultiLruCache
- All Implemented Interfaces:
Cache
- Direct Known Subclasses:
BoundedMultiLruCache
MultiLruCache -- in-memory bounded LRU cache with multiple LRU lists
Underlying Hashtable is made into logical segments, with each segment
having its own LRU list.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.sun.appserv.util.cache.BaseCache
BaseCache.CacheItem -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected int[]static final intstatic final 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 snapshotprotected voidcache has reached threshold so trim its size.protected voidvoidinit(int maxCapacity, Properties props) initialize the LRU 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 cacheprotected BaseCache.CacheItemtrimLru(int segment) remove an lru item from one of the LRU listsMethods 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, hash, incrementAddCount, incrementEntryCount, incrementHitCount, incrementMissCount, incrementOverflowCount, incrementRefreshCount, incrementRemovalCount, init, isEmpty, isThresholdReached, keys, loadValue, notifyRefresh, put, put, remove, remove, remove, removeAll, trimExpiredEntries, trimItem, values, waitRefresh
-
Field Details
-
LRU_HEAD
public static final int LRU_HEAD- See Also:
-
LRU_TAIL
public static final int LRU_TAIL- See Also:
-
DEFAULT_HASHTABLE_SEGMENT_SIZE
public static final int DEFAULT_HASHTABLE_SEGMENT_SIZE- See Also:
-
listsLength
protected int[] listsLength
-
-
Constructor Details
-
MultiLruCache
public MultiLruCache()
-
-
Method Details
-
init
initialize the LRU cache -
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
remove an lru item from one of the LRU lists- Parameters:
the- LRU segment index to trim- Returns:
- the item that was successfully trimmed
-
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
-
handleOverflow
protected void handleOverflow()cache has reached threshold so trim its size. subclasses are expected to provide a robust cache replacement algorithm.- Overrides:
handleOverflowin classBaseCache
-
incrementTrimIndex
protected void incrementTrimIndex() -
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
get the stats snapshot
-