
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-fs
Advanced tools
This project is inspired by the memoize project by Mariusz Nowak aka medikoo. The motivation behind this module is that sometimes you have to persist cached function calls but you do not want to deal with an extra process (ie. managing a Redis store). Memoization is best technique to save on memory or CPU cycles when we deal with repeated operations. For detailed insight see: http://en.wikipedia.org/wiki/Memoization
In your project path:
$ npm install memoize-fs
var memoize = require('memoize-fs')({ cachePath: require('path').join(__dirname, '../../build/cache' }),
fun = function (a, b) { return a + b; };
memoize.fn(fun).then(function (memFn) {
memFn(1, 2).then(function (result) {
assert.strictEqual(result, 3);
memFn(1, 2).then(function (result) { // cache hit
assert.strictEqual(result, 3);
}, function (err) { /* handle error */ });
}, function (err) { /* handle error */ });
}, function (err) { /* handle error */ });
Note that a result of a momoised function is always a Promise instance!
In order to memoize an async function it must be first promisified in the following manner:
Before:
var funAsync = function (a, b, cb) { setTimeout(function () { cb(null, a + b); }, 100); };
// later
funAsync(1, 2, function (err, result) {
if (err) throw err;
console.log(result);
});
After:
var funPromisified = function (a, b) {
return new require('es6-promise').Promise(function (resolve, reject) {
setTimeout(function () { resolve(a + b); }, 100);
});
};
// later
funPromisified(1, 2).then(function (result) {
console.log(result);
}, function (err) {
throw err;
});
// now we can memoize it
memoize.fn(funPromisified).then(...
####TODO: continue with docs here
FAQs
Node.js solution for memoizing/caching function results on the file system
The npm package memoize-fs receives a total of 7,656 weekly downloads. As such, memoize-fs popularity was classified as popular.
We found that memoize-fs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.