Closed
Conversation
Without an explicit gcTime, inactive queries using staleTime: Infinity stay "fresh" forever and never get garbage collected. Setting gcTime to 30 min ensures inactive query data is eventually cleaned up while being generous enough for a long-running desktop app.
1443977 to
eba995e
Compare
jonathanlab
reviewed
Mar 30, 2026
Contributor
There was a problem hiding this comment.
afaik gcTime and staleTime are fully independent. Garbage collection is only triggered once a query has zero observers right? So if a query with staleTime: infinity has no observers, it gets garbage collected after 5 minutes. If it has observers, it'll just stay around infinitely.
I do not see how bumping it to 30 minutes helps in this scenario, as it would only increase cache retention, but I might be wrong :)
Member
Author
|
You are right, there's no point changing this, I misunderstood the setting's impact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
We set
staleTimeglobally but never setgcTime. TanStack Query's default gcTime is 5 min which sounds fine, but queries that override withstaleTime: Infinity(we have a bunch) stay "fresh" forever, meaning the GC never kicks in for them even when they go inactive.Changes
Set an explicit
gcTime: 30minat the client level so inactive query data always gets cleaned up regardless of staleTime. 30 min is generous enough for a long-running desktop app where you're switching between tasks/files, but prevents multi-hour sessions from hoarding stale data indefinitely.