cached-callback
cached-callback caches arguments returned from an earlier execution and passes them to a callback passed in
Examples
var cachedCallback =
Debounce
Debounces an invocation with a specific key as long as it's callback is not yet called
var debounced = // The request only gets triggered once even when you// invoke the wrapped method multiple times. // So this shouldn't result in the same output
Persistent cache
Permanently caches the result of the callback. Multiple invocations result in the same output. (Only use this in a controlled environment. This fills an object with the whole response of the callback. So it might lead to a memory leak.)
var cached = // This is definitely the same response
The second cache
argument is also exposed with .cache()
var cached = var get =
Custom caching method
Caches the result with a custom caching method. This example caches the result for 20 seconds.
var cache = {}var setterAndGetter = { return cachekey } { cachekey = value } var custom =
async.memoize
?
Why don't I use I ended up writing similar code like this module tons of times and didn't find async.memoize
when I needed it.
IMO asyncjs also got too large and could benefit from some modularization.
The advantage of this module is that you can hook up a custom cache method. E.g. a lru cache like https://www.npmjs.com/package/lru-cache