Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

memoize-fs

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoize-fs

memoize/cache in file system solution for Node.js

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
decreased by-29%
Maintainers
1
Weekly downloads
 
Created
Source

memoize-fs

memoize/cache in file system solution for Node.js

Motivation

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

Features

Installation

In your project path:

$ npm install memoize-fs

Usage

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!

Memoizing promisified functions

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(...

Configuration

####TODO: continue with docs here

FAQs

Package last updated on 17 Jun 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc