com.sun.labs.minion.util
Class LRACache<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.sun.labs.minion.util.LRACache<K,V>
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>
- Direct Known Subclasses:
- DocCache
public class LRACache<K,V>
- extends java.util.LinkedHashMap<K,V>
A least-recently-accessed cache.
- See Also:
- Serialized Form
| Nested classes/interfaces inherited from class java.util.AbstractMap |
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
|
Field Summary |
protected static int |
DEFAULT_SIZE
The default cache size. |
protected int |
lraSize
The number of items to be held in the cache. |
|
Constructor Summary |
LRACache()
Creates a cache of the default size. |
LRACache(int size)
Creates a cache that will hold the given number of items. |
|
Method Summary |
protected boolean |
removeEldestEntry(java.util.Map.Entry<K,V> eldest)
Removes the oldest entry in the map. |
| Methods inherited from class java.util.LinkedHashMap |
clear, containsValue, get |
| Methods inherited from class java.util.HashMap |
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values |
| Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
lraSize
protected int lraSize
- The number of items to be held in the cache. If the size is less
than 0, no elements will ever be removed.
DEFAULT_SIZE
protected static final int DEFAULT_SIZE
- The default cache size.
- See Also:
- Constant Field Values
LRACache
public LRACache()
- Creates a cache of the default size.
LRACache
public LRACache(int size)
- Creates a cache that will hold the given number of items.
- Parameters:
size - The number of elements to cache. If the size is less
than 0, then the cache can grow unboundedly.
removeEldestEntry
protected boolean removeEldestEntry(java.util.Map.Entry<K,V> eldest)
- Removes the oldest entry in the map.
- Overrides:
removeEldestEntry in class java.util.LinkedHashMap<K,V>
- Parameters:
eldest - The oldest entry.
- Returns:
true if this entry should be removed, which
will happen when the size of the map exceeds our cache size.