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: docs/src/pages/plugins/persistQueryClient.md
+52-11Lines changed: 52 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,12 +79,62 @@ When you reload/bootstrap your app:
79
79
80
80
## API
81
81
82
+
### `persistQueryClientRestore`
83
+
84
+
This will attempt to restore a persister's stored cached to the active query cache.
85
+
86
+
```ts
87
+
persistQueryClientRestore({
88
+
queryClient,
89
+
persister,
90
+
maxAge=1000*60*60*24, // 24 hours
91
+
buster='',
92
+
hydrateOptions,
93
+
})
94
+
```
95
+
96
+
### `persistQueryClientSave`
97
+
98
+
This will attempt to save the current query cache with the persister. You can use this to explicitly persist the cache at the moments you choose.
99
+
100
+
```ts
101
+
persistQueryClientSave({
102
+
queryClient,
103
+
persister,
104
+
buster='',
105
+
dehydrateOptions,
106
+
})
107
+
```
108
+
109
+
### `persistQueryClientSubscribe`
110
+
111
+
This will subscribe to query cache updates which will run `persistQueryClientSave`. For example: you might initiate the `subscribe` when a user logs-in and checks "Remember me".
112
+
113
+
- It returns an `unsubscribe` function which you can use to discontinue the monitor; ending the updates to the persisted cache.
114
+
- If you want to erase the persisted cache after the `unsubscribe`, you can send a new `buster` to `persistQueryClientRestore` which will trigger the persister's `removeClient` function and discard the persisted cache.
115
+
116
+
```ts
117
+
persistQueryClientSubscribe({
118
+
queryClient,
119
+
persister,
120
+
buster='',
121
+
dehydrateOptions,
122
+
})
123
+
```
124
+
82
125
### `persistQueryClient`
83
126
84
-
Pass this function a `QueryClient` instance and a persister that will persist your cache. Both are **required**
127
+
This will automatically restore any persisted cache and permanently subscribe to the query cache to persist any changes from the query cache to the persister.
0 commit comments