| java.util.LinkedHashMap org.cougaar.util.LRUExpireMap
LRUExpireMap | public class LRUExpireMap extends LinkedHashMap (Code) | | An LRUExpireMap is a simple least-recently-used cache that also
expires entries based on the system time.
Entries are put in the map with an explicit expiration time. The
cache will not return expired entries and will remove them
automatically. The cache also has a maximum size to limit the
number of non-expired entries.
The caller must synchronized access on this map.
If you just want a simple LRU cache then see the javadocs for
LinkedHashMap, where you can override the
"removeEldestEntry(..)" method.
|
Inner Class :public interface Config | |
Inner Class :public interface Watcher | |
Inner Class :public static class Expirable implements Serializable | |
Field Summary | |
final protected Config | config | final protected Watcher | watcher |
Constructor Summary | |
public | LRUExpireMap(Config config, Watcher watcher) |
config | final protected Config config(Code) | | |
watcher | final protected Watcher watcher(Code) | | |
LRUExpireMap | public LRUExpireMap(Config config, Watcher watcher)(Code) | | |
get | public Object get(Object key, boolean bypass)(Code) | | Get a value with an optional "bypass the cache" flag".
The config's "minBypassTime()" is consulted if the
entry has not expired. This allows the config to
limit the bypass to a fixed time from the "put(..)"
of the entry (e.g. "you can only bypass if the
entry is older than 5 seconds").
the value |
getExpirable | protected Expirable getExpirable(Object key)(Code) | | |
getExpirable | protected Expirable getExpirable(Object key, boolean bypass)(Code) | | |
getExpirationTime | public long getExpirationTime(Object key)(Code) | | Get the expiration time for an entry.
-1 if the entry is not in the cache or has expired. |
put | public Object put(Object key, Object value, long expireTime)(Code) | | Put an entry in the cache with an expiration time.
If it has already expired, this is method removes the old
value (even if it hasn't expired) and ignores the new value.
the old value if one was replaced |
removeEldestEntry | protected boolean removeEldestEntry(Map.Entry eldest)(Code) | | Called by the LinkedHashMap when an entry is added,
this allows the cache to remove the LRU "eldest" entry.
|
trim | public boolean trim()(Code) | | Remove all expired entries from the cache.
This can optionally be called on a periodic timer, but
it's not necessary -- the cache will limit its size based
upon the config's "maxSize()".
true if anything was removed |
|
|