|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
java.util.HashMap
org.jasig.portal.concurrency.caching.LRUCache
public class LRUCache
A rewrite of SmartCache that uses a moderate LRU algorithm: entries are purged from the cache via periodic sweeps rather than in response to specific cache additions. Note that sweeps have to be kicked off externally, e.g.,
int MAX_CACHE_SIZE = 1000;
int MAX_UNUSED_TIME_MILLIS = 30*60*1000;
LRUCache cache = new LRUCache(MAX_CACHE_SIZE, MAX_UNUSED_TIME_MILLIS);
// ... put stuff in ...
cache.sweepCache()
// ... put more stuff in ...
At the end of the sweep, the cache will have no more (and possibly less)
than maxSize
entries, though the sweep may have to reduce
maxUnusedTimeMillis
in order to get there.
SmartCache
,
Serialized FormNested Class Summary | |
---|---|
private class |
LRUCache.ValueWrapper
|
Field Summary | |
---|---|
protected static int |
DEFAULT_MAX_SIZE
|
protected static int |
DEFAULT_MAX_UNUSED_TIME_MILLIS
|
protected int |
maxSize
|
protected int |
maxUnusedTimeMillis
|
Constructor Summary | |
---|---|
LRUCache()
|
|
LRUCache(int size)
|
|
LRUCache(int size,
int maxUnusedAge)
|
Method Summary | |
---|---|
void |
clear()
Synchronizes removal of ALL entries from the cache. |
java.lang.Object |
get(java.lang.Object key)
Get the object from the cache and reset the timestamp. |
private java.lang.Object[] |
getKeySetArray()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Add a new value to the cache. |
java.lang.Object |
remove(java.lang.Object key)
Synchronizes removal of an entry from the cache. |
void |
sweepCache()
Sweep the cache until it gets back under maxSize . |
Methods inherited from class java.util.HashMap |
---|
clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, 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 |
---|
equals, hashCode |
Field Detail |
---|
protected static int DEFAULT_MAX_SIZE
protected int maxSize
protected static int DEFAULT_MAX_UNUSED_TIME_MILLIS
protected int maxUnusedTimeMillis
Constructor Detail |
---|
public LRUCache()
public LRUCache(int size)
public LRUCache(int size, int maxUnusedAge)
size
- intmaxUnusedAge
- intMethod Detail |
---|
public void clear()
clear
in interface java.util.Map
clear
in class java.util.HashMap
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.HashMap
key
- the key, typically a String
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.HashMap
key
- the key, typically a Stringvalue
- the value
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.HashMap
key
- the key, typically a String
public void sweepCache()
maxSize
.
private java.lang.Object[] getKeySetArray()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |