0.1.1 • Published 8 years ago

memoize-clear v0.1.1

Weekly downloads
19
License
ISC
Repository
github
Last release
8 years ago

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