Methods Summary |
---|
protected final void | decrementCurrentSize(int size)
synchronized(currentSizeLk) {
currentSize -= size;
}
|
public java.lang.Object | getStatByName(java.lang.String key)get the desired statistic counter
Object stat = super.getStatByName(key);
if (stat == null && key != null) {
if (key.equals(Constants.STAT_BOUNDEDMULTILRUCACHE_CURRENT_SIZE))
stat = Long.valueOf(currentSize);
else if (key.equals(Constants.STAT_BOUNDEDMULTILRUCACHE_MAX_SIZE)) {
if (maxSize == Constants.DEFAULT_MAX_CACHE_SIZE)
stat = Constants.STAT_DEFAULT;
else
stat = Long.valueOf(maxSize);
}
}
return stat;
|
public java.util.Map | getStats()
Map stats = super.getStats();
// cache size in KB
stats.put(Constants.STAT_BOUNDEDMULTILRUCACHE_CURRENT_SIZE,
Long.valueOf(currentSize));
if (maxSize == Constants.DEFAULT_MAX_CACHE_SIZE) {
stats.put(Constants.STAT_BOUNDEDMULTILRUCACHE_MAX_SIZE,
Constants.STAT_DEFAULT);
}
else {
stats.put(Constants.STAT_BOUNDEDMULTILRUCACHE_MAX_SIZE,
Long.valueOf(maxSize));
}
return stats;
|
protected final void | incrementCurrentSize(int size)synchronized counter updates
synchronized(currentSizeLk) {
currentSize += size;
}
|
public void | init(int maxCapacity, java.util.Properties props)initialize the LRU cache
super.init(maxCapacity, props);
currentSize = 0;
if (props != null) {
String strMaxSize = props.getProperty("MaxSize");
int multiplier = 1;
long size = -1;
String prop = strMaxSize;
if (prop != null) {
int index;
// upper case the string
prop = prop.toUpperCase();
// look for 200KB or 80Kb or 1MB or 2Mb like suffixes
if ((index = prop.indexOf("KB")) != -1) {
multiplier = Constants.KB;
prop = prop.substring(0, index);
} else if ((index = prop.indexOf("MB")) != -1) {
multiplier = Constants.MB;
prop = prop.substring(0, index);
}
try {
size = Long.parseLong(prop.trim());
} catch (NumberFormatException nfe) {}
}
// sanity check and convert
if (size > 0)
maxSize = (size * multiplier);
else {
String msg = _rb.getString("cache.BoundedMultiLruCache.illegalMaxSize");
Object[] params = { strMaxSize };
msg = MessageFormat.format(msg, params);
throw new IllegalArgumentException(msg);
}
}
|
protected boolean | isThresholdReached()has cache reached its threshold
return (currentSize > maxSize || super.isThresholdReached());
|
protected CacheItem | itemAdded(CacheItem item)this item is just added to the cache
LruCacheItem overflow = (LruCacheItem) super.itemAdded(item);
// update the size
if (overflow != null) {
decrementCurrentSize(overflow.getSize());
}
incrementCurrentSize(item.getSize());
return overflow;
|
protected void | itemRefreshed(CacheItem item, int oldSize)item value has been refreshed
super.itemRefreshed(item, oldSize);
/** reduce the cache by the size of the size of the previous value
* and increment by the value being refreshed with.
*/
decrementCurrentSize(oldSize);
incrementCurrentSize(item.getSize());
|
protected void | itemRemoved(CacheItem item)item value has been removed from the cache
super.itemRemoved(item);
// update the size
decrementCurrentSize(item.getSize());
|