Renaming cacheTime to gcTime
This was one of the changes I’m most personally happy about because it is probably the most misunderstood option in React Query. Most often, it is assumed that cacheTime
means the length of time that data will be cached instead of what it really means, which is the time that inactive data in the cache will remain in memory.
To stop this misconception, the cacheTime
option has been renamed gcTime
. This is because gc
is often a shortened way to refer to the garbage collector. Therefore, from now on, we explicitly declare the time until our data is garbage-collected.
To use it, all you need to do is add the gcTime
option to your useQuery
/useMutation
hook, like this:
useQuery({ gcTime: 60000 });
In the snippet, we define that after our query is inactive for one minute, the data will be garbage-collected.
To wrap up the renaming spree, let us see how our Hydrate
component changed.