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 long
The default time to live time span (5 mins).protected LRU
The lru.protected long
The time to live. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Test if an entry can expire.boolean
containsKey
(Object key) Test if a key is contained.Get data from the cache.void
Put an entry in the cache.void
Put an entry in the cache.boolean
Remove an entry.int
size()
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.
-