async-cache-dedupe
async-cache-dedupe
is a cache for asynchronous fetching of resources
with full deduplication, i.e. the same resource is only asked once at any given time.
Install
npm i async-cache-dedupe
Example
import { Cache } from 'async-cache-dedupe'
const cache = new Cache({
ttl: 5
})
cache.define('fetchSomething', async (k) => {
console.log('query', k)
return { k }
})
const p1 = cache.fetchSomething(42)
const p2 = cache.fetchSomething(24)
const p3 = cache.fetchSomething(42)
const res = await Promise.all([p1, p2, p3])
console.log(res)
Commonjs/require
is also supported.
License
MIT