K
- the type of keys.V
- the type of values.public class Cache<K,V> extends Object implements Disposable
Clients may subclass this class.
Modifier and Type | Field and Description |
---|---|
static long |
NO_EXPIRATION
A negative integer to be used as expiration setting when no expiration is desired,
i.e.
|
Constructor and Description |
---|
Cache(long expiration)
Instantiates a cache that uses the specified default expiration setting.
|
Modifier and Type | Method and Description |
---|---|
void |
clean()
Removes the cache entries that are expired.
|
boolean |
containsKey(K key)
Determines whether the cache contains an entry matching the specified key.
|
void |
dispose()
Disposes the cache, which also disposes each cached value that implements
Disposable . |
V |
get(K key)
Returns the value assigned to the specified key in the cache.
|
long |
getExpiration()
Returns the default cache expiration,
i.e.
|
long |
getExpiration(K key)
Returns the cache expiration for the specified key,
i.e.
|
void |
put(K key,
V object)
Changes the value assigned to the specified key in the cache.
|
void |
remove(K key)
Removes the cache entry matching the specified key.
|
void |
removeExpiration(K key)
Remove the specific expiration assigned to the cache entry identified by the specified key.
|
void |
setExpiration(K key,
long expiration)
Changes the cache expiration for the specified key,
i.e.
|
void |
setExpiration(long expiration)
Changes the default cache expiration,
i.e.
|
Map<K,V> |
toMap()
Copies the content of this cache into a
Map instance. |
public static final long NO_EXPIRATION
setExpiration(long)
,
Constant Field Valuespublic Cache(long expiration)
expiration
- the number of milliseconds after which a cache entry is considered expired.
A negative number disables the expiration monitoring.public long getExpiration()
getExpiration(Object)
public void setExpiration(long expiration)
expiration
- the new number of milliseconds after which a cache entry is considered expired.
A negative number disables the expiration monitoring.setExpiration(Object, long)
public long getExpiration(K key)
key
- the key identifying the cache entry for which the expiration is to determine.getExpiration()
public void setExpiration(K key, long expiration)
key
- the key identifying the cache entry for which the expiration is to change.expiration
- the new number of milliseconds after which this cache entry is considered expired.
A negative number disables the expiration monitoring.setExpiration(long)
public void removeExpiration(K key)
key
- the key identifying the cache entry for which the specific expiration is to remove.getExpiration()
public boolean containsKey(K key)
key
- the cache entry to look for.true
if the key is found in the cache, false
otherwise.public V get(K key)
key
- the cache entry to look for.null
if none.public void put(K key, V object)
key
- the cache entry to look for.object
- the value to put in the cache.public void remove(K key)
key
- the cache entry to look for.public void clean()
getExpiration()
public void dispose()
Disposable
.dispose
in interface Disposable