|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.internet2.middleware.subject.util.ExpirableCache<K,V>
K
- key typeV
- value typepublic class ExpirableCache<K,V>
This is like a map, but the setters also take an expire time which will mean the items in the cache will be automatically deleted. Also, every so often (e.g. 2 minutes) all items are checked for expiration. If no timetolive is set, it will default to 1 day. The max time to live is one day. This is synchronized so that all access is safe.
Note, evictions are check for periodically, but only when the map is accessed (and even then only every few minutes). so you can check for evictions externally, or clear the map if you are done with it.
Constructor Summary | |
---|---|
ExpirableCache()
|
|
ExpirableCache(int defaultTimeToLiveInMinutes)
|
Method Summary | |
---|---|
void |
checkForEvictions(boolean onlyCheckIfNeeded)
check and remove elements that are stale |
void |
clear()
delete the cache |
static void |
clearAll()
clear out all caches everywhere (session, request, context, etc) |
V |
get(K key)
get a value or null if not there or expired this will check for eviction, and evict if evictable |
int |
getCacheEvictions()
number of items evicted from cache |
int |
getCacheHits()
number of items successfully retrieved from cache |
int |
getCacheInserts()
number of items inserted into the cache |
void |
put(K key,
V value)
put a value into the cache, accept the default time to live for this cache |
void |
put(K key,
V value,
int timeToLiveInMinutes)
put a value into the cache, accept the default time to live for this cache |
int |
size(boolean evictEvictables)
number of elements in map (and check for |
static String |
staticToString()
string representation of cache |
String |
toString()
string representation of cache |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ExpirableCache()
public ExpirableCache(int defaultTimeToLiveInMinutes)
defaultTimeToLiveInMinutes
- time in minutes is the default cache time to live for contentMethod Detail |
---|
public void clear()
public void put(K key, V value)
key
- value
- public void put(K key, V value, int timeToLiveInMinutes)
key
- value
- timeToLiveInMinutes
- time to live for this item in minutes.
If -1 then use the defaultpublic static void clearAll()
public void checkForEvictions(boolean onlyCheckIfNeeded)
onlyCheckIfNeeded
- true if only check every so often (e.g. every two minutes)public V get(K key)
key
-
public int size(boolean evictEvictables)
evictEvictables
- true if we should evict values that are stale
(even if recently checked)
public int getCacheInserts()
public int getCacheEvictions()
public int getCacheHits()
public String toString()
toString
in class Object
Object.toString()
public static String staticToString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |