int index = getIndex(item.hashCode()); int segment = (index/segmentSize); LruCacheItem[] list = lists[segment]; if (isThresholdReached()) { overflow = trimLru(trimIndex); incrementTrimIndex();
/** * Returns the legnth of the segment list */ public Integer[] getSegmentListLength() { return (Integer[]) multiLruCache.getStatByName( Constants.STAT_MULTILRUCACHE_SEGMENT_LIST_LENGTH); } }
/** * item value has been refreshed * @param item <code>CacheItem</code> that was refreshed * @param oldSize size of the previous value that was refreshed * Cache bucket is already synchronized by the caller */ protected void itemRefreshed(CacheItem item, int oldSize) { itemAccessed(item); }
int index = getIndex(item.hashCode()); int segment = (index/segmentSize); LruCacheItem[] list = lists[segment];
/** * has cache reached its threshold * @return true when the cache reached its threshold */ protected boolean isThresholdReached() { return (currentSize > maxSize || super.isThresholdReached()); }
/** * item value has been removed from the cache * @param item <code>CacheItem</code> that was just removed * * Cache bucket is already synchronized by the caller */ protected void itemRemoved(CacheItem item) { super.itemRemoved(item); // update the size decrementCurrentSize(item.getSize()); }
/** * item value has been refreshed * @param item <code>CacheItem</code> that was refreshed * @param oldSize size of the previous value that was refreshed * Cache bucket is already synchronized by the caller */ protected void itemRefreshed(CacheItem item, int oldSize) { 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()); }
public 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; } }
/** * this item is just added to the cache * @param item <code>CacheItem</code> that was created * @return a overflow item; may be null * * Cache bucket is already synchronized by the caller */ protected CacheItem itemAdded(CacheItem item) { LruCacheItem overflow = (LruCacheItem) super.itemAdded(item); // update the size if (overflow != null) { decrementCurrentSize(overflow.getSize()); } incrementCurrentSize(item.getSize()); return overflow; }
super.init(maxCapacity, props); currentSize = 0;
/** * item value has been removed from the cache * @param item <code>CacheItem</code> that was just removed * * Cache bucket is already synchronized by the caller */ protected void itemRemoved(CacheItem item) { LruCacheItem l = (LruCacheItem) item; int index = getIndex(item.hashCode()); int segment = (index/segmentSize); LruCacheItem[] list = lists[segment]; // remove the item from the LRU list synchronized (list) { // if the item is already trimmed from the LRU list, nothing to do. if (l.isTrimmed) return; LruCacheItem prev = l.lPrev; LruCacheItem next = l.lNext; // patch up the neighbors and make sure head/tail are correct if (prev != null) prev.lNext = next; else list[LRU_HEAD] = next; if (next != null) next.lPrev = prev; else list[LRU_TAIL] = prev; listsLength[segment]--; } }
/** * has cache reached its threshold * @return true when the cache reached its threshold */ protected boolean isThresholdReached() { return (currentSize > maxSize || super.isThresholdReached()); }
/** * item value has been removed from the cache * @param item <code>CacheItem</code> that was just removed * * Cache bucket is already synchronized by the caller */ protected void itemRemoved(CacheItem item) { super.itemRemoved(item); // update the size decrementCurrentSize(item.getSize()); }
/** * item value has been refreshed * @param item <code>CacheItem</code> that was refreshed * @param oldSize size of the previous value that was refreshed * Cache bucket is already synchronized by the caller */ protected void itemRefreshed(CacheItem item, int oldSize) { 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()); }
public 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; } }
/** * this item is just added to the cache * @param item <code>CacheItem</code> that was created * @return a overflow item; may be null * * Cache bucket is already synchronized by the caller */ protected CacheItem itemAdded(CacheItem item) { LruCacheItem overflow = (LruCacheItem) super.itemAdded(item); // update the size if (overflow != null) { decrementCurrentSize(overflow.getSize()); } incrementCurrentSize(item.getSize()); return overflow; }
super.init(maxCapacity, props); currentSize = 0;
LruCacheItem lc = (LruCacheItem) item; int index = getIndex(item.hashCode()); int segment = (index/segmentSize); LruCacheItem[] list = lists[segment]; if (isThresholdReached()) { overflow = trimLru(trimIndex); incrementTrimIndex();
/** * Returns the legnth of the segment list */ public Integer[] getSegmentListLength() { return (Integer[]) multiLruCache.getStatByName( Constants.STAT_MULTILRUCACHE_SEGMENT_LIST_LENGTH); } }
int index = getIndex(item.hashCode()); int segment = (index/segmentSize); LruCacheItem[] list = lists[segment];