abortable-promise-cache
Adds AbortController/AbortSignal semantics to a cache of promises. Each get
from the cache can optionally take an AbortSignal
object that lets that
request be aborted.
Cached fill requests will be aborted and evicted from the cache if all the
incoming requests for it are aborted before the promise settles.
If the fill request has already settled before all the requests for it have been
aborted, it will stay in the cache.
Install
$ npm install --save abortable-promise-cache
Usage
import AbortablePromiseCache from 'abortable-promise-cache'
import QuickLRU from 'quick-lru'
const cache = new AbortablePromiseCache({
cache: new QuickLRU({ maxSize: 1000 }),
async fill(requestData, abortSignal) {
return longRunningThing(requestData, abortSignal)
},
})
const aborter = new AbortController()
const result = await cache.get('some key', { ...anyStuff }, aborter.signal)
cache.delete('some key')
cache.clear()
API
Table of Contents
Academic Use
This package was written with funding from the NHGRI as
part of the JBrowse project. If you use it in an academic
project that you publish, please cite the most recent JBrowse paper, which will
be linked from jbrowse.org.
License
MIT © Robert Buels