@mish-tv/cache
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@mish-tv/cache

npm Build and test coverage license

`@mish-tv/cache` is a simple cache library that holds a single value in a single instance.

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

Readme

Keywords

none

Package Sidebar

Install

npm i @mish-tv/cache

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

42.8 kB

Total Files

22

Last publish

Collaborators

  • malt03