Skip to content

rakannimer/with-localstorage-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

with-localstorage-cache

Wrap any method, sync or async with a local storage cache.

Usage

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

const myID = await withFsCache(
  // Can be anything
  "my-id",
  async () => {
    await sleep(500);
    functionCallCount += 1;
    return { someData: "1" };
  }
);

// If called again it will return without waiting.