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: src/main/java/org/dataloader/ValueCache.java
+26-11Lines changed: 26 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -7,33 +7,36 @@
7
7
8
8
/**
9
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
10
+
* of values. The {@link ValueCache} is used as a place to cache values when they come back from an async
11
+
* cache store.
11
12
* <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}.
13
+
* It differs from {@link CacheMap} which is in fact a cache of promised values aka {@link CompletableFuture}<V>'s.
14
+
* <p>
15
+
* {@link ValueCache is more suited to be a wrapper of a long-lived or externallly cached values. {@link CompletableFuture}s cant
16
+
* be easily placed in an external cache outside the JVM say, hence the need for the {@link ValueCache}.
15
17
* <p>
16
18
* {@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
19
* 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}.
20
+
* <p>
18
21
* 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
22
* the {@link ValueCache} and the promises to those values are also stored in the {@link CacheMap}.
20
23
* <p>
21
24
* The default implementation is a no-op store which replies with the key always missing and doesn't
22
25
* store any actual results. This is to avoid duplicating the stored data between the {@link CacheMap}
23
26
* out of the box.
24
27
* <p>
25
-
* The API signature uses completable futures because the backing implementation MAY be a remote external cache
26
-
* and hence exceptions may happen in retrieving values.
28
+
* The API signature uses {@link CompletableFuture}s because the backing implementation MAY be a remote external cache
29
+
* and hence exceptions may happen in retrieving values and they may take time to complete.
* Gets the specified key from the store. if the key si not present, then the implementation MUST return an exceptionally completed future
52
-
* and not null because null is a valid cacheable value. Any exception is will cause {@link DataLoader} to load the key via batch loading
54
+
* Gets the specified key from the value cache. If the key is not present, then the implementation MUST return an exceptionally completed future
55
+
* and not null because null is a valid cacheable value. An exceptionally completed future will cause {@link DataLoader} to load the key via batch loading
53
56
* instead.
57
+
* <p>
58
+
* NOTE: Your implementation MUST not throw exceptions, rather it should return a CompletableFuture that has completed exceptionally. Failure
59
+
* to do this may cause the {@link DataLoader} code to not run properly.
0 commit comments