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
This way, you do not need to store whole `QueryClient`, but choose what is worth to be persisted in your application. Each query is lazily restored (when the Query is first used) and persisted (after each run of the `queryFn`), so it does not need to be throttled. `staleTime` is also respected after restoring the Query, so if data is considered `stale`, it will be refetched immediately after restoring. If data is `fresh`, the `queryFn` will not run.
38
38
39
+
Garbage collecting a Query from memory **does not** affect the persisted data. That means Queries can be kept in memory for a shorter period of time to be more **memory efficient**. If they are used the next time, they will just be restored from the persistent storage again.
@@ -44,15 +46,20 @@ import { experimental_createPersister } from '@tanstack/query-persist-client-cor
44
46
const queryClient =newQueryClient({
45
47
defaultOptions: {
46
48
queries: {
47
-
gcTime: 1000*60*60*24, //24 hours
49
+
gcTime: 1000*30, //30 seconds
48
50
persister: experimental_createPersister({
49
51
storage: AsyncStorage,
52
+
maxAge: 1000*60*60*12// 12 hours
50
53
}),
51
54
},
52
55
},
53
56
})
54
57
```
55
58
59
+
### Adapted defaults
60
+
61
+
The `createPersister` plugin technically wraps the `queryFn`, so it doesn't restore if the `queryFn` doesn't run. In that way, it acts as a caching layer between the Query and the network. Thus, the `networkMode` defaults to `'offlineFirst'` when a persister is used, so that restoring from the persistent storage can also happen even if there is no network connection.
0 commit comments