Modifier and Type | Class and Description |
---|---|
protected static class |
LruCache.LruCacheItem
default CacheItem class implementation
|
BaseCache.CacheItem
Modifier and Type | Field and Description |
---|---|
protected int |
defaultMaxEntries |
protected LruCache.LruCacheItem |
head |
protected boolean |
isUnbounded |
protected int |
listSize |
static long |
NO_TIMEOUT |
protected LruCache.LruCacheItem |
tail |
protected long |
timeout |
protected int |
trimCount |
_rb, bucketLocks, buckets, entryCount, listeners, maxBuckets, refreshFlags, threshold
Constructor and Description |
---|
LruCache()
default constructor
|
LruCache(int defaultMaxEntries)
constructor with specified max entries.
|
Modifier and Type | Method and Description |
---|---|
protected BaseCache.CacheItem |
createItem(int hashCode,
Object key,
Object value,
int size)
create new item
|
Object |
getStatByName(String key)
get the desired statistic counter
|
Map |
getStats()
get the stats snapshot
|
void |
init(int maxEntries,
long timeout,
float loadFactor,
Properties props)
initialize the cache
|
protected void |
itemAccessed(BaseCache.CacheItem item)
this item is accessed
|
protected BaseCache.CacheItem |
itemAdded(BaseCache.CacheItem item)
/**
this item is just added to the cache
|
protected void |
itemRefreshed(BaseCache.CacheItem item,
int oldSize)
item value has been refreshed
|
protected void |
itemRemoved(BaseCache.CacheItem item)
item value has been removed from the cache
|
void |
setTimeout(long timeout)
sets the timeout value
|
void |
trimExpiredEntries(int maxCount)
trim the expired entries from the cache.
|
protected BaseCache.CacheItem |
trimLru(long currentTime)
trim one item from the LRU list
|
_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
public static final long NO_TIMEOUT
protected LruCache.LruCacheItem head
protected LruCache.LruCacheItem tail
protected int trimCount
protected int listSize
protected long timeout
protected int defaultMaxEntries
protected boolean isUnbounded
public LruCache()
public LruCache(int defaultMaxEntries)
defaultMaxEntries
- specifies the default max entries
to use when the maxEntries is <= 0.public void init(int maxEntries, long timeout, float loadFactor, Properties props)
maxEntries
- maximum number of entries expected in the cacheloadFactor
- the load factortimeout
- to be used to trim the expired entriesprops
- opaque list of properties for a given cache implementationa
- generic Exception if the initialization failedpublic void setTimeout(long timeout)
timeout
- to be used to trim the expired entriesprotected BaseCache.CacheItem createItem(int hashCode, Object key, Object value, int size)
createItem
in class BaseCache
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.
protected BaseCache.CacheItem trimLru(long currentTime)
currentTime
- of this operationlist synchronization is handled by the caller
protected BaseCache.CacheItem itemAdded(BaseCache.CacheItem item)
protected void itemAccessed(BaseCache.CacheItem item)
itemAccessed
in class BaseCache
item
- CacheItem
accessed
Cache bucket is already synchronized by the caller
protected void itemRefreshed(BaseCache.CacheItem item, int oldSize)
itemRefreshed
in class BaseCache
item
- CacheItem
that was refreshedoldSize
- size of the previous value that was refreshed
Cache bucket is already synchronized by the callerprotected void itemRemoved(BaseCache.CacheItem item)
itemRemoved
in class BaseCache
item
- CacheItem
that was just removed
Cache bucket is already synchronized by the caller
public void trimExpiredEntries(int maxCount)
trimExpiredEntries
in interface Cache
trimExpiredEntries
in class BaseCache
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).
public Object getStatByName(String key)
getStatByName
in interface Cache
getStatByName
in class BaseCache
key
- to corresponding statCopyright © 2006–2018 TinyGroup. All rights reserved.