ttl-set
Version:
Like a JavaScript Set, but with a TTL on entries
54 lines (34 loc) • 1.03 kB
Markdown
with a TTL on entries
```sh
npm install ttl-set --save
```
```js
const TTLSet = require('ttl-set')
const cache = new TTLSet(60 * 1000) // TTL: 1 minute
cache.add('hello')
// ...wait 40 seconds...
cache.add('world')
// ...wait 40 seconds...
console.log(cache.has('hello')) // => false
console.log(cache.has('world')) // => true
// ...wait 40 seconds...
console.log(cache.has('world')) // => false
```
Create a new instance of the TTLSet.
Takes `ttl` as a required argument,
which is the number of milliseconds for elements to live in the TTLSet before evicting them.
Adds the given `value` to the TTLSet.
Clear all previously added values to the TTLSet.
Returns `true` if the TTLSet contains the given `value`. Returns `false` otherwise.
The number of elements in the TTLSet.
MIT
Like a JavaScript Set, but