Skip to content

Commit 8ee4c79

Browse files
committed
Hint fixes. Removing relaxing options.
1 parent 1c341dd commit 8ee4c79

File tree

2 files changed

+37
-52
lines changed

2 files changed

+37
-52
lines changed

lib/multi_caching.js

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*jshint -W072 */
2-
31
var async = require('async');
42
var domain = require('domain');
53

64
/**
75
* Module that lets you specify a hierarchy of caches.
86
*/
9-
var multi_caching = function (caches) {
7+
var multi_caching = function(caches) {
108
var self = {};
119
if (!Array.isArray(caches)) {
1210
throw new Error('multi_caching requires an array of caches');
@@ -21,40 +19,29 @@ var multi_caching = function (caches) {
2119
}
2220

2321
var i = 0;
24-
async.forEachSeries(caches, function (cache, async_cb) {
25-
if(typeof options === 'object'){
26-
cache.store.get(key, options, function (err, result) {
27-
if (err) {
28-
return cb(err);
29-
}
30-
if (result) {
31-
// break out of async loop.
32-
return cb(err, result, i);
33-
}
34-
35-
i += 1;
36-
async_cb(err);
37-
});
38-
}else{
39-
cache.store.get(key, function (err, result) {
40-
if (err) {
41-
return cb(err);
42-
}
43-
if (result) {
44-
// break out of async loop.
45-
return cb(err, result, i);
46-
}
22+
async.forEachSeries(caches, function(cache, async_cb) {
23+
var callback = function(err, result) {
24+
if (err) {
25+
return cb(err);
26+
}
27+
if (result) {
28+
// break out of async loop.
29+
return cb(err, result, i);
30+
}
4731

48-
i += 1;
49-
async_cb(err);
50-
});
32+
i += 1;
33+
async_cb(err);
34+
};
35+
if (typeof options === 'object') {
36+
cache.store.get(key, options, callback);
37+
}else {
38+
cache.store.get(key, callback);
5139
}
52-
5340
}, cb);
5441
}
5542

5643
function set_in_multiple_caches(caches, opts, cb) {
57-
async.forEach(caches, function (cache, async_cb) {
44+
async.forEach(caches, function(cache, async_cb) {
5845
if (typeof opts.options !== 'object') {
5946
cache.store.set(opts.key, opts.value, opts.ttl, async_cb);
6047
} else {
@@ -68,8 +55,8 @@ var multi_caching = function (caches) {
6855
*
6956
* When a key is found in a lower cache, all higher levels are updated
7057
*/
71-
self.get_and_pass_up = function (key, cb) {
72-
get_from_highest_priority_cache(key, function (err, result, index) {
58+
self.get_and_pass_up = function(key, cb) {
59+
get_from_highest_priority_cache(key, function(err, result, index) {
7360
if (err) {
7461
return cb(err);
7562
}
@@ -78,7 +65,7 @@ var multi_caching = function (caches) {
7865

7966
if (result !== undefined && index) {
8067
var cachesToUpdate = caches.slice(0, index);
81-
async.forEach(cachesToUpdate, function (cache, async_cb) {
68+
async.forEach(cachesToUpdate, function(cache, async_cb) {
8269
cache.set(key, result, result.ttl, async_cb);
8370
});
8471
}
@@ -95,7 +82,7 @@ var multi_caching = function (caches) {
9582
* If a key doesn't exist in a higher-priority cache but exists in a lower-priority
9683
* cache, it gets set in all higher-priority caches.
9784
*/
98-
self.wrap = function (key, work, options, cb) {
85+
self.wrap = function(key, work, options, cb) {
9986
if (typeof options === 'function') {
10087
cb = options;
10188
options = undefined;
@@ -109,14 +96,14 @@ var multi_caching = function (caches) {
10996
self.queues[key] = [{cb: cb, domain: process.domain}];
11097

11198
function fillCallbacks(err, data) {
112-
self.queues[key].forEach(function (task) {
99+
self.queues[key].forEach(function(task) {
113100
var taskDomain = task.domain || domain.create();
114101
taskDomain.bind(task.cb)(err, data);
115102
});
116103
delete self.queues[key];
117104
}
118105

119-
get_from_highest_priority_cache(key, function (err, result, index) {
106+
get_from_highest_priority_cache(key, function(err, result, index) {
120107
if (err) {
121108
return fillCallbacks(err);
122109
} else if (result) {
@@ -131,16 +118,16 @@ var multi_caching = function (caches) {
131118
opts.ttl = options;
132119
}
133120

134-
set_in_multiple_caches(caches_to_update, opts, function (err) {
121+
set_in_multiple_caches(caches_to_update, opts, function(err) {
135122
fillCallbacks(err, result);
136123
});
137124
} else {
138125
domain
139126
.create()
140-
.on('error', function (err) {
127+
.on('error', function(err) {
141128
fillCallbacks(err);
142129
})
143-
.bind(work)(function (err, data) {
130+
.bind(work)(function(err, data) {
144131
if (err) {
145132
fillCallbacks(err);
146133
return;
@@ -154,7 +141,7 @@ var multi_caching = function (caches) {
154141
if (typeof options !== 'object') {
155142
opts.ttl = options;
156143
}
157-
set_in_multiple_caches(caches, opts, function (err) {
144+
set_in_multiple_caches(caches, opts, function(err) {
158145
if (err) {
159146
fillCallbacks(err);
160147
} else {
@@ -166,7 +153,7 @@ var multi_caching = function (caches) {
166153
});
167154
};
168155

169-
self.set = function (key, value, options, cb) {
156+
self.set = function(key, value, options, cb) {
170157
var opts = {
171158
key: key,
172159
value: value,
@@ -178,24 +165,24 @@ var multi_caching = function (caches) {
178165
set_in_multiple_caches(caches, opts, cb);
179166
};
180167

181-
self.get = function (key, options, cb) {
168+
self.get = function(key, options, cb) {
182169
if (typeof options === 'function') {
183170
cb = options;
184171
options = false;
185172
}
186173
get_from_highest_priority_cache(key, options, cb);
187174
};
188175

189-
self.del = function (key, options, cb) {
176+
self.del = function(key, options, cb) {
190177
if (typeof options === 'function') {
191178
cb = options;
192179
options = false;
193180
}
194-
async.forEach(caches, function (cache, async_cb) {
195-
if(typeof options ==='object'){
196-
cache.store.del(key, options, async_cb );
197-
}else{
198-
cache.store.del(key, async_cb );
181+
async.forEach(caches, function(cache, async_cb) {
182+
if (typeof options === 'object') {
183+
cache.store.del(key, options, async_cb);
184+
}else {
185+
cache.store.del(key, async_cb);
199186
}
200187
}, cb);
201188
};

test/stores/options.unit.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*jshint -W072 */
2-
31
var caching = require("../../index");
42
var assert = require("assert");
53
var support = require('../support');
@@ -77,7 +75,7 @@ describe("Methods with options", function() {
7775
done();
7876
}
7977
};
80-
testCache.get(key , options, function(err, response) {
78+
testCache.get(key, options, function(err, response) {
8179
assert.equal(response, "GetFunctionOption");
8280
});
8381
});

0 commit comments

Comments
 (0)