Replies: 4 comments 8 replies
-
Yeah I was thinking about this since swr has this (or will have it in v2). All we would need to do is expose the possibility to overwrite the internal Object / Map with something that matches the interface. So you could do:
so then you could use your own implementation and do whatever you want with it... I just don't know how you would like to enforce the limit? Like, what happens if |
Beta Was this translation helpful? Give feedback.
-
已收到你的邮件。
|
Beta Was this translation helpful? Give feedback.
-
@TkDodo Just stumbled across this one, are there any news on this? This could probably break a lot of stuff when not done properly, but I feel like this could help a lot. Especially useful for 3rd party tools. There would need to be proper guidlines or smth. similar to make sure people also implement the notify stuff so it won't break other tooling. Otherwise it would probably lead to confusion and issues on this repo if some 3rd party tool implements some weird stuff there. |
Beta Was this translation helpful? Give feedback.
-
Hey, @TkDodo I see this is added to the V5 roadmap in #4252, though V5 is already here, and I couldn't find anything related to it. I don't exactly know what's in scope for the manual caching options, but just to add to the use cases, I have a very specific one for this as well: my backend is written on a concept of Resources, and tailor made so that frontend can consume it as efficiently as possible: To illustrate, queries for a list of items always return in the following format:
With get requests(and responses for mutations) following a similar pattern:
What this essentially means, is that the frontend can use a very specific caching strategy:
This cache setup would allow a lot of manual fiddling to be automated, such as query invalidation from mutations, automatic updates after mutations, etc. Compared to the current cache setup, it would also significantly reduce the cache size: currently every query is cached individually, so we have a lot of duplication between different kind of fetches for separate resources. |
Beta Was this translation helpful? Give feedback.
-
The use case where I'm currently trying to use tanstack-query has one rather peculiar requirement: Limit the size of the cache.
This can either be done by size (probably more complicated) or by item count (more arbitrary, but easier). I've tried to find a way to configure this, but couldn't find any. The closest was implementing (or extending) the QueryClient, but unfortunately to extend it, the
this.query
property is private, so manually limiting it in any of the ways described isn't possible.Btw: using time (cacheLimit) isn't an option, because users can trigger quite a few queries in a short amount of time.
Are there any suggestions on how this can be achieved, or can tanstack-query make it easier to create a custom cache implementation (would also make it possible to use different "backends" for the cache)
Beta Was this translation helpful? Give feedback.
All reactions