1.0.2 • Published 1 year ago

@mish-tv/cache v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Installation

npm install --save @mish-tv/cache

Simple Usage

import { Cache } from "@mish-tv/cache";

// By default, it caches for 1hour + rand()*6min.
const entityCache = new Cache<Entity>();

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

// 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");
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago