Browse Source

Merge branch 'release/2.0.0'

master
Bryan Donovan 9 years ago
parent
commit
8fc6636a76
  1. 1
      .travis.yml
  2. 5
      History.md
  3. 10
      lib/caching.js
  4. 11
      lib/callback_filler.js
  5. 12
      lib/multi_caching.js
  6. 4
      package.json
  7. 16
      test/caching.unit.js
  8. 16
      test/multi_caching.unit.js

1
.travis.yml

@ -1,6 +1,5 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '5.5'
script: 'make test-travis'

5
History.md

@ -1,5 +1,8 @@
- 2.0.0 2015-03-13
- Removing domain integration (#38), no longer actively supporting node 0.10.x.
- 1.5.0 2015-03-13
-npm bumps, making sure global.Promise is not defined in node 0.10 memory store test.
- npm bumps, making sure global.Promise is not defined in node 0.10 memory store test.
- 1.4.1 2016-03-13
- Fixing backward-compatibility Promise issue with node 0.10.x in memory store.

10
lib/caching.js

@ -1,6 +1,5 @@
/** @module cacheManager/caching */
/*jshint maxcomplexity:15*/
var domain = require('domain');
var CallbackFiller = require('./callback_filler');
/**
@ -92,7 +91,7 @@ var caching = function(args) {
}
var hasKey = callbackFiller.has(key);
callbackFiller.add(key, {cb: cb, domain: process.domain});
callbackFiller.add(key, {cb: cb});
if (hasKey) { return; }
self.store.get(key, options, function(err, result) {
@ -101,12 +100,7 @@ var caching = function(args) {
} else if (self._isCacheableValue(result)) {
callbackFiller.fill(key, null, result);
} else {
domain
.create()
.on('error', function(err) {
callbackFiller.fill(key, err);
})
.bind(work)(function(err, data) {
work(function(err, data) {
if (err) {
callbackFiller.fill(key, err);
return;

11
lib/callback_filler.js

@ -1,18 +1,13 @@
var domain = require('domain');
function CallbackFiller() {
this.queues = {};
}
CallbackFiller.prototype.fill = function(key, err, data) {
var self = this;
var waiting = self.queues[key];
delete self.queues[key];
var waiting = this.queues[key];
delete this.queues[key];
waiting.forEach(function(task) {
var taskDomain = task.domain || domain.create();
taskDomain.bind(task.cb)(err, data);
(task.cb)(err, data);
});
};

12
lib/multi_caching.js

@ -1,6 +1,5 @@
/** @module cacheManager/multiCaching */
var async = require('async');
var domain = require('domain');
var CallbackFiller = require('./callback_filler');
/**
@ -218,7 +217,7 @@ var multiCaching = function(caches, options) {
}
var hasKey = callbackFiller.has(key);
callbackFiller.add(key, {cb: cb, domain: process.domain});
callbackFiller.add(key, {cb: cb});
if (hasKey) { return; }
getFromHighestPriorityCache(key, function(err, result, index) {
@ -232,14 +231,7 @@ var multiCaching = function(caches, options) {
callbackFiller.fill(key, err, result);
});
} else {
domain
.create()
.on('error', function(err) {
if (callbackFiller.has(key)) {
callbackFiller.fill(key, err);
}
})
.bind(work)(function(err, data) {
work(function(err, data) {
if (err) {
return callbackFiller.fill(key, err);
}

4
package.json

@ -1,6 +1,6 @@
{
"name": "cache-manager",
"version": "1.5.0",
"version": "2.0.0",
"description": "Cache module for Node.js",
"main": "index.js",
"scripts": {
@ -20,7 +20,7 @@
"author": "Bryan Donovan",
"license": "MIT",
"dependencies": {
"async": "^1.5.2",
"async": "1.5.2",
"lru-cache": "4.0.0"
},
"devDependencies": {

16
test/caching.unit.js

@ -576,12 +576,20 @@ describe("caching", function() {
fakeError = new Error(support.random.string());
});
it("bubbles up that error", function(done) {
it("does not catch the error", function(done) {
var originalExceptionHandler = process.listeners('uncaughtException').pop();
process.removeListener('uncaughtException', originalExceptionHandler);
process.once('uncaughtException', function(err) {
process.on('uncaughtException', originalExceptionHandler);
assert.ok(err);
done();
});
cache.wrap(key, function() {
throw fakeError;
}, function(err) {
assert.equal(err, fakeError);
done();
}, function() {
done(new Error('Should not have caught error'));
});
});
});

16
test/multi_caching.unit.js

@ -926,12 +926,20 @@ describe("multiCaching", function() {
fakeError = new Error(support.random.string());
});
it("bubbles up that error", function(done) {
it("does not catch the error", function(done) {
var originalExceptionHandler = process.listeners('uncaughtException').pop();
process.removeListener('uncaughtException', originalExceptionHandler);
process.once('uncaughtException', function(err) {
process.on('uncaughtException', originalExceptionHandler);
assert.ok(err);
done();
});
multiCache.wrap(key, function() {
throw fakeError;
}, ttl, function(err) {
assert.equal(err, fakeError);
done();
}, function() {
done(new Error('Should not have caught error'));
});
});
});

Loading…
Cancel
Save