Expose memoized function's results cache #175

Merged
merged 3 commits into from Jan 31, 2013
View
@@ -975,6 +975,9 @@ Caches the results of an async function. When creating a hash to store function
results against, the callback is omitted from the hash and an optional hash
function can be used.
+The cache of results is exposed as the `memo` property of the function returned
+by `memoize`.
+
__Arguments__
* fn - the function you to proxy and cache results from.
View
@@ -679,6 +679,7 @@
}]));
}
};
+ memoized.memo = memo;
memoized.unmemoized = fn;
return memoized;
};
View
@@ -1503,6 +1503,18 @@ exports['memoize custom hash function'] = function (test) {
test.done();
};
+exports['memoize manually added memo value'] = function (test) {
+ test.expect(1);
+ var fn = async.memoize(function(arg, callback) {
+ test(false, "Function should never be called");
+ });
+ fn.memo["foo"] = ["bar"];
+ fn("foo", function(val) {
+ test.equal(val, "bar");
+ test.done();
+ });
+};
+
// Issue 10 on github: https://github.com/caolan/async/issues#issue/10
exports['falsy return values in series'] = function (test) {
function taskFalse(callback) {