public interface Cache
Modifier and Type | Method and Description |
---|---|
void |
clear()
Empties the entire cache by expiring and removing all objects.
|
void |
close()
Closes this cache, which makes all items in the cache unavailable.
|
boolean |
containsKey(Object key)
Returns true if the cache has a valid cached item specified by the
key.
|
void |
expire(Object key)
Expires immediately the object specified by the key.
|
void |
extend(Object key,
long extendTime)
Adds the specified amount of time to the object (to it's current time left)
before that object will be expired.
|
Object |
get(Object key)
Returns the cached item specified by the key.
|
Map |
getAll()
Returns all objects in the cache.
|
long |
getDefaultTTL()
Gets the default TTL in milliseconds.
|
long |
getTimeLeft(Object key)
Returns the amount of time left (in milliseconds) before the object will be
expired from the cache.
|
boolean |
isClosed()
Returns true if this cache has been closed, false otherwise.
|
Object |
put(Object key,
Object item)
Convenience method that puts an object into the cache that expires in
the default TTL.
|
Object |
put(Object key,
Object val,
long expiry)
Puts the specified object into the cache, mapped with the specified key.
|
void |
setDefaultTTL(long millis)
Sets the default TTL in milliseconds.
|
void clear()
boolean containsKey(Object key)
key
- typically a String but can be any objectObject get(Object key)
key
- typically a String but can be any objectMap getAll()
Modification to this map will affect this cache.
Object put(Object key, Object val, long expiry)
key
- key with which the specified value is to be associated.val
- value to be associated with the specified key.expiry
- time in milliseconds (from the time the
object is put into the cache) before it is expired. Specify
-1 for the item to never expire.Object put(Object key, Object item)
setDefaultTTL(long)
method and subclasses are free to implement a default TTL as they see fit.
If that key already contains a value, then that value is returned by this
method (and also replaced by the new value).long getTimeLeft(Object key)
If the object specified by the key is not found in the cache, then 0 is returned.
If the object has already expired, then 0 is returned.
If the object will never expire, then -1 is returned.
key
- the key with which to find the object under consideration.void expire(Object key)
key
- the key with which to find the object under consideration.void extend(Object key, long extendTime)
key
- the key with which to find the object
under consideration.extendTime
- exntension time in milliseconds, valid
values are >= 0 and -1void setDefaultTTL(long millis)
long getDefaultTTL()
void close()
boolean isClosed()