A simple cache library with support for exclusion control.
npm install @mish-tv/cache@mish-tv/cache is a simple cache library that holds a single value in a single instance.
npm install --save @mish-tv/cache
`Simple Usage
`typescript
import { Cache } from "@mish-tv/cache";// By default, it caches for 1hour + rand()*6min.
const entityCache = new Cache();
// Only at the beginning and when it expires,
// it calls an anonymous function passed as an argument and
// caches the returned value.
const getEntity = () =>
entityCache.get(async () => {
const entity: Entity = await fetch();
return entity;
});
(async () => {
const entity = await getEntity();
})();
`Other Usage
`typescript
// You can configure ttl, jitter and initial value.
const entityCache = new Cache(60000, 1000, entity);// You can create a cache that will never expire.
const entityCache = new Cache("infinity");
``