Configure gcTime (garbage collection) within React Query

Tomasz Ducin
InstructorTomasz Ducin
Share this video with your friends

Social Share Links

Send Tweet

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.