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

cache-manager-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager-js

A caching library for managing asynchronous function results with TTL and eviction strategies.

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

cache-manager-js

npm version License: MIT

A caching library for managing asynchronous function results with TTL and eviction strategies.

Installation

You can install the package using npm:

npm install cache-manager-js

Usage

import { AsyncCacheManager } from "scache-manager-js";

const cache = new AsyncCacheManager();

const callCount: any[] = [];

async function fetchDataFromAPI(id: string): Promise<any> {
  console.log(
    `async function called. ID: ${id} Count: ${callCount.length + 1}`
  );
  const result = Math.random();
  callCount.push(result);
  return result;
}

const cachedFetchData = cache.wrap(fetchDataFromAPI);

// The first call triggers the actual async operation
const data1 = await cachedFetchData("123");

// Subsequent calls return cached results without re-executing the async operation
const data2 = await cachedFetchData("123");

const data3 = await cachedFetchData("666");

if (data1 === data2) {
  console.log("data1 equals data2");
  // data1 equals data2
}

Promising Field

Asynchronous programming is increasingly prevalent in modern JavaScript and TypeScript applications. Creating a sophisticated caching manager for asynchronous operations addresses a common performance optimization challenge. This package could be particularly useful in scenarios where repeated asynchronous calls with similar parameters occur.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 27 Jan 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