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 If the item is found, it is removed from the list and added first.
|
Set<K> |
getKeySet()
Get an Array of the keys for all elements in the memory 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.
|
boolean |
remove(K key)
Removes an item from the cache.
|
void |
removeAll()
Remove all of the elements from both the Map and the linked list implementation.
|
void |
update(ICacheElement<K,V> ce)
Calls the abstract method updateList.
|
dispose, dumpMap, getCacheAttributes, getCacheName, getCompositeCache, getMultiple, getQuiet, getSize, getStatus, 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 final ICacheElement<K,V> get(K key) throws IOException
get
in interface IMemoryCache<K,V>
get
in class AbstractMemoryCache<K,V>
key
- Identifies item to findIOException
protected abstract void adjustListForGet(MemoryElementDescriptor<K,V> me)
me
- public int freeElements(int numberToFree) throws IOException
numberToFree
- IOException
public boolean remove(K key) throws IOException
remove
in interface IMemoryCache<K,V>
remove
in class AbstractMemoryCache<K,V>
key
- IOException
public void removeAll() throws IOException
removeAll
in interface IMemoryCache<K,V>
removeAll
in class AbstractMemoryCache<K,V>
IOException
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 Set<K> getKeySet()
getKeySet
in interface IMemoryCache<K,V>
getKeySet
in class AbstractMemoryCache<K,V>
public IStats getStatistics()
getStatistics
in interface IMemoryCache<K,V>
getStatistics
in class AbstractMemoryCache<K,V>
IMemoryCache.getStatistics()
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.