/** * Returns current number of buckets */ public Integer getTableSize() { return (Integer) baseCache.getStatByName( Constants.STAT_BASECACHE_TABLE_SIZE); }
/** * initialize the cache * @param maxEntries maximum number of entries expected in the cache * @param props opaque list of properties for a given cache implementation * @throws a generic Exception if the initialization failed */ public void init(int maxEntries, Properties props) throws Exception { init(maxEntries, DEFAULT_LOAD_FACTOR, props); }
/** * clear all the entries from the cache. * @returns the number of entries cleared from the cache */ public int clear() { CacheItem item=null, next=null; int count = 0; for (int index = 0; index < maxBuckets; index++) { synchronized (bucketLocks[index]) { for (item = buckets[index]; item != null; item = item.next) { next = item.next; item.next = null; count++; decrementEntryCount(); itemRemoved(item); if (entryCount == 0) break; } buckets[index] = null; } } return count; }
int index = getIndex(hashCode); if ((hashCode == item.hashCode) && eq(key, item.key)) { newItem = createItem(hashCode, key, value, size); overflow = itemAdded(newItem); itemRefreshed(oldItem, oldSize); incrementEntryCount(); incrementAddCount(); trimItem(overflow); incrementRefreshCount();
int index = getIndex(hashCode); Object value; CacheItem item = null; if ( (hashCode == item.hashCode) && eq(key, item.key) ) { break; itemAccessed(item); value = loadValue(key, hashCode); incrementHitCount(); else incrementMissCount();
int index = getIndex(hashCode); itemRemoved(item); break; decrementEntryCount(); incrementRemovalCount(); incrementHitCount(); } else incrementMissCount();
int hashCode = hash(key); int index = getIndex(hashCode); decrementEntryCount(); incrementRemovalCount(); itemRemoved((CacheItem)items.get(i));
/** * get all the items stored at the key. * @param key lookup key * @returns an Iterator over the items with the given key. */ public Iterator getAll(Object key) { int hashCode = hash(key); int index = getIndex(hashCode); ArrayList valueList = new ArrayList(entryCount); synchronized (bucketLocks[index]) { CacheItem item = buckets[index]; for (; item != null; item = item.next) { if ( (hashCode == item.hashCode) && eq(key, item.key) ) { incrementHitCount(); valueList.add(item.getValue()); } } } return valueList.iterator(); }
/** * remove the item stored at the key. * @param key lookup key * @returns the item stored at the key; null if not found. */ public Object remove(Object key) { int hashCode = hash(key); Object retVal = null; CacheItem removed = _remove( hashCode, key, null); if (removed != null) retVal = removed.getValue(); return retVal; }
/** * remove the item stored at the key. * @param item CacheItem to be removed * @return the item stored at the key; null if not found. */ protected CacheItem _removeItem(CacheItem ritem) { int index = getIndex(ritem.hashCode); CacheItem prev = null, item = null; synchronized (bucketLocks[index]) { for (item = buckets[index]; item != null; item = item.next) { if (item == ritem) { if (prev == null) { buckets[index] = item.next; } else { prev.next = item.next; } item.next = null; break; } prev = item; } } if (item != null) { decrementEntryCount(); } return item; }
/** * check if the cache contains the item at the key * @param key lookup key * @returns true if there is an item stored at the key; false if not. */ public boolean contains(Object key) { return (get(key) != null); }
/** * trim the item from the cache and notify listeners * @param item to be trimmed */ protected void trimItem(CacheItem item) { CacheItem removed = _removeItem(item); if (removed != null) { for (int i = 0; i < listeners.size(); i++) { CacheListener listener = (CacheListener) listeners.get(i); listener.trimEvent(removed.key, removed.value); } } }
/** * remove the item stored at the key. * @param hashCode a precomputed hashCode * @param key lookup key * @returns the item stored at the key; null if not found. */ public Object remove(int hashCode, Object key) { Object retVal = null; CacheItem removed = _remove( hashCode, key, null); if (removed != null) retVal = removed.getValue(); return retVal; }
/** * Sets all references to null. This method should be called * at the end of this object's life cycle. */ public void destroy() { if ((listeners != null) && (buckets != null) && (bucketLocks != null)) { clear(); listeners.clear(); } entryCountLk = null; hitCountLk = null; missCountLk = null; removalCountLk = null; refreshCountLk = null; addCountLk = null; overflowCountLk = null; buckets = null; bucketLocks = null; refreshFlags = null; listeners = null; }
int index = getIndex(hashCode); if ((hashCode == item.hashCode) && eq(key, item.key)) { newItem = createItem(hashCode, key, value, size); overflow = itemAdded(newItem); itemRefreshed(oldItem, oldSize); incrementEntryCount(); incrementAddCount(); trimItem(overflow); incrementRefreshCount();
int index = getIndex(hashCode); Object value; CacheItem item = null; if ( (hashCode == item.hashCode) && eq(key, item.key) ) { break; itemAccessed(item); value = loadValue(key, hashCode); incrementHitCount(); else incrementMissCount();
int index = getIndex(hashCode); itemRemoved(item); break; decrementEntryCount(); incrementRemovalCount(); incrementHitCount(); } else incrementMissCount();