Skip to content

Commit 1e8f678

Browse files
committed
hiding queues inside CallbackFiller
1 parent 3b127c2 commit 1e8f678

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

lib/caching.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ var caching = function(args) {
4444
options = undefined;
4545
}
4646

47-
if (callbackFiller.queues[key]) {
48-
callbackFiller.queues[key].push({cb: cb, domain: process.domain});
49-
return;
50-
}
51-
52-
callbackFiller.queues[key] = [{cb: cb, domain: process.domain}];
47+
var hasKey = callbackFiller.has(key);
48+
callbackFiller.add(key, {cb: cb, domain: process.domain});
49+
if (hasKey) { return; }
5350

5451
self.store.get(key, options, function(err, result) {
5552
if (err && (!self.ignoreCacheErrors)) {

lib/callback_filler.js

+12
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ CallbackFiller.prototype.fill = function(key, err, data) {
1616
});
1717
};
1818

19+
CallbackFiller.prototype.has = function(key) {
20+
return this.queues[key];
21+
};
22+
23+
CallbackFiller.prototype.add = function(key, funcObj) {
24+
if (this.queues[key]) {
25+
this.queues[key].push(funcObj);
26+
} else {
27+
this.queues[key] = [funcObj];
28+
}
29+
};
30+
1931
module.exports = CallbackFiller;

lib/multi_caching.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ var multiCaching = function(caches) {
9696
options = undefined;
9797
}
9898

99-
if (callbackFiller.queues[key]) {
100-
callbackFiller.queues[key].push({cb: cb, domain: process.domain});
101-
return;
102-
}
103-
104-
callbackFiller.queues[key] = [{cb: cb, domain: process.domain}];
99+
var hasKey = callbackFiller.has(key);
100+
callbackFiller.add(key, {cb: cb, domain: process.domain});
101+
if (hasKey) { return; }
105102

106103
getFromHighestPriorityCache(key, function(err, result, index) {
107104
if (err) {

0 commit comments

Comments
 (0)