org.apache.shindig.common.cache
Class LruCache<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.apache.shindig.common.cache.LruCache<K,V>
- All Implemented Interfaces:
- Serializable, Cloneable, Map<K,V>, Cache<K,V>
public class LruCache<K,V>
- extends LinkedHashMap<K,V>
- implements Cache<K,V>
A basic LRU cache. Prefer using EhCache for most purposes to this class.
- See Also:
- Serialized Form
|
Constructor Summary |
LruCache(int capacity)
|
| Methods inherited from interface java.util.Map |
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
LruCache
public LruCache(int capacity)
getElement
public V getElement(K key)
- Description copied from interface:
Cache
- Retrieves an entry for the cache.
- Specified by:
getElement in interface Cache<K,V>
- Returns:
- The entry stored under the given key, or null if it doesn't exist.
addElement
public void addElement(K key,
V value)
- Description copied from interface:
Cache
- Stores an entry into the cache.
- Specified by:
addElement in interface Cache<K,V>
removeElement
public V removeElement(K key)
- Description copied from interface:
Cache
- Removes an entry from the cache.
- Specified by:
removeElement in interface Cache<K,V>
- Parameters:
key - The entry to return.
- Returns:
- The entry stored under the given key, or null if it doesn't exist.
getCapacity
public long getCapacity()
- Description copied from interface:
Cache
- Returns the capacity of the cache.
- Specified by:
getCapacity in interface Cache<K,V>
- Returns:
- a positive integer indicating the upper bound on the number of allowed elements
in the cace, -1 signifies that the capacity is unbounded
getSize
public long getSize()
- Specified by:
getSize in interface Cache<K,V>
- Returns:
- The current size of the cache, or -1 if the cache does not support returning sizes.
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
- Overrides:
removeEldestEntry in class LinkedHashMap<K,V>
Copyright © 2007-2012. All Rights Reserved.