Skip to content

Commit 31cf788

Browse files
Brian DeteringBrian Detering
authored andcommitted
tweaks and docs on cacheKeyFn
1 parent b897c58 commit 31cf788

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ All the options available to Facebook Dataloader can be passed in here. An
9090
additional option called **expire** is also available, and will set a ttl in seconds
9191
on all keys set in redis if this option is passed.
9292

93+
By default, the "cacheKeyFn" will serialize objects and arrays using [json-stable-stringify](https://github.com/substack/json-stable-stringify) and allow all other values to pass through unchanged.
9394

9495
### Caching
9596

index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,7 @@ module.exports = fig => {
9292
this.opt = _.pick(opt, customOptions) || {};
9393

9494
this.opt.cacheKeyFn =
95-
this.opt.cacheKeyFn ||
96-
(k => {
97-
if (_.isString(k)) {
98-
return k;
99-
} else if (_.isObject(k)) {
100-
return stringify(k);
101-
} else {
102-
throw new TypeError('Key must be a string or a json object');
103-
}
104-
});
95+
this.opt.cacheKeyFn || (k => (_.isObject(k) ? stringify(k) : k));
10596

10697
this.keySpace = ks;
10798
this.loader = new DataLoader(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redis-dataloader",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "DataLoader Using Redis as a Cache",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)