public class LRUCache<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 |
LRUCache.NodeImpl<K,V>
A sortable node containing the hashable key and value of a cache entry.
|
ExpiryCache.Node<K,V>
Constructor and Description |
---|
LRUCache(int limit)
Constructor.
|
LRUCache(java.lang.String name,
int limit)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected ExpiryCache.Node<K,V> |
createNode(K key,
V value)
Create a node of the appropriate type for the given key and value.
|
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, ensureCapacity, get, put, remove, removeCacheExpiryListener
public LRUCache(int limit)
limit
- Maximum number of elements allowed in the cache.java.lang.IllegalArgumentException
- if the specified limit is less than one.public LRUCache(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.