New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@avanio/expire-cache

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avanio/expire-cache

Typescript/Javascript cache with expiration

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

@avanio/expire-cache

TypeScript npm version Maintainability Test Coverage github action

Typescript/Javascript Cache interfaces and expiration cache class.

This package contains:

  • ICache common cache interface
  • IAsyncCache common async cache interface
  • TAnyCache type for both common cache interfaces
  • ExpireCache class which implements ICache interface with value expiration

examples

Synchronous example

import {ICache, ExpireCache} from '@avanio/expire-cache';

const cache = new ExpireCache<string>();

cache.add('key', 'value', new Date(Date.now() + 1000)); // expires 1000ms
cache.add('key2', 'value2'); // never expires (if no default expiration is set)

cache.get('key'); // 'value'

cache.delete('key');

cache.clear();

function useCache(cache: ICache<string>) {
	const value = cache.get('key'); // 'value'
}

Synchronous/Asynchronous example (works with both ICache and IAsyncCache interfaces)

import {TAnyCache} from '@avanio/expire-cache';

function useCache(cache: TAnyCache<string>) {
	const value = await cache.get('key'); // 'value'
}

Advanced logging example, see default log levels

const cache = new ExpireCache<string>(console, {
	get: LogLevel.Info,
	set: LogLevel.Info,
});

(optional) default expiration in milliseconds if not specified in add() method. (if both are undefined, cache entry never expires)

const cache = new ExpireCache<string>(console, undefined, 60 * 1000); // sets default 60 seconds expiration for add() method

Keywords

FAQs

Package last updated on 08 May 2023

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