New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cache-set

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-set

a Set cache, self-clearing, with willDelete hook

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

cache-set

build status AppVeyor Build Status

A minimal cache that actually just is a Set.

Get it!

npm install --save cache-set

Usage

var CacheSet = require('cache-set')
var cache = new CacheSet()

cache.add(27, 419) // time-to-live, value

console.log(cache, cache.size)

setTimeout(function () {
  console.log(cache, cache.size) // will be empty
}, 28)

API

var cache = new CacheSet([ttl, iterable][, willDelete(value, doDelete)])

Create a new CacheSet instance. If iterable is provided all passed items get added to the set during instantiation, and deleted after ttl. If willDelete is a function it will be called as a cleanup hook before items are deleted from the set but after ttl has exceeded. Make sure to call the doDelete callback at the end of the willDelete hook to actually perform the deletion.

cache.add(ttl, ...itemsAndOptionalwillDeleteHook)

Provide ttl, time to live in ms, and a variable number of items that will get deleted from the set at the end of their lifetime. If the last argument is a function it will be called as a cleanup hook before items are deleted from the set but after ttl has exceeded. Make sure to call the doDelete callback at the end of the willDelete hook to actually perform the deletion.

cache.find(predicate)

Find a value in the set. Equivalent to Array.prototype.find.

cache.some(predicate)

Check if any predicate(value) is truthy. Equivalent to Array.prototype.some.

cache.every(predicate)

Check if all predicate(value) are truthy. Equivalent to Array.prototype.every.

License

MIT

Keywords

cache

FAQs

Package last updated on 22 Aug 2018

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