Socket
Book a DemoInstallSign in
Socket

ttl-set

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ttl-set

Like a JavaScript Set, but with a TTL on entries

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

ttl-set

Like a JavaScript Set, but with a TTL on entries

Installation

npm install ttl-set --save

Usage

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

API

TTLSet(ttl) constructor

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.

TTLSet.prototype.add(value)

Adds the given value to the TTLSet.

TTLSet.prototype.clear()

Clear all previously added values to the TTLSet.

TTLSet.prototype.has(value)

Returns true if the TTLSet contains the given value. Returns false otherwise.

TTLSet.prototype.size

The number of elements in the TTLSet.

License

MIT

Keywords

ttl

FAQs

Package last updated on 05 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts