How to skip in-memory cache and default to persisted storage? #7533
-
Hi folks, we have a very specific use case where we are aiming for a local-first-like experience where we prefetch thousands of requests the first time the app loads and use the local storage persister, so the next time the app is opened or a different view is navigated too, it feels very fast. ⚡ However, since the entire local cache is loaded to the memory when the app loads, it means that we may have hundreds of MBs of JSON responses in memory, slowing down the app and using a ton of RAM in the browser’s tab. Is there a way to essentially disable the in-memory cache, using local storage as the cache? This way, we won’t need to load up all the data in memory but will read and write from the disk on every first request, after which it’s ok to load them in memory. I considered writing a custom fetcher function that returns data from local storage pretending that it comes from the server, but then I have to manually revalidate after making the actual request. Appreciate any ideas! Thank you for your hard work developing and maintaining this library! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
you can't disable it, but you can "lazy-load" each query when it's used the first time. That's what |
Beta Was this translation helpful? Give feedback.
you can't disable it, but you can "lazy-load" each query when it's used the first time. That's what
creatPersister
is for: https://tanstack.com/query/v5/docs/framework/react/plugins/createPersister