
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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 0 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.