com.tagtraum.perf.datastructures
Class LRUCache
java.lang.Object
|
+--java.util.AbstractMap
|
+--java.util.HashMap
|
+--java.util.LinkedHashMap
|
+--com.tagtraum.perf.datastructures.LRUCache
- All Implemented Interfaces:
- Cache, java.lang.Cloneable, java.util.Map, java.io.Serializable
- public class LRUCache
- extends java.util.LinkedHashMap
- implements Cache
LRU cache that uses LinkedHashMap
.
Needs JDK >= 1.4.0
- Version:
- $Id: $
- Author:
- Hendrik Schreiber
- See Also:
- Serialized Form
Nested classes inherited from class java.util.Map |
java.util.Map.Entry |
Constructor Summary |
LRUCache(int capacity)
Creates a LRU cache with the given capacity. |
Method Summary |
java.lang.Object |
get(java.lang.Object key)
Retrieves an object from this cache using the given key. |
int |
getCapacity()
Capacity of this cache. |
float |
getHitRatio()
Returns a number between 0.0 and 1.0. 1.0 is a 100% hit rate. |
protected boolean |
removeEldestEntry(java.util.Map.Entry eldest)
Returns true if size() exceeds the capacity of this cache (not map). |
Methods inherited from class java.util.LinkedHashMap |
clear, containsValue |
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 com.tagtraum.perf.datastructures.Cache |
put |
Methods inherited from interface java.util.Map |
equals, hashCode |
LRUCache
public LRUCache(int capacity)
- Creates a LRU cache with the given capacity.
get
public java.lang.Object get(java.lang.Object key)
- Description copied from interface:
Cache
- Retrieves an object from this cache using the given key.
- Specified by:
get
in interface Cache
- Overrides:
get
in class java.util.LinkedHashMap
- Returns:
- null if the object is not in this cache (anymore)
removeEldestEntry
protected boolean removeEldestEntry(java.util.Map.Entry eldest)
- Returns true if size() exceeds the capacity of this cache (not map).
- Overrides:
removeEldestEntry
in class java.util.LinkedHashMap
getCapacity
public int getCapacity()
- Capacity of this cache.
- Specified by:
getCapacity
in interface Cache
getHitRatio
public float getHitRatio()
- Returns a number between 0.0 and 1.0. 1.0 is a 100% hit rate.
- Specified by:
getHitRatio
in interface Cache
Copyright © 2002 Hendrik Schreiber
http://www.tagtraum.com/performance/
This software can be distributed under LGPL