Package jadex.commons.collection
Class Cache
- java.lang.Object
-
- jadex.commons.collection.Cache
-
public class Cache extends java.lang.ObjectCache that provide expiration in case of a) timetolive is exceeded b) the max number of data has been reached (lru behaviour)
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_TIME_TO_LIVEThe default time to live time span (5 mins).protected LRUlruThe lru.protected longttlThe time to live.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanExpire(java.lang.Object key)Test if an entry can expire.booleancontainsKey(java.lang.Object key)Test if a key is contained.java.lang.Objectget(java.lang.Object key, long now)Get data from the cache.voidput(java.lang.Object key, java.lang.Object value, long now)Put an entry in the cache.voidput(java.lang.Object key, java.lang.Object value, long now, long ttl)Put an entry in the cache.booleanremove(java.lang.Object key)Remove an entry.intsize()Get the size.
-
-
-
Field Detail
-
DEFAULT_TIME_TO_LIVE
public static final long DEFAULT_TIME_TO_LIVE
The default time to live time span (5 mins).- See Also:
- Constant Field Values
-
lru
protected LRU lru
The lru.
-
ttl
protected long ttl
The time to live.
-
-
Constructor Detail
-
Cache
public Cache(int max)
Create a new cache.
-
Cache
public Cache(int max, long ttl)Create a new cache.
-
Cache
public Cache(LRU lru, long ttl)
Create a new cache.
-
-
Method Detail
-
put
public void put(java.lang.Object key, java.lang.Object value, long now)Put an entry in the cache.- Parameters:
key- The key.value- The value.now- The current time.
-
put
public void put(java.lang.Object key, java.lang.Object value, long now, long ttl)Put an entry in the cache.- Parameters:
key- The key.value- The value.now- The current time (-1 for never expire).
-
get
public java.lang.Object get(java.lang.Object key, long now)Get data from the cache.- Parameters:
key- The key.now- The current time (-1 for never expire).- Returns:
- The cached object.
-
remove
public boolean remove(java.lang.Object key)
Remove an entry.- Parameters:
key- The key.
-
containsKey
public boolean containsKey(java.lang.Object key)
Test if a key is contained.- Parameters:
key- The key.- Returns:
- True if contained.
-
canExpire
public boolean canExpire(java.lang.Object key)
Test if an entry can expire.- Parameters:
key- The key.- Returns:
- True, if entry can expire.
-
size
public int size()
Get the size.- Returns:
- The size.
-
-