Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
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 2,284 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.