|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttuwien.auto.calimero.buffer.cache.ExpiringCache
public abstract class ExpiringCache
Implements a cache expiring mechanism for CacheObject
s.
A time span is specified for how long a value is considered valid. After that time for
expiring, the cache object is removed on the next call of removeExpired()
by
an internal CacheSweeper
. If a cache with expiring cache objects is not used
anymore, invoke Cache.clear()
to quit the running cache sweeping mechanism.
The timestamp of CacheObject.getTimestamp()
is used to determine if a cache
object value has expired.
Note that if the timestamp of a CacheObject
changes after it was put into the
cache, the object has to be reinserted (see Cache.put(CacheObject)
) to keep the
cache in a consistent state. If no expiring is used, this might be omitted.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface tuwien.auto.calimero.buffer.cache.Cache |
---|
Cache.Statistic |
Field Summary | |
---|---|
protected static int |
defaultSweepInterval
Default sweep interval in seconds used for a CacheSweeper
(60 seconds). |
protected java.util.Map |
map
The map holding the CacheObject s. |
protected int |
sweepInterval
Sweep interval in seconds used for the CacheSweeper . |
Constructor Summary | |
---|---|
ExpiringCache(int timeToExpire)
Creates an ExpiringCache . |
Method Summary | |
---|---|
protected void |
notifyRemoved(CacheObject obj)
Override this method to get notified when removeExpired() removed a
CacheObject from the map . |
void |
removeExpired()
Removes all CacheObject s, where , with
timeToExpire > 0 and now is the point of time
removeExpired() is invoked. |
protected void |
startSweeper()
Starts a new CacheSweeper , if not already running, and if an expiring time
for CacheObject was specified. |
protected void |
stopSweeper()
Stops the CacheSweeper , if any. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface tuwien.auto.calimero.buffer.cache.Cache |
---|
clear, get, put, remove, statistic |
Field Detail |
---|
protected static final int defaultSweepInterval
CacheSweeper
(60 seconds).
protected java.util.Map map
CacheObject
s.
The map instance itself is not synchronized, synchronization is done using the cache object (this).
protected int sweepInterval
CacheSweeper
.
It defaults to 60 seconds. For a new value to take
effect, it has to be assigned either before the first startSweeper()
call,
or the cache sweeper has to be restarted.
Constructor Detail |
---|
public ExpiringCache(int timeToExpire)
ExpiringCache
.
Note that for the actual begin of cache sweeping startSweeper()
has to be
invoked.
timeToExpire
- time > 0 in seconds for cache entries to stay valid, on time =
0 no expiring of cache entries will occurMethod Detail |
---|
protected void notifyRemoved(CacheObject obj)
removeExpired()
removed a
CacheObject
from the map
.
obj
- removed CacheObject
public void removeExpired()
CacheObject
s, whereCacheObject.getTimestamp()
+ timeToExpire <= now
, with
timeToExpire > 0
and now
is the point of time
removeExpired()
is invoked.
removeExpired
in interface Cache
protected final void startSweeper()
CacheSweeper
, if not already running, and if an expiring time
for CacheObject
was specified.startSweeper
and stopSweeper
are invoked
by different threads, they need to be synchronized.
protected final void stopSweeper()
CacheSweeper
, if any.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |