mono-cache
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

mono-cache

install to npm dependencies :

npm i -D mono-cache

usage:

import cache from 'mono-cache';

interface CacheState {
  name: string;
  age: number;

  next: {
    weight: number;
    height: number;
  };
}

const c = cache<CacheState>();
c.set('name', 'mono-cache');
c.set('age', 18);
c.set('next.weight', 60);
c.set('next.height', 180);

const name = c.get('name');
const age = c.get('age');
const next = c.get('next');
console.log(name, age, next);

// ttl

c.set('name', 'mono-cache', 1000); // 1000 = 1s

// how to get result type on get method ?

import { CachePaths } from './type';

const nextPaths: CachePaths<CacheState> = 'next';
const typedNext = c.get<typeof nextPaths>(nextPaths);
console.log(typedNext.weight, typedNext.height);

/mono-cache/

    Package Sidebar

    Install

    npm i mono-cache

    Weekly Downloads

    6

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    92.3 kB

    Total Files

    15

    Last publish

    Collaborators

    • sia-fl