How to prevent oversized IndexedDB cache with persistQueryClient? #9508
Unanswered
wandering-sage
asked this question in
Q&A
Replies: 1 comment
-
the size limit usually comes from the storage itself. We also wouldn’t know what to do if he size gets exceeded. if you’re worried that it grows too large, you can:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We’re using IndexedDB to persist the React Query client in a large app with many API calls and data-heavy views.
A common case in our app is fetching work item records on a list view. These are paginated, but over time, a user could fetch up to a million items if they dedicatedly fetch all the pages. After typical usage, the cache grows to ~4k queries (~45MB). We are worried that with an extended usage, this could go up to ~20k queries (~250MB) or even more.
This raises concerns about poor user experience, performance, and potential quota limits on browser storage.
To mitigate this, we’re currently capping the number of queries we restore from IndexedDB to 10k.
But this feels like a hack because:
Question:
👉 Is this kind of restore-time capping something you’d recommend?
Or is there a safer, preferred way to handle cache bloat with persistence?
Also curious, would it be possible to introduce a size-based limit in addition to maxAge when persisting or restoring from IndexedDB?
We imagine a config like:
Thanks for the amazing work on this library! We’re happy to contribute more context or explore a PR if this is something that fits the roadmap.
Beta Was this translation helpful? Give feedback.
All reactions