Package jadex.commons.collection
Class Cache
- java.lang.Object
-
- jadex.commons.collection.Cache
-
public class Cache extends java.lang.Object
Cache 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 long
DEFAULT_TIME_TO_LIVE
The default time to live time span (5 mins).protected LRU
lru
The lru.protected long
ttl
The time to live.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canExpire(java.lang.Object key)
Test if an entry can expire.boolean
containsKey(java.lang.Object key)
Test if a key is contained.java.lang.Object
get(java.lang.Object key, long now)
Get data from the cache.void
put(java.lang.Object key, java.lang.Object value, long now)
Put an entry in the cache.void
put(java.lang.Object key, java.lang.Object value, long now, long ttl)
Put an entry in the cache.boolean
remove(java.lang.Object key)
Remove an entry.int
size()
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.
-
-