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
Copy file name to clipboardExpand all lines: README.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -322,13 +322,13 @@ will be given the same future and hence the same value.
322
322
323
323
This cache can only work local to the JVM, since its caches `CompletableFuture`s which cannot be serialised across a network say.
324
324
325
-
The second level cache is a value cache represented by the interface `org.dataloader.CachedValueStore`. By default, this is not enabled and is a no-op.
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
326
327
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
328
329
329
## Custom future caches
330
330
331
-
The default cache behind `DataLoader` is an in memory `HashMap`. There is no expiry on this, and it lives for as long as the data loader
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
332
lives.
333
333
334
334
However, you can create your own custom cache and supply it to the data loader on construction via the `org.dataloader.CacheMap` interface.
@@ -346,13 +346,15 @@ As stated above, a custom `org.dataloader.CacheMap` is a local cache of futures
346
346
347
347
## Custom value caches
348
348
349
-
You will need to create your own implementations of the `org.dataloader.CachedValueStore` if your want to use an external cache.
349
+
You will need to create your own implementations of the `org.dataloader.ValueCache` if your want to use an external cache.
350
350
351
-
This library does not ship with any implementations of `CachedValueStore` because it does not want to have
352
-
production dependencies on external cache libraries.
351
+
This library does not ship with any implementations of `ValueCache` because it does not want to have
352
+
production dependencies on external cache libraries, but you can easily write your own.
353
353
354
-
The API of `CachedValueStore` has been designed to be asynchronous because it is expected that the value cache could be outside
355
-
your JVM. It uses `Future`s to get and set values into cache, which may involve a network call and hence exceptional failures to get
354
+
The tests have an example based on [Caffeine](https://github.com/ben-manes/caffeine).
355
+
356
+
The API of `ValueCache` has been designed to be asynchronous because it is expected that the value cache could be outside
357
+
your JVM. It uses `CompleteableFuture`s to get and set values into cache, which may involve a network call and hence exceptional failures to get
Copy file name to clipboardExpand all lines: src/main/java/org/dataloader/ValueCache.java
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,26 @@
1
1
packageorg.dataloader;
2
2
3
3
importorg.dataloader.annotations.PublicSpi;
4
-
importorg.dataloader.impl.NoOpCachedValueStore;
4
+
importorg.dataloader.impl.NoOpValueCache;
5
5
6
6
importjava.util.concurrent.CompletableFuture;
7
7
8
8
/**
9
-
* Cache value store for data loaders that use caching and want a long-lived or external cache.
9
+
* The {@link ValueCache} is used by data loaders that use caching and want a long-lived or external cache
10
+
* of values. The {@link ValueCache} is used as a place to cache values when they come back from
11
+
* <p>
12
+
* It differs from {@link CacheMap} which is in fact a cache of promises to values aka {@link CompletableFuture}<V> and it rather suited
13
+
* to be a wrapper of a long lived or external value cache. {@link CompletableFuture}s cant be easily placed in an external cache
14
+
* outside the JVM say, hence the need for the {@link ValueCache}.
15
+
* <p>
16
+
* {@link DataLoader}s use a two stage cache strategy if caching is enabled. If the {@link CacheMap} already has the promise to a value
17
+
* that is used. If not then the {@link ValueCache} is asked for a value, if it has one then that is returned (and cached as a promise in the {@link CacheMap}.
18
+
* If there is no value then the key is queued and loaded via the {@link BatchLoader} calls. The returned values will then be stored in
19
+
* the {@link ValueCache} and the promises to those values are also stored in the {@link CacheMap}.
10
20
* <p>
11
21
* The default implementation is a no-op store which replies with the key always missing and doesn't
12
22
* store any actual results. This is to avoid duplicating the stored data between the {@link CacheMap}
13
-
* and the store.
23
+
* out of the box.
14
24
* <p>
15
25
* The API signature uses completable futures because the backing implementation MAY be a remote external cache
16
26
* and hence exceptions may happen in retrieving values.
0 commit comments