|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.TimerTask org.jboss.util.TimedCachePolicy
An implementation of a timed cache. This is a cache whose entries have a limited lifetime with the ability to refresh their lifetime. The entries managed by the cache implement the TimedCachePolicy.TimedEntry interface. If an object inserted into the cache does not implement this interface, it will be wrapped in a DefaultTimedEntry and will expire without the possibility of refresh after getDefaultLifetime() seconds. This is a lazy cache policy in that objects are not checked for expiration until they are accessed.
Nested Class Summary | |
static interface |
TimedCachePolicy.TimedEntry
The interface that cache entries support. |
Field Summary | |
protected int |
defaultLifetime
The lifetime in seconds to use for objects inserted that do not implement the TimedEntry interface. |
protected Map |
entryMap
The map of cached TimedEntry objects. |
protected long |
now
The caches notion of the current time |
protected int |
resolution
The resolution in seconds of the cach current time |
protected static Timer |
resolutionTimer
|
protected boolean |
threadSafe
A flag indicating if entryMap should be synchronized |
Constructor Summary | |
TimedCachePolicy()
Creates a new TimedCachePolicy with a default entry lifetime of 30 mins that does not synchronized access to its policy store and uses a 60 second resolution. |
|
TimedCachePolicy(int defaultLifetime)
Creates a new TimedCachePolicy with the given default entry lifetime that does not synchronized access to its policy store and uses a 60 second resolution. |
|
TimedCachePolicy(int defaultLifetime,
boolean threadSafe,
int resolution)
Creates a new TimedCachePolicy with the given default entry lifetime that does/does not synchronized access to its policy store depending on the value of threadSafe. |
Method Summary | |
void |
create()
Initializes the cache for use. |
long |
currentTimeMillis()
Get the cache time. |
void |
destroy()
Clears the cache of all entries. |
void |
flush()
Remove all entries from the cache. |
Object |
get(Object key)
Get the cache value for key if it has not expired. |
int |
getDefaultLifetime()
Get the default lifetime of cache entries. |
int |
getResolution()
Get the frequency of the current time snapshot. |
List |
getValidKeys()
Get the list of keys for entries that are not expired. |
void |
insert(Object key,
Object value)
Insert a value into the cache. |
Object |
peek(Object key)
Get the cache value for key. |
TimedCachePolicy.TimedEntry |
peekEntry(Object key)
Get the raw TimedEntry for key without performing any expiration check. |
void |
remove(Object key)
Remove the entry associated with key and call destroy on the entry if found. |
void |
run()
The TimerTask run method. |
void |
setDefaultLifetime(int defaultLifetime)
Set the default lifetime of cache entries for new values added to the cache. |
void |
setResolution(int resolution)
Set the cache timer resolution |
int |
size()
Get the size of the cache. |
void |
start()
Schedules this with the class resolutionTimer Timer object for execution every resolution seconds. |
void |
stop()
Stop cancels the resolution timer and flush()es the cache. |
Methods inherited from class java.util.TimerTask |
cancel, scheduledExecutionTime |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static Timer resolutionTimer
protected Map entryMap
protected int defaultLifetime
protected boolean threadSafe
protected long now
protected int resolution
Constructor Detail |
public TimedCachePolicy()
public TimedCachePolicy(int defaultLifetime)
public TimedCachePolicy(int defaultLifetime, boolean threadSafe, int resolution)
defaultLifetime
- - the lifetime in seconds to use for objects inserted
that do not implement the TimedEntry interface.threadSafe
- - a flag indicating if the cach store should be synchronized
to allow correct operation under multi-threaded access. If true, the
cache store is synchronized. If false the cache store is unsynchronized and
the cache is not thread safe.resolution
- - the resolution in seconds of the cache timer. A cache does
not query the system time on every get() invocation. Rather the cache
updates its notion of the current time every 'resolution' seconds.Method Detail |
public void create()
create
in interface CachePolicy
public void start()
start
in interface CachePolicy
public void stop()
stop
in interface CachePolicy
public void destroy()
destroy
in interface CachePolicy
public Object get(Object key)
get
in interface CachePolicy
key
- the key paired with the object
CachePolicy.peek(java.lang.Object)
public Object peek(Object key)
peek
in interface CachePolicy
key
- the key paired with the object
CachePolicy.get(java.lang.Object)
public void insert(Object key, Object value)
insert
in interface CachePolicy
key
- - the key for the cache entryvalue
- - Either an instance of TimedEntry that will be inserted without
change, or an abitrary value that will be wrapped in a non-refreshing
TimedEntry.CachePolicy.remove(java.lang.Object)
public void remove(Object key)
remove
in interface CachePolicy
key
- the key paired with the objectCachePolicy.insert(java.lang.Object, java.lang.Object)
public void flush()
flush
in interface CachePolicy
public int size()
CachePolicy
size
in interface CachePolicy
public List getValidKeys()
public int getDefaultLifetime()
public void setDefaultLifetime(int defaultLifetime)
defaultLifetime
- - lifetime in seconds of cache values that do
not implement TimedEntry.public int getResolution()
public void setResolution(int resolution)
resolution
- - the resolution in seconds of the cache timer. A cache does
not query the system time on every get() invocation. Rather the cache
updates its notion of the current time every 'resolution' seconds.public void run()
public long currentTimeMillis()
public TimedCachePolicy.TimedEntry peekEntry(Object key)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |