From the course: TanStack Query: Efficient Data Fetching and State Management
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Improving performance with cache control - TanStack Query Tutorial
From the course: TanStack Query: Efficient Data Fetching and State Management
Improving performance with cache control
- [Instructor] In a previous video, we saw how focusing back on this page would automatically go to the API and refresh the data. It would update the cache pretty regularly. When we mounted a component or when the window regained focus, we saw that this data is going to be fetched quite a bit. Now for data that doesn't change that often, like a GitHub user profile, these extra API calls are pretty unnecessary and can impact performance. So what we can do here on line 12 is we can adjust our query client so that it has some default options. Now, this will overwrite the existing default, which is to always refresh the data. It's always considered stale once it has been loaded for the first time. But what we can do is we can reset the stale time to be every 30 seconds. So every 30 seconds here is going to overwrite the default. So from here we can modify the fetch GitHub user call so that we can start to visualize this a bit. So we'll say fetching username data at…