1.0.1 • Published 5 years ago

temp_map v1.0.1

Weekly downloads
4
License
MIT
Repository
-
Last release
5 years ago

TempMap

npm version Build Status codecov dependencies Status PRs Welcome

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.