0.1.2 • Published 6 years ago

function-memoization v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

function-memoization

Make function memoization via data cache, to skip some async process (for the same data) and call the callback function directly.

Installation

npm install --save function-memoization

Usage

const { cacheFunction, cacheMethod } = require('function-memoization');

let func = function (p1 = '', p2 = {}, callback) { /**/ };
func = cacheFunction(func);
func(/* args */);

let obj = {
    method: function (p1 = 0, p2 = {}, p3 = [], callback) { /**/ }
};
cacheMethod(obj, 'method');
obj.method(/* args */);

Options

async

Boolean value, whether to execute the callback function asynchronously, false by default.

func = cacheFunction(func, { async: true });
func(/* args */);

cacheMethod(obj, 'method', { async: true });
obj.method(/* args */);

License

MIT