K - The type of the key to storeV - The type of the value to storepublic class ExpiringCache<K,V>
extends java.lang.Object
implements java.util.Map<K,V>
| Modifier and Type | Class and Description |
|---|---|
static interface |
ExpiringCache.OnEvictRunnable<V> |
| Constructor and Description |
|---|
ExpiringCache(long expireTimeMs)
Expiring cache constructor.
|
ExpiringCache(long expireTimeMs,
@Nullable ExpiringCache.OnEvictRunnable<V> onEvictRunnable)
Expiring cache constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears all mapping from the cache.
|
boolean |
containsKey(java.lang.Object key)
Checks if the cache contains a specific key.
|
boolean |
containsValue(java.lang.Object value)
Checks if the cache contains a specific value.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a
Set view of the keys. |
V |
get(java.lang.Object key)
Retrieves the value from a key.
|
long |
getExpireTime()
Accessor method for expireTimeMs.
|
java.util.concurrent.locks.ReentrantLock |
getLock() |
boolean |
isEmpty()
Checks whether it is empty.
|
java.util.Set<K> |
keySet()
Returns a
Set view of the keys. |
V |
put(K key,
V value)
Associates a specified value with a specified key in this map.
|
void |
putAll(java.util.Map<? extends K,? extends V> m)
Copies the content from one map to the current map.
|
V |
remove(java.lang.Object key)
Removes the mapping for a key if it's present.
|
void |
setExpireTime(long expireTimeMs)
Mutator method for expireTimeMs.
|
void |
setOnEvictRunnable(ExpiringCache.OnEvictRunnable<V> onEvictRunnable) |
int |
size()
Retrieves the number of items stored.
|
java.util.Collection<V> |
values()
Returns a
Collection view of the keys. |
public ExpiringCache(long expireTimeMs)
expireTimeMs - The expired time in Mspublic ExpiringCache(long expireTimeMs,
@Nullable ExpiringCache.OnEvictRunnable<V> onEvictRunnable)
expireTimeMs - The expired time in MsonEvictRunnable - A function that will be called on each evicted cache entrypublic void setExpireTime(long expireTimeMs)
expireTimeMs - The expired time in Mspublic long getExpireTime()
public int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public V get(java.lang.Object key)
public V remove(java.lang.Object key)
public void putAll(java.util.Map<? extends K,? extends V> m)
public void clear()
public java.util.Set<K> keySet()
Set view of the keys.public java.util.Collection<V> values()
Collection view of the keys.public void setOnEvictRunnable(ExpiringCache.OnEvictRunnable<V> onEvictRunnable)
public java.util.concurrent.locks.ReentrantLock getLock()