You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// set a prefix for the keys stored in redis. This way you can avoid key
@@ -20,11 +20,16 @@ const loader = new RedisDataLoader(
20
20
// The options here are the same as the regular dataloader options, with
21
21
// the additional option "expire"
22
22
{
23
-
// caching here is a local in memory cache
23
+
// caching here is a local in memory cache. Caching is always done
24
+
// to redis.
24
25
cache:true,
25
26
// if set redis keys will be set to expire after this many seconds
26
27
// this may be useful as a fallback for a redis cache.
27
-
expire:60
28
+
expire:60,
29
+
// can include a custom serialization and deserialization for
30
+
// storage in redis.
31
+
serialize:date=>date.getTime(),
32
+
deserialize:timestamp=>newDate(timestamp)
28
33
}
29
34
);
30
35
@@ -40,9 +45,10 @@ loader.clear(5).then(() => {})
40
45
In general, RedisDataLoader has the same API as the Facebook Dataloader Api,
41
46
with a few differences. Read through the [Facebook Dataloader documentation](https://github.com/facebook/dataloader) and then note the differences mentioned here.
42
47
43
-
-`clear` returns a promise (waits until redis succeeds at deleting the key)
48
+
-`clear` returns a promise (waits until redis succeeds at deleting the key). Facebook Dataloader's `clear` method is synchronous.
44
49
-`clearAll` is not available (redis does not have an efficient way to do this?)
45
-
-`prime` will always overwrite the redis cache. It in turn calls prime on the local cache (which does not adjust the cache if the key already exists)
50
+
-`prime` will always overwrite the cache. Facebook Dataloader will only write to
51
+
its cache if a value is not already present. Prime is asyncronous and returns a Promise.
46
52
- dataloader results must be either `null` or a JSON object.
0 commit comments