Configure gcTime (garbage collection) within React Query

Tomasz Ducin
InstructorTomasz Ducin
Share this video with your friends

Social Share Links

Send Tweet
Published 6 months ago
Updated a month ago

gcTime stands for "garbage collection time" and it is the amount of time that must pass, when there are no components actively using a query, before the query is cleared from the cache.

It is set independently from stale time!

[00:00] Set the GC time property on the query options of a given query. This is yet again defined in milliseconds and stands for garbage collection. So as long as there is at least one active subscriber active component which requires the query data, then g [00:20] c doesn't kick in. G c will kick in only when there are no active components and we're starting to count g c. So let me just refresh just to make sure that the new settings are applied. We'll move to employees tab. So as long as there is at least one component [00:39] which reads the data, g c doesn't kick in. But when we walk away into a page where there are no components that would require the data, after 3 seconds, this query is being removed from the cache entirely. What is important is that stale time and g c time are totally [00:59] independent on each other. So it could potentially happen that GC time could be smaller than stale time. They work independently and they do different things.

egghead
egghead
~ 6 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today