public class LFUAgingCache<K,V> extends ExpiryCache<K,V>
Registered listeners are notified of each expiry event.
This implementation is not synchronized. Any access to the methods of this class which modify the internal state of the cache must be synchronized externally.
Modifier and Type | Class and Description |
---|---|
private static class |
LFUAgingCache.NodeImpl<K,V>
A sortable node containing the hashable key and value of a cache entry.
|
ExpiryCache.Node<K,V>
Modifier and Type | Field and Description |
---|---|
private static double |
CLEAN_RATIO
Portion of cache limit to be expired when the cache is full and capacity is needed
|
Constructor and Description |
---|
LFUAgingCache(int limit)
Constructor.
|
LFUAgingCache(java.lang.String name,
int limit)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
ageNodes()
Recompute the relevance of nodes with older access ages.
|
protected ExpiryCache.Node<K,V> |
createNode(K key,
V value)
Create a node of the appropriate type for the given key and value.
|
protected void |
ensureCapacity()
Ensure there is sufficient capacity to add a new record to the cache, by expiring the least
desirable element(s), according to the policy of the cache.
|
protected int |
getCleanLimit()
Get the number of elements which will be expired from the cache each time it becomes full,
and capacity is required for a new element.
|
addCacheExpiryListener, get, put, remove, removeCacheExpiryListener
private static final double CLEAN_RATIO
public LFUAgingCache(int limit)
limit
- Maximum number of elements allowed in the cache.java.lang.IllegalArgumentException
- if the specified limit is less than one.public LFUAgingCache(java.lang.String name, int limit)
name
- Cache name, for debug and logging purposes.limit
- Maximum number of elements allowed in the cache.java.lang.IllegalArgumentException
- if the specified limit is less than one.protected int getCleanLimit()
getCleanLimit
in class ExpiryCache<K,V>
protected ExpiryCache.Node<K,V> createNode(K key, V value)
createNode
in class ExpiryCache<K,V>
key
- Hashable key.value
- Cached value.protected void ensureCapacity()
When elements are expired from the cache, a cache expiry event is sent to all registered listeners.
ensureCapacity
in class ExpiryCache<K,V>
private void ageNodes()