# The Data Cache

> Persistent, cross-user HTTP caching via fetch.

Subject: Next.js | Lesson 23 of 65 | 6 min read
Interactive lesson: https://codewithanimation.in/nextjs/data-cache
Previous: [Request Memoization](https://codewithanimation.in/nextjs/request-memoization.md) | Next: [The Full Route Cache](https://codewithanimation.in/nextjs/full-route-cache.md)

## The persistent cache

Unlike Request Memoization, which is destroyed the moment the page finishes rendering, the Data Cache is persistent. It survives across multiple server requests, and its cached data is shared among all users visiting your site.

Next.js achieves this by extending the native `fetch` API, allowing you to configure caching behavior on a per-request basis.

## Granular control

Historically, caching was done at the page level. If a page was cached, everything on it was cached.

The Data Cache allows granular, component-level caching. Your Sidebar can fetch cached navigational links, while your Header simultaneously fetches real-time, completely uncached shopping cart data on the exact same page.

## The three core configurations

You control the Data Cache using the options object in your `fetch` calls:

`{ cache: 'force-cache' }`: The request is cached indefinitely until manually invalidated.

`{ cache: 'no-store' }`: The request completely bypasses the cache and hits the origin server every time.

`{ next: { revalidate: 60 } }`: The request is cached, but automatically invalidated after 60 seconds.

## Common mistake: The Next.js 15 paradigm shift

If you learned Next.js 14, you likely encountered the 'caching nightmare' where data refused to update. This was because Next.js 14 aggressively defaulted to `force-cache`.

Next.js 15 fundamentally changed this. The framework now defaults to `no-store` (uncached) for `fetch` requests when dynamic functions are used. You must explicitly opt-in to caching.

## Tip: Bypassing the cache

Even if you set `force-cache`, certain dynamic Next.js functions will force the route to bypass caching entirely.

For example, if you read cookies via `cookies()`, or read headers via `headers()`, Next.js knows the response depends on the specific user, and will automatically opt out of the Data Cache for that render path.

## Try it: The Fetch Semantics

Review the mapping below to understand exactly how the `fetch` API options dictate whether a request hits the Data Cache or the Origin Server.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/data-cache

## Check yourself

### Question 1

What is the primary difference between Request Memoization and the Data Cache?

- A. Memoization works on the client, the Data Cache works on the server.
- B. Memoization persists across all users, while the Data Cache is per-user.
- C. Memoization lasts for a single render pass; the Data Cache persists across multiple requests and users.
- D. Memoization requires React.cache(), the Data Cache only requires Axios.

Correct answer: C

Request Memoization is a short-lived deduplication tool for a single render. The Data Cache is a long-lived, cross-user storage mechanism.

- Why not A: Both operate on the server.
- Why not B: It is the exact opposite.
- Why not D: The Data Cache relies on the extended native fetch API.

### Question 2

In Next.js 15, what is the default caching behavior for a fetch request inside a dynamic route?

- A. force-cache
- B. no-store
- C. revalidate: 3600
- D. only-if-cached

Correct answer: B

Next.js 15 shifted to 'uncached by default' (`no-store`) for dynamic requests to prevent stale data issues, requiring developers to explicitly opt-in to caching.

- Why not A: This was the default in Next.js 14, which caused widespread confusion.
- Why not C: Next.js does not guess time-based revalidation defaults.
- Why not D: This is not a standard Next.js fetch cache directive.

## Remember this

- The Data Cache persists across multiple server requests and is shared among all users.
- Next.js 15 defaults to `no-store` (uncached) for dynamic requests.
- Use `force-cache` to cache indefinitely.
- Use `next: { revalidate: N }` for Time-based Revalidation.
- Calling `cookies()` or `headers()` will dynamically opt the route out of the Data Cache.
