Decorates a
Map
to evict expired entries once their expiration time has been reached.
When putting a key-value pair in the map this decorator uses a {@link ExpirationPolicy} to determine how long the entry should remain aliveas defined by an expiration time value.
When accessing the mapped value for a key, its expiration time is checked, and if it is a negative value or if it is greater than the current time, the mapped value is returned. Otherwise, the key is removed from the decorated map, and null
is returned.
When invoking methods that involve accessing the entire map contents (i.e {@link #containsKey(Object)}, {@link #entrySet()}, etc.) this decorator removes all expired entries prior to actually completing the invocation.
Note that {@link PassiveExpiringMap} is not synchronized and is notthread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw exceptions when accessed by concurrent threads without synchronization.
@param < K> the type of the keys in the map
@param < V> the type of the values in the map
@since 4.0
@version $Id: PassiveExpiringMap.java 1481598 2013-05-12 16:28:28Z tn $