A TTL cache with an API compatible with an ES6 Map. Requires node 6+.
Parameters
ttl
number The TTL for all entries added to this mapevictInterval
number? How frequently to delete expired entries from the internal mapintialValues
Iterable<[K, V]>? An iterable such as an array or another map containing the initial values to set in the map
Returns void
Removes all key/value pairs from the Map object.
Returns void
Removes any value associated with that key
Parameters
key
K the key to delete
Returns boolean
Returns Iterator<[K, V]> a new iterator object that contains an array of [key, value] for each element in the map that has not expired
Calls fn once for each non-expired key-value pair in the map object
Parameters
fn
function (value: V, index: K, map: any): any the function to callthisArg
any the value of this when fn is called
Returns void
Parameters
key
K
Returns V? the value associated with the key, or undefined if there is none or that entry has expired
Parameters
key
K
Returns boolean indicates if the key has an associated value which hasn't expired
Returns Iterator<K> a new iterator containing the keys of each non-expired entry in the map
Sets the value in the map, with a ttl of Date.now() + map.ttl
Parameters
key
Kvalue
V
Returns any the map
The number of non-expired key/value pairs in the map
Returns number
Returns Iterator<V> a new iterator containing the values of each non-expired entry in the map
Removes every entry from the internal map that has already expired
Returns void