temp_map
v1.0.1
Published
TempMap is in-memory data structure with ttl. It has zero-dependencies.
Downloads
2
Readme
TempMap
TempMap is in-memory data structure with ttl. It has zero-dependencies.
Install
npm i temp_map
Usage example
const { TempMap } = require('temp_map')
const cache = new TempMap()
const expireMs = 1000
cache.set('key', 'value', expireMs)
console.log(cache.get('key')) // value
setTimeout(() => cache.get('key'), 2000) // undefined
Notes
This data structure on top of Node.js timers. Timers are crucial to Node.js.
Internally, any TCP I/O connection creates a timer so that we can time out of connections.
Similar to other hashed wheel timers, Node.js uses a hash table and a linked list
to maintain the timers instances.