Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
memoize-function
Advanced tools
A memoization library that caches all results and supports *N* arguments with any type.
In computing, memoization is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again. — Wikipedia
A memoization library that caches all results and supports N arguments with any type.
npm install memoize-function --save
const memoizeFunction = require("memoize-function");
const factorial = memoizeFunction((value) => {
if (value <= 1) {
return 1;
}
return value * factorial(value - 1);
});
factorial(50);
factorial(20); // Value from cache
It is possible to pass a custom storage to be used.
const memoized = memoizeFunction(fn, {
storage: {
store: {},
clear() {
this.store = {};
},
remove(key) {
delete this.store[key];
},
set(key, value) {
this.store[key] = value;
},
get(key) {
return this.store[key] || null;
},
},
});
class Storage {
store;
constructor() {
this.store = {};
}
clear() {
this.store = {};
}
remove(key) {
delete this.store[key];
}
get(key) {
return this.store[key] || null;
}
set(key, value) {
this.store[key] = value;
}
}
const memoized = memoizeFunction(fn, {
storage: new Storage(),
});
The custom cache can be a class or an object implementing the following methods:
get
set
clear
remove
To use a custom cache key generator:
const generateCacheKey = (...args) =>
"my_custom_key_for_each_function_argument";
const memoized = memoizeFunction(fn, {
generateCacheKey,
});
FAQs
A memoization library that caches all results and supports *N* arguments with any type.
The npm package memoize-function receives a total of 7 weekly downloads. As such, memoize-function popularity was classified as not popular.
We found that memoize-function 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.