Package jadex.collection
Class Cache
java.lang.Object
jadex.collection.Cache
Cache that provide expiration in case of
a) timetolive is exceeded
b) the max number of data has been reached (lru behaviour)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default time to live time span (5 mins).protected LRUThe lru.protected longThe time to live. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTest if an entry can expire.booleancontainsKey(Object key) Test if a key is contained.Get data from the cache.voidPut an entry in the cache.voidPut an entry in the cache.booleanRemove an entry.intsize()Get the size.
-
Field Details
-
DEFAULT_TIME_TO_LIVE
public static final long DEFAULT_TIME_TO_LIVEThe default time to live time span (5 mins).- See Also:
-
lru
The lru. -
ttl
protected long ttlThe time to live.
-
-
Constructor Details
-
Cache
public Cache(int max) Create a new cache. -
Cache
public Cache(int max, long ttl) Create a new cache. -
Cache
Create a new cache.
-
-
Method Details
-
put
Put an entry in the cache.- Parameters:
key- The key.value- The value.now- The current time.
-
put
Put an entry in the cache.- Parameters:
key- The key.value- The value.now- The current time (-1 for never expire).
-
get
Get data from the cache.- Parameters:
key- The key.now- The current time (-1 for never expire).- Returns:
- The cached object.
-
remove
Remove an entry.- Parameters:
key- The key.
-
containsKey
Test if a key is contained.- Parameters:
key- The key.- Returns:
- True if contained.
-
canExpire
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.
-