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
public class MultiLruCache extends BaseCache
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
Fields Modifier and Type Field Description static int
DEFAULT_HASHTABLE_SEGMENT_SIZE
protected int[]
listsLength
static int
LRU_HEAD
static int
LRU_TAIL
-
Fields inherited from class com.sun.appserv.util.cache.BaseCache
bucketLocks, buckets, entryCount, hitCount, listeners, maxBuckets, maxEntries, missCount, refreshFlags, removalCount, threshold
-
-
Constructor Summary
Constructors Constructor Description MultiLruCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BaseCache.CacheItem
createItem(int hashCode, Object key, Object value, int size)
create new itemObject
getStatByName(String key)
get the desired statistic counterMap
getStats()
get the stats snapshotprotected void
handleOverflow()
cache has reached threshold so trim its size.protected void
incrementTrimIndex()
void
init(int maxCapacity, Properties props)
initialize the LRU cacheprotected void
itemAccessed(BaseCache.CacheItem item)
this item is accessedprotected BaseCache.CacheItem
itemAdded(BaseCache.CacheItem item)
this item is just added to the cacheprotected void
itemRefreshed(BaseCache.CacheItem item, int oldSize)
item value has been refreshedprotected void
itemRemoved(BaseCache.CacheItem item)
item value has been removed from the cacheprotected BaseCache.CacheItem
trimLru(int segment)
remove an lru item from one of the LRU lists-
Methods 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 Detail
-
LRU_HEAD
public static final int LRU_HEAD
- See Also:
- Constant Field Values
-
LRU_TAIL
public static final int LRU_TAIL
- See Also:
- Constant Field Values
-
DEFAULT_HASHTABLE_SEGMENT_SIZE
public static final int DEFAULT_HASHTABLE_SEGMENT_SIZE
- See Also:
- Constant Field Values
-
listsLength
protected int[] listsLength
-
-
Method Detail
-
init
public void init(int maxCapacity, Properties props) throws Exception
initialize the LRU cache
-
createItem
protected BaseCache.CacheItem createItem(int hashCode, Object key, Object value, int size)
create new item- Overrides:
createItem
in classBaseCache
- Parameters:
hashCode
- for the entrykey
-Object
keyvalue
-Object
valuesize
- size in bytes of the item subclasses may override to provide their own CacheItem extensions e.g. one that permits persistence.
-
trimLru
protected BaseCache.CacheItem trimLru(int segment)
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
protected BaseCache.CacheItem itemAdded(BaseCache.CacheItem item)
this item is just added to the cache
-
itemAccessed
protected void itemAccessed(BaseCache.CacheItem item)
this item is accessed- Overrides:
itemAccessed
in classBaseCache
- Parameters:
item
-CacheItem
accessed Cache bucket is already synchronized by the caller
-
itemRefreshed
protected void itemRefreshed(BaseCache.CacheItem item, int oldSize)
item value has been refreshed- Overrides:
itemRefreshed
in classBaseCache
- Parameters:
item
-CacheItem
that was refreshedoldSize
- size of the previous value that was refreshed Cache bucket is already synchronized by the caller
-
itemRemoved
protected void itemRemoved(BaseCache.CacheItem item)
item value has been removed from the cache- Overrides:
itemRemoved
in classBaseCache
- Parameters:
item
-CacheItem
that 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:
handleOverflow
in classBaseCache
-
incrementTrimIndex
protected void incrementTrimIndex()
-
getStatByName
public Object getStatByName(String key)
get the desired statistic counter- Specified by:
getStatByName
in interfaceCache
- Overrides:
getStatByName
in classBaseCache
- Parameters:
key
- to corresponding stat- Returns:
- an Object corresponding to the stat See also: Constant.java for the key
-
-