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
@@ -313,6 +313,49 @@ and some of which may have failed. From that data loader can infer the right be
313
313
On the above example if one of the `Try` objects represents a failure, then its `load()` promise will complete exceptionally and you can
314
314
react to that, in a type safe manner.
315
315
316
+
## Caching
317
+
318
+
`DataLoader` has a two tiered caching system in place.
319
+
320
+
The first cache is represented by the interface `org.dataloader.CacheMap`. It will cache `CompletableFuture`s by key and hence future `load(key)` calls
321
+
will be given the same future and hence the same value.
322
+
323
+
This cache can only work local to the JVM, since its caches `CompletableFuture`s which cannot be serialised across a network say.
324
+
325
+
The second level cache is a value cache represented by the interface `org.dataloader.ValueCache`. By default, this is not enabled and is a no-op.
326
+
327
+
The value cache uses an async API pattern to encapsulate the idea that the value cache could be in a remote place such as REDIS or Memcached.
328
+
329
+
## Custom future caches
330
+
331
+
The default future cache behind `DataLoader` is an in memory `HashMap`. There is no expiry on this, and it lives for as long as the data loader
332
+
lives.
333
+
334
+
However, you can create your own custom cache and supply it to the data loader on construction via the `org.dataloader.CacheMap` interface.
You could choose to use one of the fancy cache implementations from Guava or Kaffeine and wrap it in a `CacheMap` wrapper ready
423
-
for data loader. They can do fancy things like time eviction and efficient LRU caching.
424
-
425
452
## Manual dispatching
426
453
427
-
The original [Facebook DataLoader](https://github.com/facebook/dataloader) was written in Javascript for NodeJS. NodeJS is single-threaded in nature, but simulates
428
-
asynchronous logic by invoking functions on separate threads in an event loop, as explained
454
+
The original [Facebook DataLoader](https://github.com/facebook/dataloader) was written in Javascript for NodeJS.
455
+
456
+
NodeJS is single-threaded in nature, but simulates asynchronous logic by invoking functions on separate threads in an event loop, as explained
429
457
[in this post](http://stackoverflow.com/a/19823583/3455094) on StackOverflow.
430
458
431
459
NodeJS generates so-call 'ticks' in which queued functions are dispatched for execution, and Facebook `DataLoader` uses
432
460
the `nextTick()` function in NodeJS to _automatically_ dequeue load requests and send them to the batch execution function
433
461
for processing.
434
462
435
-
And here there is an **IMPORTANT DIFFERENCE** compared to how `java-dataloader` operates!!
463
+
Here there is an **IMPORTANT DIFFERENCE** compared to how `java-dataloader` operates!!
436
464
437
465
In NodeJS the batch preparation will not affect the asynchronous processing behaviour in any way. It will just prepare
0 commit comments