Skip to content

Commit d10cad0

Browse files
committed
feat: mutation cachetime
docs
1 parent 8550b2c commit d10cad0

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

docs/src/pages/guides/migrating-to-react-query-4.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,30 @@ For the same reason, those have also been combined:
9393
```
9494

9595
This flag defaults to `active` because `refetchActive` defaulted to `true`. This means we also need a way to tell `invalidateQueries` to not refetch at all, which is why a fourth option (`none`) is also allowed here.
96+
97+
### Streamlined NotifyEvents
98+
99+
Subscribing manually to the `QueryCache` has always given you a `QueryCacheNotifyEvent`, but this was not true for the `MutationCache`. We have streamlined the behavior and also adapted event names accordingly.
100+
101+
#### QueryCacheNotifyEvent
102+
103+
```diff
104+
- type: 'queryAdded'
105+
+ type: 'added'
106+
- type: 'queryRemoved'
107+
+ type: 'removed'
108+
- type: 'queryUpdated'
109+
+ type: 'updated'
110+
```
111+
112+
#### MutationCacheNotifyEvent
113+
114+
The `MutationCacheNotifyEvent` uses the same types as the `QueryCacheNotifyEvent`.
115+
116+
> Note: This is only relevant if you manually subscribe to the caches via `queryCache.subscribe` or `mutationCache.subscribe`
117+
118+
## New Features 🚀
119+
120+
### Mutation Cache Garbage Collection
121+
122+
Mutations can now also be garbage collected automatically, just like queries. The default `cacheTime` for mutations is also set to 5 minutes.

docs/src/pages/reference/MutationCache.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ const mutations = mutationCache.getAll()
6060
The `subscribe` method can be used to subscribe to the mutation cache as a whole and be informed of safe/known updates to the cache like mutation states changing or mutations being updated, added or removed.
6161

6262
```js
63-
const callback = mutation => {
64-
console.log(mutation)
63+
const callback = event => {
64+
console.log(event.type, event.mutation)
6565
}
6666

6767
const unsubscribe = mutationCache.subscribe(callback)
6868
```
6969

7070
**Options**
7171

72-
- `callback: (mutation?: Mutation) => void`
72+
- `callback: (mutation?: MutationCacheNotifyEvent) => void`
7373
- This function will be called with the mutation cache any time it is updated.
7474

7575
**Returns**

docs/src/pages/reference/useMutation.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ const {
1717
reset,
1818
status,
1919
} = useMutation(mutationFn, {
20+
cacheTime,
2021
mutationKey,
2122
onError,
2223
onMutate,
2324
onSettled,
2425
onSuccess,
2526
useErrorBoundary,
26-
meta,
27+
meta
2728
})
2829

2930
mutate(variables, {
@@ -39,6 +40,9 @@ mutate(variables, {
3940
- **Required**
4041
- A function that performs an asynchronous task and returns a promise.
4142
- `variables` is an object that `mutate` will pass to your `mutationFn`
43+
- `cacheTime: number | Infinity`
44+
- The time in milliseconds that unused/inactive cache data remains in memory. When a mutation's cache becomes unused or inactive, that cache data will be garbage collected after this duration. When different cache times are specified, the longest one will be used.
45+
- If set to `Infinity`, will disable garbage collection
4246
- `mutationKey: string`
4347
- Optional
4448
- A mutation key can be set to inherit defaults set with `queryClient.setMutationDefaults` or to identify the mutation in the devtools.

0 commit comments

Comments
 (0)