Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
cached-callback
Advanced tools
cached-callback caches arguments returned from an earlier execution and passes them to a callback passed in
cached-callback caches arguments returned from an earlier execution and passes them to a callback passed in
var cachedCallback = require('cached-callback')
Debounces an invocation with a specific key as long as it's callback is not yet called
var debounced = cachedCallback(function (id, callback) {
request('http://example.com/'+id, callback)
})
// The request only gets triggered once even when you
// invoke the wrapped method multiple times.
debounced('test.html', function (err, data) { console.log(err, data) })
debounced('test.html', function (err, data) { console.log(err, data) })
// So this shouldn't result in the same output
setTimeout(function () {
debounced('test.html', function (err, data) { console.log(err, data) })
}, 10000)
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 = cachedCallback(function (id, callback) {
request('http://example.com/'+id, callback)
}, true)
cached('test.html', function (err, data) { console.log(err, data) })
// This is definitely the same response
setTimeout(function () {
cached('test.html', function (err, data) { console.log(err, data) })
}, 10000)
The second cache
argument is also exposed with .cache()
var cached = require('cached-callback').cache()
var get = cached(function (id, callback) {
request('http://example.com/'+id, callback)
}
Caches the result with a custom caching method. This example caches the result for 20 seconds.
var cache = {}
var setterAndGetter = {
get: function get (key) {
return cache[key]
},
set: function set (key, value) {
cache[key] = value
setTimeout(function () { delete cache[key] }, 20000)
}
}
var custom = cachedCallback(function (id, callback) {
request('http://example.com/'+id, callback)
}, setterAndGetter)
async.memoize
?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
FAQs
cached-callback caches arguments returned from an earlier execution and passes them to a callback passed in
The npm package cached-callback receives a total of 0 weekly downloads. As such, cached-callback popularity was classified as not popular.
We found that cached-callback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.