npm.io
0.2.0 • Published 6 years ago

@specialblend/lru-cache-pipe

Licence
ISC
Version
0.2.0
Deps
2
Size
5 kB
Vulns
0
Weekly
0

@specialblend/lru-cache-pipe

functional wrapper around lru-cache

installation

npm install @specialblend/lru-cache-pipe

usage

import createCache from '@specialblend/lru-cache-pipe';

async function fetchTodoById (id) {
    // IO intensive operation ...
}

const todoCache = createCache(fetchTodoById)

async function main() {
    await todoCache.resolve('test-todo-id'); // => calls fetchTodoById with test-todo-id and caches the result

    await todoCache.resolve('test-todo-id'); // => returns the cached result

    await todoCache.resolve('fooBarId'); // => calls fetchTodoById with fooBarId and caches the result

    await todoCache.resolve('fooBarId'); // => returns the cached result
}

Keywords