Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

fix: better understanding of staleTime and cacheTime #594

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

spaenleh
Copy link
Member

@spaenleh spaenleh commented Jan 26, 2024

Reading the docs more carefully, there was a miss-understanding in the use of staleTime and cacheTime.

React Query staleTime and cacheTime

So for our application we want:

  • a staleTime that represents our usual loading time, or until all components have rendered on screen and we would like to minimise the number of duplicated request to the backend. Ideally only one per resource.
  • a cacheTime that is big enough so that when navigating between pages we can display the "old" data before updating it -> this will remove a lot of loading spinners once we have data (even if it is slightly older).

Proposed default values:

  • staleTime: 3 seconds
  • cacheTime: 5 minutes (this is the default for react query)

Understanding this difference we should change Constant cache time to actually be a Constant stale time for rarely updated data (thumbnails, app list, and others)

@spaenleh spaenleh force-pushed the no-cachetime-for-item-thumbnail branch from 2c96c0c to 871a6b8 Compare January 26, 2024 08:15
@spaenleh spaenleh self-assigned this Jan 26, 2024
@spaenleh spaenleh added bug 🪲 Something isn't working improvement Not a feature but a QoL improvement in DX labels Jan 26, 2024
Copy link
Contributor

@ReidyT ReidyT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice explanations ! thank you 🙌

@spaenleh spaenleh force-pushed the no-cachetime-for-item-thumbnail branch from c6d9821 to e49ad9b Compare January 29, 2024 14:17
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@spaenleh spaenleh merged commit 662549a into main Jan 29, 2024
@spaenleh spaenleh deleted the no-cachetime-for-item-thumbnail branch January 29, 2024 14:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🪲 Something isn't working improvement Not a feature but a QoL improvement in DX v2.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants