cache-map v1.1.0
CacheMap
A TTL cache with an API compatible with an ES6 Map. Requires node 6+.
constructor
Parameters
ttlnumber The TTL for all entries added to this mapevictIntervalnumber? How frequently to delete expired entries from the internal mapintialValuesIterable<[K, V]>? An iterable such as an array or another map containing the initial values to set in the map
Returns void
clear
Removes all key/value pairs from the Map object.
Returns void
delete
Removes any value associated with that key
Parameters
keyK the key to delete
Returns boolean
entries
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
forEach
Calls fn once for each non-expired key-value pair in the map object
Parameters
fnfunction (value: V, index: K, map: any): any the function to callthisArgany the value of this when fn is called
Returns void
get
Parameters
keyK
Returns V? the value associated with the key, or undefined if there is none or that entry has expired
has
Parameters
keyK
Returns boolean indicates if the key has an associated value which hasn't expired
keys
Returns Iterator<K> a new iterator containing the keys of each non-expired entry in the map
set
Sets the value in the map, with a ttl of Date.now() + map.ttl
Parameters
keyKvalueV
Returns any the map
size
The number of non-expired key/value pairs in the map
Returns number
values
Returns Iterator<V> a new iterator containing the values of each non-expired entry in the map
deleteExpired
Removes every entry from the internal map that has already expired
Returns void