Skip to content

Commit 3b127c2

Browse files
committed
reluctantly converting to camelcase
1 parent 6fc0078 commit 3b127c2

15 files changed

+509
-498
lines changed

.jscs.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
1313
"disallowSpaceAfterBinaryOperators": ["!"],
1414
"disallowSpaceBeforeBinaryOperators": [","],
15+
"requireCamelCaseOrUpperCaseIdentifiers": true,
1516

1617
"disallowMultipleVarDecl": true,
1718
"disallowEmptyBlocks": true,

README.md

+38-38
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ First, it includes a `wrap` function that lets you wrap any function in cache.
3535
This is probably the feature you're looking for. As an example, where you might have to do this:
3636

3737
```javascript
38-
function get_cached_user(id, cb) {
39-
memory_cache.get(id, function (err, result) {
38+
function getCachedUser(id, cb) {
39+
memoryCache.get(id, function (err, result) {
4040
if (err) { return cb(err); }
4141

4242
if (result) {
4343
return cb(null, result);
4444
}
4545

46-
get_user(id, function (err, result) {
46+
getUser(id, function (err, result) {
4747
if (err) { return cb(err); }
48-
memory_cache.set(id, result);
48+
memoryCache.set(id, result);
4949
cb(null, result);
5050
});
5151
});
@@ -54,9 +54,9 @@ function get_cached_user(id, cb) {
5454
... you can instead use the `wrap` function:
5555

5656
```javascript
57-
function get_cached_user(id, cb) {
58-
memory_cache.wrap(id, function (cache_callback) {
59-
get_user(id, cache_callback);
57+
function getCachedUser(id, cb) {
58+
memoryCache.wrap(id, function (cacheCallback) {
59+
getUser(id, cacheCallback);
6060
}, ttl, cb);
6161
}
6262
```
@@ -86,40 +86,40 @@ Redis cache store with connection pooling.
8686
### Single Store
8787

8888
```javascript
89-
var cache_manager = require('cache-manager');
90-
var memory_cache = cache_manager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});
89+
var cacheManager = require('cache-manager');
90+
var memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10/*seconds*/});
9191
var ttl = 5;
9292
// Note: callback is optional in set() and del().
9393

