public abstract class AbstractDoubleLinkedListMemoryCache<K,V> extends AbstractMemoryCache<K,V>
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.
Modifier and Type | Field and Description |
---|---|
protected DoubleLinkedList<MemoryElementDescriptor<K,V>> |
list
thread-safe double linked list for lru
|
Constructor and Description |
---|
AbstractDoubleLinkedListMemoryCache() |
Modifier and Type | Method and Description |
---|---|
protected 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 |
adjustListForGet(MemoryElementDescriptor<K,V> me)
Adjust the list as needed for a get.
|
protected abstract MemoryElementDescriptor<K,V> |
adjustListForUpdate(ICacheElement<K,V> ce)
Children implement this to control the cache expiration algorithm
|
ConcurrentMap<K,MemoryElementDescriptor<K,V>> |
createMap()
This is called by super initialize.
|
int |
freeElements(int numberToFree)
This instructs the memory cache to remove the numberToFree according to its eviction
policy.
|
ICacheElement<K,V> |
get(K key)
Get an item from the cache.
|
IStats |
getStatistics()
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 |
lockedGetElement(MemoryElementDescriptor<K,V> me)
Update control structures after get
(guarded by the lock)
|
protected void |
lockedRemoveAll()
Removes all cached items from the cache control structures.
|
protected void |
lockedRemoveElement(MemoryElementDescriptor<K,V> me)
Remove element from control structure
(guarded by the lock)
|
void |
update(ICacheElement<K,V> ce)
Calls the abstract method updateList.
|
dispose, dumpMap, getCacheAttributes, getCacheName, getCompositeCache, getKeySet, getMultiple, getQuiet, getSize, remove, removeAll, removeByGroup, removeByHierarchy, setCacheAttributes, waterfal
protected DoubleLinkedList<MemoryElementDescriptor<K,V>> list
public AbstractDoubleLinkedListMemoryCache()
public void initialize(CompositeCache<K,V> hub)
initialize
in interface IMemoryCache<K,V>
initialize
in class AbstractMemoryCache<K,V>
hub
- public ConcurrentMap<K,MemoryElementDescriptor<K,V>> createMap()
createMap
in class AbstractMemoryCache<K,V>
public final void update(ICacheElement<K,V> ce) throws IOException
If the max size is reached, an element will be put to disk.
update
in interface IMemoryCache<K,V>
update
in class AbstractMemoryCache<K,V>
ce
- The cache element, or entry wrapperIOException
protected abstract MemoryElementDescriptor<K,V> adjustListForUpdate(ICacheElement<K,V> ce) throws IOException
ce
- IOException
public int freeElements(int numberToFree)
numberToFree
- public ICacheElement<K,V> get(K key) throws IOException
AbstractMemoryCache
get
in interface IMemoryCache<K,V>
get
in class AbstractMemoryCache<K,V>
key
- Identifies item to findIOException
- Description of the ExceptionAbstractMemoryCache.get(Object)
protected abstract void adjustListForGet(MemoryElementDescriptor<K,V> me)
me
- protected void lockedGetElement(MemoryElementDescriptor<K,V> me)
lockedGetElement
in class AbstractMemoryCache<K,V>
me
- the memory element descriptorprotected void lockedRemoveElement(MemoryElementDescriptor<K,V> me)
lockedRemoveElement
in class AbstractMemoryCache<K,V>
me
- the memory element descriptorprotected void lockedRemoveAll()
lockedRemoveAll
in class AbstractMemoryCache<K,V>
protected MemoryElementDescriptor<K,V> addFirst(ICacheElement<K,V> ce)
ce
- The feature to be added to the Firstprotected MemoryElementDescriptor<K,V> addLast(ICacheElement<K,V> ce)
ce
- The feature to be added to the Firstpublic IStats getStatistics()
getStatistics
in interface IMemoryCache<K,V>
getStatistics
in class AbstractMemoryCache<K,V>
IMemoryCache.getStatistics()
Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.