Class AbstractMemoryCache<K,V>
java.lang.Object
org.apache.commons.jcs3.engine.memory.AbstractMemoryCache<K,V>
- All Implemented Interfaces:
IMemoryCache<K,V>
- Direct Known Subclasses:
AbstractDoubleLinkedListMemoryCache,LHMLRUMemoryCache,SoftReferenceMemoryCache
This base includes some common code for memory caches.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intHow many to spool at a time.protected AtomicLongnumber of hitsprotected final Lockprotected Map<K,MemoryElementDescriptor<K, V>> Map where items are stored by key.protected AtomicLongnumber of missesprotected AtomicLongnumber of puts -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Map<K,MemoryElementDescriptor<K, V>> Children must implement this method.voiddispose()Prepares for shutdown.voiddumpMap()Dump the cache map for debugging.Get an item from the cache.Returns the CacheAttributes.Returns the cache (aka "region") name.Gets the cache hub / region that the MemoryCache is used byGet an Array of the keys for all elements in the memory cacheMap<K,ICacheElement<K, V>> getMultiple(Set<K> keys) Gets multiple items from the cache based on the given set of keys.Get an item from the cache without affecting its last access time or position.intgetSize()Returns the current cache size.Returns the historical and statistical data for a region's memory cache.voidinitialize(CompositeCache<K, V> hub) For post reflection creation initializationprotected abstract voidUpdate control structures after get (guarded by the lock)protected abstract voidRemoves all cached items from the cache control structures.protected abstract voidRemove element from control structure (guarded by the lock)booleanRemoves an item from the cache.voidRemoves all cached items from the cache.protected booleanremoveByGroup(K key) Remove all keys of the same group hierarchy.protected booleanremoveByHierarchy(K key) Remove all keys of the same name hierarchy.voidSets the CacheAttributes.abstract voidupdate(ICacheElement<K, V> ce) Puts an item to the cache.voidwaterfal(ICacheElement<K, V> ce) Puts an item to the cache.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.jcs3.engine.memory.behavior.IMemoryCache
freeElements
-
Field Details
-
chunkSize
How many to spool at a time. -
lock
-
map
Map where items are stored by key. This is created by the concrete child class. -
hitCnt
number of hits -
missCnt
number of misses -
putCnt
number of puts
-
-
Constructor Details
-
AbstractMemoryCache
public AbstractMemoryCache()
-
-
Method Details
-
initialize
For post reflection creation initialization- Specified by:
initializein interfaceIMemoryCache<K,V> - Parameters:
hub-
-
createMap
Children must implement this method. A FIFO implementation may use a tree map. An LRU might use a hashtable. The map returned should be threadsafe.- Returns:
- a threadsafe Map
-
getMultiple
Gets multiple items from the cache based on the given set of keys.- Specified by:
getMultiplein interfaceIMemoryCache<K,V> - Parameters:
keys-- Returns:
- a map of K key to ICacheElement<K, V> element, or an empty map if there is no data in cache for any of these keys
- Throws:
IOException
-
getQuiet
Get an item from the cache without affecting its last access time or position. Not all memory cache implementations can get quietly.- Specified by:
getQuietin interfaceIMemoryCache<K,V> - Parameters:
key- Identifies item to find- Returns:
- Element matching key if found, or null
- Throws:
IOException
-
update
Puts an item to the cache.- Specified by:
updatein interfaceIMemoryCache<K,V> - Parameters:
ce- Description of the Parameter- Throws:
IOException- Description of the Exception
-
removeAll
Removes all cached items from the cache.- Specified by:
removeAllin interfaceIMemoryCache<K,V> - Throws:
IOException
-
lockedRemoveAll
Removes all cached items from the cache control structures. (guarded by the lock) -
dispose
Prepares for shutdown. Reset statistics- Specified by:
disposein interfaceIMemoryCache<K,V> - Throws:
IOException
-
getStatistics
Description copied from interface:IMemoryCacheReturns the historical and statistical data for a region's memory cache.- Specified by:
getStatisticsin interfaceIMemoryCache<K,V> - Returns:
- statistics about the cache
-
getSize
Returns the current cache size.- Specified by:
getSizein interfaceIMemoryCache<K,V> - Returns:
- The size value
-
getCacheName
Returns the cache (aka "region") name.- Returns:
- The cacheName value
-
waterfal
Puts an item to the cache.- Specified by:
waterfalin interfaceIMemoryCache<K,V> - Parameters:
ce- the item
-
dumpMap
Dump the cache map for debugging. -
getCacheAttributes
Returns the CacheAttributes.- Specified by:
getCacheAttributesin interfaceIMemoryCache<K,V> - Returns:
- The CacheAttributes value
-
setCacheAttributes
Sets the CacheAttributes.- Specified by:
setCacheAttributesin interfaceIMemoryCache<K,V> - Parameters:
cattr- The new CacheAttributes value
-
getCompositeCache
Gets the cache hub / region that the MemoryCache is used by- Specified by:
getCompositeCachein interfaceIMemoryCache<K,V> - Returns:
- The cache value
-
removeByGroup
Remove all keys of the same group hierarchy.- Parameters:
key- the key- Returns:
- true if something has been removed
-
removeByHierarchy
Remove all keys of the same name hierarchy.- Parameters:
key- the key- Returns:
- true if something has been removed
-
lockedRemoveElement
Remove element from control structure (guarded by the lock)- Parameters:
me- the memory element descriptor
-
remove
Removes an item from the cache. This method handles hierarchical removal. If the key is a String and ends with the CacheConstants.NAME_COMPONENT_DELIMITER, then all items with keys starting with the argument String will be removed.- Specified by:
removein interfaceIMemoryCache<K,V> - Parameters:
key-- Returns:
- true if the removal was successful
- Throws:
IOException
-
getKeySet
Get an Array of the keys for all elements in the memory cache- Specified by:
getKeySetin interfaceIMemoryCache<K,V> - Returns:
- An Object[]
-
get
Get an item from the cache.- Specified by:
getin interfaceIMemoryCache<K,V> - Parameters:
key- Identifies item to find- Returns:
- ICacheElement<K, V> if found, else null
- Throws:
IOException
-
lockedGetElement
Update control structures after get (guarded by the lock)- Parameters:
me- the memory element descriptor
-