94-
memory_cache.set('foo', 'bar', ttl, function(err) {
94+
memoryCache.set('foo', 'bar', ttl, function(err) {
9595
if (err) { throw err; }
9696

97-
memory_cache.get('foo', function(err, result) {
97+
memoryCache.get('foo', function(err, result) {
9898
console.log(result);
9999
// >> 'bar'
100-
memory_cache.del('foo', function(err) {});
100+
memoryCache.del('foo', function(err) {});
101101
});
102102
});
103103

104-
function get_user(id, cb) {
104+
function getUser(id, cb) {
105105
setTimeout(function () {
106106
console.log("Returning user from slow database.");
107107
cb(null, {id: id, name: 'Bob'});
108108
}, 100);
109109
}
110110

111-
var user_id = 123;
112-
var key = 'user_' + user_id;
111+
var userId = 123;
112+
var key = 'user_' + userId;
113113

114114
// Note: ttl is optional in wrap()
115-
memory_cache.wrap(key, function (cb) {
116-
get_user(user_id, cb);
115+
memoryCache.wrap(key, function (cb) {
116+
getUser(userId, cb);
117117
}, ttl, function (err, user) {
118118
console.log(user);
119119

120-
// Second time fetches user from memory_cache
121-
memory_cache.wrap(key, function (cb) {
122-
get_user(user_id, cb);
120+
// Second time fetches user from memoryCache
121+
memoryCache.wrap(key, function (cb) {
122+
getUser(userId, cb);
123123
}, function (err, user) {
124124
console.log(user);
125125
});
@@ -143,10 +143,10 @@ function respond(res, err, data) {
143143
}
144144

145145
app.get('/foo/bar', function(req, res) {
146-
var cache_key = 'foo-bar:' + JSON.stringify(req.query);
146+
var cacheKey = 'foo-bar:' + JSON.stringify(req.query);
147147
var ttl = 10;
148-
memory_cache.wrap(cache_key, function(cache_cb) {
149-
DB.find(req.query, cache_cb);
148+
memoryCache.wrap(cacheKey, function(cacheCallback) {
149+
DB.find(req.query, cacheCallback);
150150
}, ttl, function(err, result) {
151151
respond(res, err, result);
152152
});
@@ -162,45 +162,45 @@ in an instance of it, or pass in the path to the module.
162162
E.g.,
163163

164164
```javascript
165-
var my_store = require('your-homemade-store');
166-
var cache = cache_manager.caching({store: my_store});
165+
var myStore = require('your-homemade-store');
166+
var cache = cacheManager.caching({store: myStore});
167167
// or
168-
var cache = cache_manager.caching({store: '/path/to/your/store'});
168+
var cache = cacheManager.caching({store: '/path/to/your/store'});
169169
```
170170

171171
### Multi-Store
172172

173173
```javascript
174-
var multi_cache = cache_manager.multi_caching([memory_cache, some_other_cache]);
175-
user_id2 = 456;
176-
key2 = 'user_' + user_id;
174+
var multiCache = cacheManager.multiCaching([memoryCache, someOtherCache]);
175+
userId2 = 456;
176+
key2 = 'user_' + userId;
177177
ttl = 5;
178178

179179
// Sets in all caches.
180-
multi_cache.set('foo2', 'bar2', ttl, function(err) {
180+
multiCache.set('foo2', 'bar2', ttl, function(err) {
181181
if (err) { throw err; }
182182

183183
// Fetches from highest priority cache that has the key.
184-
multi_cache.get('foo2', function(err, result) {
184+
multiCache.get('foo2', function(err, result) {
185185
console.log(result);
186186
// >> 'bar2'
187187

188188
// Delete from all caches
189-
multi_cache.del('foo2');
189+
multiCache.del('foo2');
190190
});
191191
});
192192

193193
// Note: ttl is optional in wrap()
194-
multi_cache.wrap(key2, function (cb) {
195-
get_user(user_id2, cb);
194+
multiCache.wrap(key2, function (cb) {
195+
getUser(userId2, cb);
196196
}, ttl, function (err, user) {
197197
console.log(user);
198198

199-
// Second time fetches user from memory_cache, since it's highest priority.
199+
// Second time fetches user from memoryCache, since it's highest priority.
200200
// If the data expires in the memory cache, the next fetch would pull it from
201-
// the 'some_other_cache', and set the data in memory again.
202-
multi_cache.wrap(key2, function (cb) {
203-
get_user(user_id2, cb);
201+
// the 'someOtherCache', and set the data in memory again.
202+
multiCache.wrap(key2, function (cb) {
203+
getUser(userId2, cb);
204204
}, function (err, user) {
205205
console.log(user);
206206
});

examples/example.js

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
11
/*jshint unused:false*/
22
// Note: ttls are in seconds
3-
var cache_manager = require('../');
4-
var memory_cache = cache_manager.caching({store: 'memory', max: 100, ttl: 10});
5-
var memory_cache2 = cache_manager.caching({store: 'memory', max: 100, ttl: 100});
3+
var cacheManager = require('../');
4+
var memoryCache = cacheManager.caching({store: 'memory', max: 100, ttl: 10});
5+
var memoryCache2 = cacheManager.caching({store: 'memory', max: 100, ttl: 100});
66
var ttl; //Can't use a different ttl per set() call with memory cache
77

88
//
99
// Basic usage
1010
//
11-
memory_cache.set('foo', 'bar', ttl, function(err) {
11+
memoryCache.set('foo', 'bar', ttl, function(err) {
1212
if (err) { throw err; }
1313

14-
memory_cache.get('foo', function(err, result) {
14+
memoryCache.get('foo', function(err, result) {
1515
console.log(result);
1616
// >> 'bar'
17-
memory_cache.del('foo', function(err) {
17+
memoryCache.del('foo', function(err) {
1818
if (err) {
1919
console.log(err);
2020
}
2121
});
2222
});
2323
});
2424

25-
function get_user(id, cb) {
25+
function getUser(id, cb) {
2626
setTimeout(function() {
2727
console.log("Fetching user from slow database.");
2828
cb(null, {id: id, name: 'Bob'});
2929
}, 100);
3030
}
3131

32-
var user_id = 123;
33-
var key = 'user_' + user_id;
32+
var userId = 123;
33+
var key = 'user_' + userId;
3434

3535
//
3636
// wrap() example
3737
//
3838

3939
// Instead of manually managing the cache like this:
40-
function get_cached_user_manually(id, cb) {
41-
memory_cache.get(id, function(err, result) {
40+
function getCachedUserManually(id, cb) {
41+
memoryCache.get(id, function(err, result) {
4242
if (err) { return cb(err); }
4343

4444
if (result) {
4545
return cb(null, result);
4646
}
4747

48-
get_user(id, function(err, result) {
48+
getUser(id, function(err, result) {
4949
if (err) { return cb(err); }
50-
memory_cache.set(id, result);
50+
memoryCache.set(id, result);
5151
cb(null, result);
5252
});
5353
});
5454
}
5555

5656
// ... you can instead use the `wrap` function:
57-
function get_cached_user(id, cb) {
58-
memory_cache.wrap(id, function(cache_callback) {
59-
get_user(id, cache_callback);
57+
function getCachedUser(id, cb) {
58+
memoryCache.wrap(id, function(cacheCallback) {
59+
getUser(id, cacheCallback);
6060
}, cb);
6161
}
6262

63-
get_cached_user(user_id, function(err, user) {
63+
getCachedUser(userId, function(err, user) {
6464
// First time fetches the user from the (fake) database:
6565
console.log(user);
6666

67-
get_cached_user(user_id, function(err, user) {
67+
getCachedUser(userId, function(err, user) {
6868
// Second time fetches from cache.
6969
console.log(user);
7070
});
@@ -76,14 +76,14 @@ get_cached_user(user_id, function(err, user) {
7676
// { id: 123, name: 'Bob' }
7777

7878
// Same as above, but written differently:
79-
memory_cache.wrap(key, function(cb) {
80-
get_user(user_id, cb);
79+
memoryCache.wrap(key, function(cb) {
80+
getUser(userId, cb);
8181
}, function(err, user) {
8282
console.log(user);
8383

84-
// Second time fetches user from memory_cache
85-
memory_cache.wrap(key, function(cb) {
86-
get_user(user_id, cb);
84+
// Second time fetches user from memoryCache
85+
memoryCache.wrap(key, function(cb) {
86+
getUser(userId, cb);
8787
}, function(err, user) {
8888
console.log(user);
8989
});
@@ -92,36 +92,36 @@ memory_cache.wrap(key, function(cb) {
9292
//
9393
// multi-cache example
9494
//
95-
var multi_cache = cache_manager.multi_caching([memory_cache, memory_cache2]);
96-
var user_id2 = 456;
97-
var key2 = 'user_' + user_id;
95+
var multiCache = cacheManager.multiCaching([memoryCache, memoryCache2]);
96+
var userId2 = 456;
97+
var key2 = 'user_' + userId;
9898
var ttl2; //Can't use a different ttl per set() call with memory cache
9999

100-
multi_cache.wrap(key2, function(cb) {
101-
get_user(user_id2, cb);
100+
multiCache.wrap(key2, function(cb) {
101+
getUser(userId2, cb);
102102
}, function(err, user) {
103103
console.log(user);
104104

105-
// Second time fetches user from memory_cache, since it's highest priority.
105+
// Second time fetches user from memoryCache, since it's highest priority.
106106
// If the data expires in the memory cache, the next fetch would pull it from
107107
// the Redis cache, and set the data in memory again.
108-
multi_cache.wrap(key2, function(cb) {
109-
get_user(user_id2, cb);
108+
multiCache.wrap(key2, function(cb) {
109+
getUser(userId2, cb);
110110
}, function(err, user) {
111111
console.log(user);
112112
});
113113

114114
// Sets in all caches.
115-
multi_cache.set('foo2', 'bar2', ttl2, function(err) {
115+
multiCache.set('foo2', 'bar2', ttl2, function(err) {
116116
if (err) { throw err; }
117117

118118
// Fetches from highest priority cache that has the key.
119-
multi_cache.get('foo2', function(err, result) {
119+
multiCache.get('foo2', function(err, result) {
120120
console.log(result);
121121
// >> 'bar2'
122122

123123
// Delete from all caches
124-
multi_cache.del('foo2', function(err) {
124+
multiCache.del('foo2', function(err) {
125125
if (err) {
126126
console.log(err);
127127
}

0 commit comments

Comments
 (0)