Module id.xfunction

Class TemporaryHashMap<K,V>

Object
TemporaryHashMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class TemporaryHashMap<K,V> extends Object implements Map<K,V>
HashMap which caches every pair for specified period of time and when it expires such pair is removed.

The deletion of expired pairs is passive which means they may not be deleted immediately once they are expired but only during next put(Object, Object) or putAll(Map) operations. To change it to active users can setup ScheduledExecutorService to call cleanupExpired().

Keys are subject to expiration and not values associated with them. It means if user adds pair "key1": "val1", and later replace value to "key1": "val2" this will not affect this pair expiration time.

It is based on HashMap so all HashMap properties applies to TemporaryHashMap.