|
Purple Code | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.purpletech.util.Cache
An object cache that eventually times out its elements. The constructor automatically starts a background thread. You may subclass two important methods:
You may also override expire() to implement your own expiration heuristic (e.g. LMF, which is ``last modified factor'' (LMF), calculated as the ratio of two time periods: LMF = (time since last validated) / (age when last validated) -- if LMF>some threshold (i.e. 20%), then the cached data is considered stale)
| Nested Class Summary | |
class |
Cache.Entry
an entry in a cache. |
class |
Cache.StringKey
A sample Primary Key class containing merely a string. |
| Field Summary | |
protected long |
sleep
|
protected long |
timeout
|
| Constructor Summary | |
Cache()
|
|
Cache(long timeout)
|
|
| Method Summary | |
protected boolean |
expire(java.lang.Object key,
Cache.Entry entry,
long now)
Subclasses should override this to provide their own expiration heuristic. |
java.lang.Object |
get(java.lang.Object key)
Get an item from the cache. |
long |
getAccessed(java.lang.Object key)
Convenience method to get the time this key's data was last accessed |
long |
getEntered(java.lang.Object key)
Convenience method to get the time this key's data was entered into the cache. |
Cache.Entry |
getEntry(java.lang.Object key)
Get all information about this cache entry, including the object itself, and the times it was accessed and entered. |
java.util.Map |
getMap()
returns an unmodifiable Map for the entries in the cache. |
int |
getSize()
|
java.lang.Object |
load(java.lang.Object key)
Callback that loads an object or otherwise generates it when it's needed. |
void |
put(java.lang.Object key,
java.lang.Object data)
Add an item to the cache explicitly. |
void |
remove(java.lang.Object key)
Explicitly remove item from cache |
void |
run()
|
void |
setSleep(long msec)
|
void |
setTimeout(long msec)
|
boolean |
test(java.lang.Object key,
Cache.Entry current)
Callback that provides an extra check as to whether an object needs to be reloaded. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected long timeout
protected long sleep
| Constructor Detail |
public Cache()
public Cache(long timeout)
| Method Detail |
public void setTimeout(long msec)
msec - the maximum time an item can sit in the cache without being accessed before it gets removedpublic void setSleep(long msec)
msec - the time that the expiry thread sleeps before waking up and checking for expirable items
public void put(java.lang.Object key,
java.lang.Object data)
public java.lang.Object get(java.lang.Object key)
Note that load() can return null, which means you must explicitly add objects to the cache.
public Cache.Entry getEntry(java.lang.Object key)
public long getEntered(java.lang.Object key)
public long getAccessed(java.lang.Object key)
public int getSize()
public java.util.Map getMap()
public void remove(java.lang.Object key)
public boolean test(java.lang.Object key,
Cache.Entry current)
key - the key object for the desired datacurrent - the current data for this key in the cache
public java.lang.Object load(java.lang.Object key)
public void run()
run in interface java.lang.Runnable
protected boolean expire(java.lang.Object key,
Cache.Entry entry,
long now)
key - key of object we're looking atentry - entry of object we're looking atnow - current system time
|
Documentation generated March 5 2003 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||