21.5.5-f6599b3 • Published 3 years ago

@koeroesi86/cache v21.5.5-f6599b3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@koeroesi86/cache Build Status npm version

Install

yarn add @koeroesi86/cache

or

npm install --save @koeroesi86/cache

Usage example

const { InmemoryCache } = require('@koeroesi86/cache')

const initialState = {};
const expiredCallback = console.log;
const cache = new InmemoryCache(initialState, expiredCallback);

// key, value, expiry
cache.set("example", { data: "thing" }, 5000);

console.log("cached:", cache.get("example"));
declare class InmemoryCache<T = any> {
  has: (key: string) => boolean;
  get: (key: string) => T;
  set: (key: string, data: T, interval?: number) => void;
  all: () => { [key: string]: T };
  flush: () => void;
}

See full example in example/index.js