|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object echopoint.util.ExpiryCache
ExpiryCache
implements a cache that can contain
objects that "expire". A shared background task will
periodically "reap" objects that have "expired".
By default, soft references are used to the cached data so that they can be reclaimed in low memory conditions regardless of whether they have expired or not.
The time-to-live and access-timeout is used to decide when an object has expired and needs to be removed from the cache.
Time-to-live is simple. Once the specified period elapses, the object is removed from the cache, regardless of how many times its been accessed.
Access-timeout is a little more complicated. Each time the object is taken from the cache, its lastAccessTime is tracked. If the access-timeout has expired (since its last access) then the object is taken from the cache.
If both the time-to-live and access-timeout is -1, then the object will never expire from the cache.
Field Summary | |
static long |
DEFAULT_ACCESS_TIMEOUT
the default cache access time out 5 minutes |
static long |
DEFAULT_REAPER_INTERVAL
The reaper interval is 2 minutes. |
static long |
DEFAULT_TIME_TO_LIVE
the default cache time-to-live is 10 minutes |
Constructor Summary | |
ExpiryCache()
Constructs a default ExpiryCache |
|
ExpiryCache(long timeToLive,
long accessTimeout)
Constructs a ExpiryCache |
|
ExpiryCache(long timeToLive,
long accessTimeout,
boolean softReferences)
Constructs a ExpiryCache with all the parameters |
Method Summary | |
void |
clear()
Clears the cache of all contained objects |
boolean |
containsKey(java.lang.Object key)
Returns true if this ExpiryCache contains an entry for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this ExpiryCache contains a key to the specified value. |
java.lang.Object |
get(java.lang.Object key)
Retrieves an object from the cache |
int |
howManyObjects()
Returtns how many objects are currently in the cache. |
int |
howManyTimesAccessed(java.lang.Object key)
Returns the number of times the object was accessed under a given key |
boolean |
isSoftReferences()
Returns true if soft refernces are used to cached data |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object objToCache)
Places an object into the cache. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object objToCache,
long timeToLive,
long accessTimeout)
Places an object into the cache with the specified 'time-to-live' and a 'access time out' value. |
void |
setAccessTimeout(long milliSecs)
Sets the default access timeout for a cache entry |
void |
setTimeToLive(long milliSecs)
Sets the default 'time-to-live' for a cache entry |
long |
whenCached(java.lang.Object key)
Returns the time when the object was cached under a given key |
long |
whenLastAccessed(java.lang.Object key)
Returns the time when the object was last accessed under a given key |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long DEFAULT_TIME_TO_LIVE
public static final long DEFAULT_ACCESS_TIMEOUT
public static final long DEFAULT_REAPER_INTERVAL
Constructor Detail |
public ExpiryCache()
ExpiryCache
public ExpiryCache(long timeToLive, long accessTimeout)
ExpiryCache
timeToLive
- - the default time-to-live for a cache entryaccessTimeout
- - the default access timeout for a cache entrypublic ExpiryCache(long timeToLive, long accessTimeout, boolean softReferences)
ExpiryCache
with all the parameters
timeToLive
- - the default time-to-live for a cache entryaccessTimeout
- - the default access timeout for a cache entrysoftReferences
- - whether soft refernces are used to cached dataMethod Detail |
public void setTimeToLive(long milliSecs)
milliSecs
- - 'time-to-live' for a cache entrypublic void setAccessTimeout(long milliSecs)
milliSecs
- - access timeout for a cache entrypublic int howManyObjects()
public void clear()
public java.lang.Object put(java.lang.Object key, java.lang.Object objToCache)
key
- - the key of the cached objectobjToCache
- - the object to cache
public java.lang.Object put(java.lang.Object key, java.lang.Object objToCache, long timeToLive, long accessTimeout)
key
- - the key of the cached objectobjToCache
- - the object to cachetimeToLive
- - the time-to-live on the object or -1 to live for everaccessTimeout
- - the accessTimeout on the object or -1 to never time out
public java.lang.Object get(java.lang.Object key)
key
- - the key to the cached object
public boolean containsKey(java.lang.Object key)
key
- key whose presence in this map is to be tested.
public boolean containsValue(java.lang.Object value)
value
- value whose presence in this map is to be tested.
public long whenCached(java.lang.Object key)
key
- - the key to the cached object
public long whenLastAccessed(java.lang.Object key)
key
- - the key to the cached object
public int howManyTimesAccessed(java.lang.Object key)
key
- - the key to the cached object
public boolean isSoftReferences()
|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |