pajtai / memoize-clear

Memoization with the ability to clear the cache wholesale or function by function.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

memoize clear Build Status

memoize-clear is a standard memoization utility with the exception that the cache can be cleared for one function or all memoized functions:

npm install --save memoize-clear

memoization functionality from https://github.com/addyosmani/memoize.js

api

To memoize a function, require('memoize-clear'), and used the returned function to curry:

var memoize = require('memoize-clear'),
    memoized = memoize(function() { ... });

To clear the cache of one function, call .__clear() on that memoized function. You can also clear the cache of on function by passing it into memoize.clearCache(the function whose cache you want to clear). To clear the cache for all functions call .clearCache() on memoize itself.

var memoize = require('memoize'),
    storehouse = 1,
    memoized1 = memoize(function() { return storehouse; }),
    memoized2 = memoize(function() { return 2 * storehouse; });

memoized1(); // 1
memoized2(); // 2

storehouse = 3;

memoized1();    // 1

memoized1.__clear();

memoized1()     // 3
memoized2()     // 2

memoize.clearCache();

storehouse = 4;

memoized1()     // 4
memoized2()     // 8

About

Memoization with the ability to clear the cache wholesale or function by function.


Languages

Language:JavaScript 100.0%