Class AbstractDoubleLinkedListMemoryCache<K,V>
java.lang.Object
org.apache.commons.jcs3.engine.memory.AbstractMemoryCache<K,V>
org.apache.commons.jcs3.engine.memory.AbstractDoubleLinkedListMemoryCache<K,V>
- All Implemented Interfaces:
IMemoryCache<K,
V>
- Direct Known Subclasses:
FIFOMemoryCache
,LRUMemoryCache
,MRUMemoryCache
This class contains methods that are common to memory caches using the double linked list, such
as the LRU, MRU, FIFO, and LIFO caches.
Children can control the expiration algorithm by controlling the update and get. The last item in the list will be the one removed when the list fills. For instance LRU should more items to the front as they are used. FIFO should simply add new items to the front of the list.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DoubleLinkedList<MemoryElementDescriptor<K,
V>> thread-safe double linked list for lru -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected MemoryElementDescriptor<K,
V> addFirst
(ICacheElement<K, V> ce) Adds a new node to the start of the link list.protected MemoryElementDescriptor<K,
V> addLast
(ICacheElement<K, V> ce) Adds a new node to the end of the link list.protected abstract void
Adjust the list as needed for a get.protected abstract MemoryElementDescriptor<K,
V> Children implement this to control the cache expiration algorithmThis is called by super initialize.int
freeElements
(int numberToFree) This instructs the memory cache to remove the numberToFree according to its eviction policy.Get an item from the cache.This returns semi-structured information on the memory cache, such as the size, put count, hit count, and miss count.void
initialize
(CompositeCache<K, V> hub) For post reflection creation initialization.protected void
Update control structures after get (guarded by the lock)protected void
Removes all cached items from the cache control structures.protected void
Remove element from control structure (guarded by the lock)final void
update
(ICacheElement<K, V> ce) Calls the abstract method updateList.Methods inherited from class org.apache.commons.jcs3.engine.memory.AbstractMemoryCache
dispose, dumpMap, getCacheAttributes, getCacheName, getCompositeCache, getKeySet, getMultiple, getQuiet, getSize, remove, removeAll, removeByGroup, removeByHierarchy, setCacheAttributes, waterfal
-
Field Details
-
list
thread-safe double linked list for lru
-
-
Constructor Details
-
AbstractDoubleLinkedListMemoryCache
public AbstractDoubleLinkedListMemoryCache()
-
-
Method Details
-
initialize
For post reflection creation initialization.- Specified by:
initialize
in interfaceIMemoryCache<K,
V> - Overrides:
initialize
in classAbstractMemoryCache<K,
V> - Parameters:
hub
-
-
createMap
This is called by super initialize. NOTE: should return a thread safe map- Specified by:
createMap
in classAbstractMemoryCache<K,
V> - Returns:
- new ConcurrentHashMap()
-
update
Calls the abstract method updateList.If the max size is reached, an element will be put to disk.
- Specified by:
update
in interfaceIMemoryCache<K,
V> - Specified by:
update
in classAbstractMemoryCache<K,
V> - Parameters:
ce
- The cache element, or entry wrapper- Throws:
IOException
-
adjustListForUpdate
protected abstract MemoryElementDescriptor<K,V> adjustListForUpdate(ICacheElement<K, V> ce) throws IOExceptionChildren implement this to control the cache expiration algorithm- Parameters:
ce
-- Returns:
- MemoryElementDescriptor the new node
- Throws:
IOException
-
freeElements
This instructs the memory cache to remove the numberToFree according to its eviction policy. For example, the LRUMemoryCache will remove the numberToFree least recently used items. These will be spooled to disk if a disk auxiliary is available.- Parameters:
numberToFree
-- Returns:
- the number that were removed. if you ask to free 5, but there are only 3, you will get 3.
-
get
Description copied from class:AbstractMemoryCache
Get an item from the cache.- Specified by:
get
in interfaceIMemoryCache<K,
V> - Overrides:
get
in classAbstractMemoryCache<K,
V> - Parameters:
key
- Identifies item to find- Returns:
- ICacheElement<K, V> if found, else null
- Throws:
IOException
- Description of the Exception- See Also:
-
adjustListForGet
Adjust the list as needed for a get. This allows children to control the algorithm- Parameters:
me
-
-
lockedGetElement
Update control structures after get (guarded by the lock)- Specified by:
lockedGetElement
in classAbstractMemoryCache<K,
V> - Parameters:
me
- the memory element descriptor
-
lockedRemoveElement
Remove element from control structure (guarded by the lock)- Specified by:
lockedRemoveElement
in classAbstractMemoryCache<K,
V> - Parameters:
me
- the memory element descriptor
-
lockedRemoveAll
Removes all cached items from the cache control structures. (guarded by the lock)- Specified by:
lockedRemoveAll
in classAbstractMemoryCache<K,
V>
-
addFirst
Adds a new node to the start of the link list.- Parameters:
ce
- The feature to be added to the First- Returns:
- MemoryElementDescriptor
-
addLast
Adds a new node to the end of the link list.- Parameters:
ce
- The feature to be added to the First- Returns:
- MemoryElementDescriptor
-
getStatistics
This returns semi-structured information on the memory cache, such as the size, put count, hit count, and miss count.- Specified by:
getStatistics
in interfaceIMemoryCache<K,
V> - Overrides:
getStatistics
in classAbstractMemoryCache<K,
V> - Returns:
- statistics about the cache
- See Also:
-