🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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
Package was removed
Sorry, it seems this package was removed from the registry

cache-manager-js

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

1.0.0
unpublished
latest
Source
npm
Version published
Maintainers
1
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

cache

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