|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.cache.LRUCache<K,T>
public class LRUCache<K,T>
Hard reference hash map with Least Recently Used ordering over entries. The keys are object identifiers. The values are cache entries wrapping the identified objects.
HardReferenceQueue. This
will change the delegation interfaces since the ring buffer does NOT
support random access by the identifier.| Nested Class Summary | |
|---|---|
protected static interface |
LRUCache.ICacheOrderChangeListener<K,T>
|
| Field Summary | |
|---|---|
protected static boolean |
INFO
|
protected static org.apache.log4j.Logger |
log
|
| Constructor Summary | |
|---|---|
LRUCache(int capacity)
Create an LRU cache with a default load factor of 0.75. |
|
LRUCache(int capacity,
float loadFactor)
Create an LRU cache with the specific capacity and load factor. |
|
| Method Summary | |
|---|---|
protected void |
addCacheOrderChangeListener(LRUCache.ICacheOrderChangeListener<K,T> l)
Registers a listener for removeEntry events. |
int |
capacity()
The capacity of the cache. |
void |
clear()
Clear all objects from the cache. |
Iterator<ICacheEntry<K,T>> |
entryIterator()
Visits entries in the cache in LRU ordering (the
least recently used object is visited first). |
protected void |
finalize()
Writes cache performance statistics. |
T |
get(K key)
Return the indicated object from the cache or null if the object is not in cache. |
ICacheListener<K,T> |
getCacheListener()
Return the cache eviction listener. |
double |
getHitRatio()
|
long |
getInsertCount()
|
String |
getStatistics()
|
long |
getSuccessCount()
|
long |
getTestCount()
|
Iterator<T> |
iterator()
Visits objects in the cache in LRU ordering (the least recently used object is visited first). |
void |
put(K key,
T obj,
boolean dirty)
Add the object to the hash map under the key if it is not already there and update the entry ordering (this can be used to touch an entry). |
T |
remove(K key)
Remove the indicated object from the cache. |
protected void |
removeCacheOrderChangeListener(LRUCache.ICacheOrderChangeListener<K,T> l)
Unregister the listener. |
void |
resetStatistics()
|
void |
setListener(ICacheListener<K,T> listener)
Sets the cache eviction listener on the hard reference cache. |
int |
size()
The #of entries in the cache. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
| Constructor Detail |
|---|
public LRUCache(int capacity)
0.75.
capacity - The capacity of the cache.
public LRUCache(int capacity,
float loadFactor)
capacity - The capacity of the cache (must be positive).loadFactor - The load factor for the internal hash table.| Method Detail |
|---|
public double getHitRatio()
public long getInsertCount()
public long getTestCount()
public long getSuccessCount()
public void setListener(ICacheListener<K,T> listener)
ICachePolicy
setListener in interface ICachePolicy<K,T>listener - The listener or null to remove any listener.public ICacheListener<K,T> getCacheListener()
ICachePolicy
getCacheListener in interface ICachePolicy<K,T>public Iterator<T> iterator()
Visits objects in the cache in LRU ordering (the least recently used object is visited first).
The returned iterator is NOT thread safe. It supports removal but does NOT support concurrent modification of the cache state. Normally the iterator is used during a commit and the framework guarantees that concurrent
iterator in interface ICachePolicy<K,T>ICachePolicy.entryIterator()public Iterator<ICacheEntry<K,T>> entryIterator()
Visits entries in the cache in LRU ordering (the
least recently used object is visited first).
The returned iterator is NOT thread safe. It supports removal but does NOT support concurrent modification of the cache state. Normally the iterator is used during a commit and the framework guarantees that concurrent
entryIterator in interface ICachePolicy<K,T>ICacheEntry objects. If this is a weak
reference cache, then the iterator visits the entries in the
delegate hard reference cache.ICacheEntry,
ICachePolicy.iterator()public void clear()
ICachePolicy
clear in interface ICachePolicy<K,T>public void resetStatistics()
public int size()
size in interface ICachePolicy<K,T>public int capacity()
capacity in interface ICachePolicy<K,T>
protected void finalize()
throws Throwable
finalize in class ObjectThrowablepublic String getStatistics()
public void put(K key,
T obj,
boolean dirty)
Add the object to the hash map under the key if it is not already there and update the entry ordering (this can be used to touch an entry).
Cache evictions are only performed at or over capacity, but not
for reentrant invocations. If a cache eviction causes a nested
#put(long, Object, boolean) cache enters a temporary
over capacity condition. The nested eviction is effectively
deferred and a new cache entry is created for the incoming object rather
than recycling the LRU cache entry. This temporary over capacity state
exists until the primary eviction event has been handled, at which point
entries are purged from the cache until it has one free entry. That free
entry is then used to cache the incoming object which triggered the outer
eviction event.
This is not the only coherent manner in which nested eviction events could be handled, but it is perhaps the simplest. This technique MUST NOT be used with an open array hash table since the temporary over capacity condition would not be supported.
put in interface ICachePolicy<K,T>key - The object identifier.obj - The object.dirty - True iff the object is dirty.public T get(K key)
ICachePolicy
get in interface ICachePolicy<K,T>key - The object identifier.
public T remove(K key)
ICachePolicy
remove in interface ICachePolicy<K,T>key - The object identifier.
null if there was no object under that identifier.protected void addCacheOrderChangeListener(LRUCache.ICacheOrderChangeListener<K,T> l)
LRUIterator to handle concurrent modifications of the cache
ordering during traversal.
protected void removeCacheOrderChangeListener(LRUCache.ICacheOrderChangeListener<K,T> l)
l - The listener.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||