memory-cacher

1.1.1 • Public • Published

memory-cacher

get value from cache or from asynchronous getter, it will also call the promise only once in case it will ask for the same key more than once

Usage

@param {string} key @param {asynchronous function} fn @param {int} expiration

const MemoryCacher = require('memory-cacher');

const key = 'key';

let result = await MemoryCacher.getCached(key);

// result === null

result = await MemoryCacher.getCached(key, async () => {
  await delay(100);
  return 10;
}, 200);

// result === 10

result = MemoryCacher.getCached(key);

// result === 10

Package Sidebar

Install

npm i memory-cacher

Weekly Downloads

1,265

Version

1.1.1

License

BSD-2-Clause

Unpacked Size

4.46 kB

Total Files

6

Last publish

Collaborators

  • mad_vinking