-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
rename cacheTime #4678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
what about making it totally configurable ?: {
keepDataAfterDispose: boolean,
keepDataAfterDisposeDurationMs: number,
} I dislike long names, but couldn't think of better words |
We had some discussions internally about renaming
One advantage of this would be that the naming would be in-line with how the new TanStack router names those properties. I think there are a couple of reasons why renaming staleTime would not be ideal:
This leads me to the conclusion that we should leave
|
FWIW My team has definitely misinterpreted I would personally recommend removing 'cache' from the name of this particular property altogether to avoid the same aforementioned problem. To that end, my vote would be for I believe this is something a reasonable person could conceivably do if they had been exposed to the API before and remembered that |
I will vote for |
I would go for |
I think the confusion stems from people guessing / assuming how React Query works. For me, the hard part was understanding the concept of how React Query will use stale data to render a view, and then refresh that data in the background, finally updating the view, if the updated data is different. I think it would have helped with some exampled with timelines, depicting the different situations. |
👀 |
This version has some fairly major changes, but most of it is hidden from us thanks to Orval. We have made the following notable changes, however: * `cacheTime` has been renamed to `gcTime`. As far as I can tell, there are no behavioral changes and this is simply a rename to reduce confusion. Therefore, this change should be purely cosmetic. (See TanStack/query#4678, TanStack/query#1217, and TanStack/query#4829 for reference.) * Use object-style parameters to query methods where necessary. These changes should be purely cosmetic. * React Query v5 is written in TypeScript, so we can take advantage of better types. The one place we currently do that is in the `Edit` component's `useGetProgram` return types. Note that we also use `isPending` rather than `isLoading`. The docs are a bit confusing on this point as to whether they're equivalent; see https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5#status-loading-has-been-changed-to-status-pending-and-isloading-has-been-changed-to-ispending-and-isinitialloading-has-now-been-renamed-to-isloading. Initially I used `isLoading` when porting to v5, but TypeScript was not able to narrow the `data` value to non-nil unless I use `isPending`, so I've gone with `isPending` in the end. As far as I can tell, it works the same as before. * v5's dev tools are significantly improved, including the UI, which lets you choose via a nice drop-down menu where to locate the tool pop-up. This doesn't play well with our own "dev tools" checkbox UI, so I've temporarily disabled those `DevOptions`, as the UI for them will need to be rethought. I think adding another button to the canvas is probably the way to go, but I'll leave that work for later. FYI, the migration guide is here, and it informed most of these changes: https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5 Signed-off-by: Drew Hess <[email protected]>
This version has some fairly major changes, but most of it is hidden from us thanks to Orval. We have made the following notable changes, however: * `cacheTime` has been renamed to `gcTime`. As far as I can tell, there are no behavioral changes and this is simply a rename to reduce confusion. Therefore, this change should be purely cosmetic. (See TanStack/query#4678, TanStack/query#1217, and TanStack/query#4829 for reference.) * Use object-style parameters to query methods where necessary. These changes should be purely cosmetic. * React Query v5 is written in TypeScript, so we can take advantage of better types. The one place we currently do that is in the `Edit` component's `useGetProgram` return types. Note that we also use `isPending` rather than `isLoading`. The docs are a bit confusing on this point as to whether they're equivalent; see https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5#status-loading-has-been-changed-to-status-pending-and-isloading-has-been-changed-to-ispending-and-isinitialloading-has-now-been-renamed-to-isloading. Initially I used `isLoading` when porting to v5, but TypeScript was not able to narrow the `data` value to non-nil unless I use `isPending`, so I've gone with `isPending` in the end. As far as I can tell, it works the same as before. * v5's dev tools are significantly improved, including the UI, which lets you choose via a nice drop-down menu where to locate the tool pop-up. This doesn't play well with our own "dev tools" checkbox UI, so I've temporarily disabled those `DevOptions`, as the UI for them will need to be rethought. I think adding another button to the canvas is probably the way to go, but I'll leave that work for later. FYI, the migration guide is here, and it informed most of these changes: https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5 Signed-off-by: Drew Hess <[email protected]>
context
Almost everyone gets
cacheTime
wrong (exhibit A). It sounds like "the amount of time that data is cached for", but that is not correct.cacheTime
does nothing as long as a query is still in used. It only kicks in as soon as the query becomes unused. After the time has passed, data will be "garbage collected" to avoid the cache from growing (see also this explanation).RTK Query has the same feature - their prop is called keepUnusedDataFor. I think this is quite descriptive but also a bit long.
proposal
cacheTime
togcTime
gc
is referring to "garbage collect" time. It's a bit more technical, but also a quite well known abbreviation in computer science.Also, it is not something that most people will have to customize. The default of 5 minutes is usually fine. A rename will reduce the chance that this property is mixed up with
staleTime
.Lastly, if someone doesn't immediately know what
gcTime
stands for, they will (hopefully) consult the docs. This is a lot better than thinking they know whatcacheTime
does.Here is an old discussion on that topic:
The text was updated successfully, but these errors were encountered: