This repository was archived by the owner on Feb 12, 2025. It is now read-only.
fix: better understanding of staleTime
and cacheTime
#594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reading the docs more carefully, there was a miss-understanding in the use of
staleTime
andcacheTime
.So for our application we want:
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.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 secondscacheTime
: 5 minutes (this is the default for react query)Understanding this difference we should change
Constant cache time
to actually be aConstant stale time
for rarely updated data (thumbnails, app list, and others)