Skip to content

Commit dab8a70

Browse files
committed
Improve readme about cached errors.
Fixes #61
1 parent 67dbc7a commit dab8a70

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ var promise1B = userLoader.load(1)
147147
assert(promise1A === promise1B)
148148
```
149149

150-
There are two common examples when clearing the loader's cache is necessary:
150+
#### Clearing Cache
151151

152-
*Mutations:* after a mutation or update, a cached value may be out of date.
153-
Future loads should not use any possibly cached value.
152+
The most common example when clearing the loader's cache is necessary is after
153+
a mutation or update, when a cached value may be out of date and future loads
154+
should not use any possibly cached value.
154155

155156
Here's a simple example using SQL UPDATE to illustrate.
156157

@@ -160,13 +161,18 @@ sqlRun('UPDATE users WHERE id=4 SET username="zuck"').then(
160161
)
161162
```
162163

163-
*Transient Errors:* A load may fail because it simply can't be loaded
164-
(a permanent issue) or it may fail because of a transient issue such as a down
165-
database or network issue. For transient errors, clear the cache:
164+
#### Caching Errors
165+
166+
If a batch load fails (that is, a batch function throws or returns a rejected
167+
Promise), then the requested values will not be cached. However if a batch
168+
function returns an `Error` instance for an individual value, that `Error` will
169+
be cached to avoid frequently loading the same `Error`.
170+
171+
In some circumstances you may wish to clear the cache for these individual Errors:
166172

167173
```js
168174
userLoader.load(1).catch(error => {
169-
if (/* determine if error is transient */) {
175+
if (/* determine if should clear error */) {
170176
userLoader.clear(1);
171177
}
172178
throw error;

0 commit comments

Comments
 (0)