Skip to content

How to understand caching in an application

Browser, CDN, framework, application and database caches: how to find every cache between a user and your data, and explain why something is stale.

October 13, 2026 · 2 min read · RepoGrasp team

"Why is this data stale?" is one of the most common questions in web development, and the answer is almost always a cache. Modern apps have several layers of caching, each with its own rules for how long data lives and how it's refreshed. Understanding them means listing every layer between the user and the source of truth.

List the layers

From closest to the user to furthest:

  1. Browser cache: HTTP cache headers like Cache-Control, service workers.
  2. Client data caches: TanStack Query, Apollo Client, SWR, RTK Query, framework router caches.
  3. CDN or edge cache: responses cached at the edge based on headers or platform config.
  4. Framework caches: for example, Next.js caching of rendered pages and data, with "use cache", revalidatePath and revalidateTag in recent versions.
  5. Application caches: in-memory maps, Redis, memoised functions.
  6. Database-level caching: materialised views, query caches, read replicas with replication lag.

Not every app has all of these. Find the ones yours has.

For each cache, answer four questions

  • What's the key? What makes two requests share a cached value?
  • How long does it live? TTL, stale time, or "until invalidated".
  • What invalidates it? Time, an explicit call, a deploy, a tag.
  • What happens on a miss? Who recomputes the value, and can many requests do it at once?

Find invalidation calls

Invalidation is where caching bugs live. Search for calls like invalidateQueries, revalidateTag, revalidatePath, cache.del, redis.del and CDN purge calls. Then check: does every write that changes the data invalidate every cache that holds it?

Watch for caches inside caches

A server page might cache data for an hour, the CDN might cache the page for ten minutes, and the client might hold its own copy. Stale data can come from any layer. Test by bypassing layers one at a time (a hard refresh, a request with no cache, a direct API call).

Remember in-memory caches in serverless

In-memory caches in serverless functions live only as long as one instance, and different instances have different contents. Behaviour can look random. Shared caches like Redis behave consistently.

Ask where data might be cached

Ask RepoGrasp "where can product prices be cached between the database and the product page, and what invalidates each cache?" It reads cache calls and framework configuration across the codebase and cites them. Infrastructure caching (CDN rules set in a dashboard) isn't in the code, so check that separately.

See our Next.js App Router and TanStack Query guides.