Skip to content

Commit a6564c0

Browse files
docs: describe new persist features
1 parent d2309f5 commit a6564c0

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

docs/src/pages/plugins/persistQueryClient.md

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,62 @@ When you reload/bootstrap your app:
7979

8080
## API
8181

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+
82125
### `persistQueryClient`
83126

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.
85128

86129
```ts
87-
persistQueryClient({ queryClient, persister })
130+
persistQueryClient({
131+
queryClient,
132+
persister,
133+
maxAge = 1000 * 60 * 60 * 24, // 24 hours
134+
buster = '',
135+
hydrateOptions,
136+
dehydrateOptions,
137+
})
88138
```
89139

90140
### `Options`
@@ -113,15 +163,6 @@ interface PersistQueryClientOptions {
113163
}
114164
```
115165

116-
The default options are:
117-
118-
```ts
119-
{
120-
maxAge = 1000 * 60 * 60 * 24, // 24 hours
121-
buster = '',
122-
}
123-
```
124-
125166
## Building a Persister
126167

127168
Persisters have the following interface:

0 commit comments

Comments
 (0)