public class ExpiryCache<K,V> extends Object
ConcurrentHashMap so is thread safe.
It does not use any thread for removal of expired entries.
Expired entries are removed when get(Object) or removeExpired() is called.| Constructor and Description |
|---|
ExpiryCache(int expiryMillis)
Initializes the cache
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(K key)
Contains
|
V |
get(K key)
Get value associated with the key
|
V |
put(K key,
V value)
Put the value against the key.
|
V |
put(K key,
V value,
int millis)
Put the value against the key with defined expiry millis
|
void |
removeExpired()
Removes the expired objects
|
int |
size()
This may return an approximate size
|
public ExpiryCache(int expiryMillis)
expiryMillis - Expiry duration in millispublic V put(K key, V value)
key - The keyvalue - The valuepublic V put(K key, V value, int millis)
key - The keyvalue - The valuemillis - The expiry duration in millispublic int size()
public void removeExpired()
public V get(K key)
key - The keypublic boolean contains(K key)
key - the keyCopyright © 2017. All rights reserved.