Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-zap

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-zap

A cache that stores key-value pairs with a time limit for each entry.

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
69
increased by6800%
Maintainers
0
Weekly downloads
 
Created
Source

cache-zap · license

A cache that stores key-value pairs with a time limit for each entry.

Installation

npm install cache-zap

Usage

import CacheZap from 'cache-zap';

const cache = new CacheZap();
cache.set('foo', 'bar', 1000); // key, value, time in milliseconds
cache.get('foo'); // 'bar'
cache.size(); // 1

setTimeout(() => {
  cache.get('foo'); // undefined
  cache.size(); // 0
}, 1000);

API

set(key: K, value: V, duration: number): void

Set a key-value pair with a time limit for the entry.

  • key: The key of the entry.
  • value: The value of the entry.
  • duration: The duration in milliseconds for which the entry should be valid.

get(key: K): V | undefined

Get the value of an entry.

  • key: The key of the entry.

has(key: K): boolean

Check if an entry exists and is not expired.

  • key: The key of the entry.

delete(key: K): boolean

Delete an entry.

  • key: The key of the entry.

clear(): void

Clear all entries.

size(): number

Returns the number of valid (non-expired) entries in the cache.

License

MIT

Keywords

FAQs

Package last updated on 22 Dec 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc