diff --git a/lib/caching.js b/lib/caching.js index 1b0e98b..a0665f2 100644 --- a/lib/caching.js +++ b/lib/caching.js @@ -37,9 +37,9 @@ var caching = function (args) { self.wrap = function (key, work, cb) { self.store.get(key, function (err, result) { if (err && (!self.ignoreCacheErrors)) { - cb(err, result); + cb(err); } else if (result) { - cb(null, result); + cb.apply(null, result); } else if (self.queues[key]) { self.queues[key].push(cb); } else { @@ -50,15 +50,13 @@ var caching = function (args) { if (work_args[0]) { // assume first arg is an error return cb(work_args[0]); } - self.store.set(key, work_args[1], function (err) { + self.store.set(key, work_args, function (err) { if (err && (!self.ignoreCacheErrors)) { return cb(err); } self.queues[key].forEach(function (done) { - console.log(done.toString()); - console.log(work_args[1]); - done.apply(null, [work_args[1]]); + done.apply(null, work_args); }); delete self.queues[key]; diff --git a/test/caching.unit.js b/test/caching.unit.js index 8da9761..756fb55 100644 --- a/test/caching.unit.js +++ b/test/caching.unit.js @@ -262,7 +262,7 @@ describe("caching", function () { memory_store_stub.get.restore(); }); - it("retrieves data from memory when available", function (done) { + it("retrieves data from cache", function (done) { var func_called = false; cache.wrap(key, function (cb) { @@ -421,24 +421,26 @@ describe("caching", function () { construct = sinon.spy(function (val, cb) { var timeout = support.random.number(100); setTimeout(function () { - console.log("val: " + val); cb(null, 'value'); }, timeout); }); }); - it.only("calls the wrapped function once", function (done) { + it("calls the wrapped function once", function (done) { var values = []; - for (var i = 0; i < 20; i++) { + for (var i = 0; i < 2; i++) { values.push(i); } async.each(values, function (val, async_cb) { cache.wrap('key', function (cb) { construct(val, cb); - }, async_cb); - }, function (err, result) { - assert.equal(result, 'value'); + }, function (err, result) { + assert.equal(result, 'value'); + async_cb(err); + }); + }, function (err) { + check_err(err); assert.equal(construct.callCount, 1); done(); });