Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

ari-party/simplecache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@robertsspaceindustries/simplecache

Simple caching of values

Usage

// Try this out using `npm run test`

import Cache from "@robertsspaceindustries/simplecache";

const cache = new Cache(10_000, function (number) {
  return 2 + number;
});

await cache.getValue(1); // Expected value: 3

setTimeout(async function () {
  await cache.getValue(2); // Expected value: 3, cache hasn't expired yet

  setTimeout(async function () {
    await cache.getValue(2); // Expected value: 4
  }, 2_500);
}, 7_500);