Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
A few function memoization helpers to work with catbox.
litterBox.memoizeFnPromise(options)
options
: object
. Required. An object with the following keys:
client
: Catbox Client Instance
. Required. A catbox client instance.fn
: Function
. Required. A function which returns a Promise.ttl
: Integer
. Required. The time-to-live for the cached fn
result.keyProvider
: (fn-input) => {id, segment}
. Required. A function which returns a cache-key for Catbox. This
function is called with the same arguments as fn
, allowing you to create a dynamic cache-key, for example: const exampleKeyProvider = (input) => ({ segment: 'test', id: `test-${input}` })
This code is also available here.
const litterBox = require('litter-box')
const examplePromiseFunction = (input) => Promise.resolve(input)
const cachedPromiseFunction = litterBox.memoizeFnPromise({
client: catboxClientInstance,
fn: examplePromiseFunction,
keyProvider: (input) => ({ segment: 'test', id: `test-${input}` }),
ttl: 5 * 60 * 1000 // 5 minutes
})
cachedPromiseFunction(1234)
.then(console.log) // prints 1234
// later on...
cachedPromiseFunction(1234) // function not executed, value is pulled from the cache
.then((result) => { // returns 1234
console.log(result)
process.exit(0)
})
litterBox.memoizeFnCallback(options)
options
: object
. Required. An object with the following keys:
client
: Catbox Client Instance
. Required. A catbox client instance.fn
: Function
. Required. A function which has a callback as it's final argument.ttl
: Integer
. Required. The time-to-live for the cached fn
result.keyProvider
: (fn-input) => {id, segment}
. Required. A function which returns a cache-key for Catbox. This
function is called with the same arguments as fn
, allowing you to create a dynamic cache-key, for example: const exampleKeyProvider = (input) => ({ segment: 'test', id: `test-${input}` })
This code is also available here.
const litterBox = require('litter-box')
const exampleCallbackFunction = (input, cb) => cb(null, input)
const cachedCallbackFunction = litterBox.memoizeFnPromise({
client: catboxClientInstance,
fn: exampleCallbackFunction,
keyProvider: (input) => ({ segment: 'test', id: `test-${input}` }),
ttl: 5 * 60 * 1000 // 5 minutes
})
cachedCallbackFunction(1234, (err, result) => console.log(result)) // prints 1234
// later on...
// function not executed, value is pulled from the cache
cachedCallbackFunction(1234, (err, result) => console.log(result)) // prints 1234
l
FAQs
A modified catbox
The npm package litter-box receives a total of 5 weekly downloads. As such, litter-box popularity was classified as not popular.
We found that litter-box 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.