From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Caching and refetching comparison

Caching and refetching comparison

Now, let's discuss the automatic caching and re-fetching. Now, let's discuss the automatic caching and re-fetching. By default, RTK query caches the result of an API call, which is for your GET API calls. It is only going to refetch in the following conditions. If the component remounts again after some time, there is a limited caching time to live window. During that time, if your component remounts, it is going to not call an API, rather fetch data from the cache. So this user result that we are seeing on our screen for 10 users, it can be cached and in the following remounts of the component, it is not going to call the API again. If there is a cache invalidation via mutation, means the data has been changed by defining the mutation, then the cache will be invalidated and it will re-fetch the results of the get query. Or the developer is manually triggering a re-fetch on some button click or any other click handler, then it will re-fetch the data again and won't get it from the…

Contents