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 int
How many to spool at a time.protected AtomicLong
number of hitsprotected final Lock
protected Map<K,
MemoryElementDescriptor<K, V>> Map where items are stored by key.protected AtomicLong
number of missesprotected AtomicLong
number of puts -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Map<K,
MemoryElementDescriptor<K, V>> Children must implement this method.void
dispose()
Prepares for shutdown.void
dumpMap()
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.int
getSize()
Returns the current cache size.Returns the historical and statistical data for a region's memory cache.void
initialize
(CompositeCache<K, V> hub) For post reflection creation initializationprotected abstract void
Update control structures after get (guarded by the lock)protected abstract void
Removes all cached items from the cache control structures.protected abstract void
Remove element from control structure (guarded by the lock)boolean
Removes an item from the cache.void
Removes all cached items from the cache.protected boolean
removeByGroup
(K key) Remove all keys of the same group hierarchy.protected boolean
removeByHierarchy
(K key) Remove all keys of the same name hierarchy.void
Sets the CacheAttributes.abstract void
update
(ICacheElement<K, V> ce) Puts an item to the cache.void
waterfal
(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, wait
Methods 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:
initialize
in 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:
getMultiple
in 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:
getQuiet
in 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:
update
in 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:
removeAll
in 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:
dispose
in interfaceIMemoryCache<K,
V> - Throws:
IOException
-
getStatistics
Description copied from interface:IMemoryCache
Returns the historical and statistical data for a region's memory cache.- Specified by:
getStatistics
in interfaceIMemoryCache<K,
V> - Returns:
- statistics about the cache
-
getSize
Returns the current cache size.- Specified by:
getSize
in 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:
waterfal
in interfaceIMemoryCache<K,
V> - Parameters:
ce
- the item
-
dumpMap
Dump the cache map for debugging. -
getCacheAttributes
Returns the CacheAttributes.- Specified by:
getCacheAttributes
in interfaceIMemoryCache<K,
V> - Returns:
- The CacheAttributes value
-
setCacheAttributes
Sets the CacheAttributes.- Specified by:
setCacheAttributes
in interfaceIMemoryCache<K,
V> - Parameters:
cattr
- The new CacheAttributes value
-
getCompositeCache
Gets the cache hub / region that the MemoryCache is used by- Specified by:
getCompositeCache
in 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:
remove
in 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:
getKeySet
in interfaceIMemoryCache<K,
V> - Returns:
- An Object[]
-
get
Get an item from the cache.- Specified by:
get
in 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
-