Skip to content

logzio/memory-cacher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = 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