Back to Blog
React QueryNext.jsPerformanceFrontendCaching

React Query Caching Strategy for Busy Business Dashboards

Every tab switch in the dashboard triggered a fresh API call โ€” same data, same response, fetched again. A 5-minute staleTime, 30-minute cacheTime, and disabled refetchOnWindowFocus cut redundant API requests by 70% and made repeat views instant.

May 10, 20256 min read

The dashboards had a problem that took a while to notice. Managers would open the inventory view, check a filter, then switch to the sales view. Every tab switch was a fresh API request. Same data, same filters, same response. Just fetched again.

On a system serving 100+ stores across 8 brands, this added up to a lot of redundant backend load during peak morning hours.

Problem

Without a caching layer, every component mount triggered a fetch. Navigation within the dashboard meant repeated calls to the same endpoints with the same parameters. A manager checking 5 different views in a session generated 5 independent fetch cycles.

The backend was handling requests it had already answered in the last 30 seconds. The frontend was showing loading states for data it had just displayed.

There was also a window-focus issue. React Query refetches data by default when the browser window regains focus. For a dashboard that managers leave open all day while working in other tabs, this meant constant refetching throughout the day.

Dashboard fetch waterfall without caching

Solution

React Query with intentional stale and cache windows:

  • staleTime: 5 minutes. Data is considered fresh for 5 minutes after fetch. No refetch within that window.
  • cacheTime: 30 minutes. Data stays in memory for 30 minutes even if the component unmounts. Navigating back shows cached data instantly.
  • refetchOnWindowFocus: false. Window focus does not trigger refetch.
  • Query keys structured by brand and filter parameters so cache entries are specific.

For large store lists, server-side pagination at 50 per page keeps initial loads bounded. Parallel queries for data and count avoid a second round trip for pagination metadata.

React Query DevTools showing cache hit rates

Result

Redundant API calls dropped by about 70% across all dashboard views.

Page interactions became faster. Views that previously showed loading states now often load from cache instantly.

Backend load during peak morning hours dropped noticeably. The same data was being served far fewer times.

The configuration took about an hour to implement and tune. The gains were measurable in the next day's usage logs.

Found this useful?

Share it with someone who'd appreciate it.

https://wardvisual.com/blogs/react-query-cache-in-business-dashboards

Eduardo Manlangit Jr.
Eduardo Manlangit Jr.

@wardvisual ยท ๐Ÿ‡ต๐Ÿ‡ญ Dasmarinas City, Cavite PH

Full-stack engineer. Business systems, database optimization, and operations software.

Follow