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

1.3.8 • Public • Published

@numbereight/cache

A simple in memory cache

Usage

import { withLittleCache, littleCache, TTL_5_minutes } from '@numbereight/cache';

function myExpensiveFunction(a: string, b: string): string {
    fictional_sleepSync(30);
    return a.slice(1) + b.slice(-1);
}

// The included "littleCache", that uses a Map<> to cache data in memory
withLittleCache(
    'myCacheName', // The name of your cache; different caches use this in different ways
    myExpensiveFunction, // The function to be cached
    (a, b) => a+b, // How to generate the cache key
    TTL_5_minutes // Cache TTL
};

// Use an external cache that supports the Cache<T> interface like this:
withCache(
    littleCache('myCacheName'), // get your cache
    myExpensiveFunction,
    (a, b) => a+b,
    TTL_5_minutes
);

Readme

Keywords

Package Sidebar

Install

npm i @numbereight/cache

Weekly Downloads

18

Version

1.3.8

License

MIT

Unpacked Size

28.9 kB

Total Files

21

Last publish

Collaborators

  • nechris