Returns the number of keys being stored.
Adds event listener.
Events
Event name
Event handler
Deletes the value under key
, if present.
Returns true if something was removed.
Deletes all values where elapsed time has past for get/set or either.
// Delete all keys (and associated values) not accessed for a minute
em.deleteWithElapsed({mins:1}, `get`);
// Delete things that were set 1s ago
em.deleteWithElapsed(1000, `set`);
Interval
Basis for deletion 'get','set' or 'either'
Items removed
Returns the elapsed time since key
was accessed. Returns undefined if key
does not exist
Returns the elapsed time since key
was set. Returns undefined if key
does not exist
Protected
fireFire event
Type of event
Arguments for event
Returns true if key
is stored.
Does not affect the key's last access time.
Remove event listener
Updates the lastSet/lastGet time for a value
under k
.
Returns false if key was not found
A map that can have a capacity limit. The elapsed time for each get/set operation is maintained allowing for items to be automatically removed.
has()
does not affect the last access time.By default, it uses the
none
eviction policy, meaning that when full an error will be thrown if attempting to add new keys.Eviction policies:
oldestGet
removes the item that hasn't been accessed the longest,oldestSet
removes the item that hasn't been updated the longest.Last set/get time for a key can be manually reset using touch.
Events:
The map can automatically remove items based on elapsed intervals.
Example
Automatically delete items that haven't been accessed for one second
Example
Automatically delete the oldest item if we reach a capacity limit