# ISR and caching

Revalidate pages and cached data by time, tag or path, with the Next.js APIs you already use.

Use Next.js's caching APIs as you would on a Next.js server; nothing in your app needs to change.
Arkor shares each deployment's cache across regions. Regenerated pages and invalidations
propagate to the edge; a region can briefly serve an older copy while that happens. See
[How soon changes appear](#how-soon-changes-appear) for the timing and local-cache behavior.

## Revalidate by time [#revalidate-by-time]

Set a lifetime with `cacheLife` in a `'use cache'` function or component, with `revalidate` on a
route segment or a `fetch`, or with `revalidate` in `getStaticProps`:

```tsx title="app/blog/page.tsx"
import { cacheLife, cacheTag } from 'next/cache';

async function getPosts() {
  'use cache';
  cacheLife({ stale: 30, revalidate: 60, expire: 3600 });
  cacheTag('posts');
  const response = await fetch('https://cms.example.com/api/posts');
  return response.json();
}
```

For Arkor's production `default` and `remote` `use cache` handlers, a render can read the cached
value through its `revalidate` boundary. Once it is older, Next.js computes a replacement for that
read, so the render can take longer. Tag-based revalidation and custom cache handlers keep their
own policies.

Page ISR and cached `fetch` / `unstable_cache` retain their existing policies. A page's ISR delivery
record behaves as follows:

- Before `revalidate` seconds have passed, the cached version is served.
- After that, the cached version is still served, and the page is regenerated behind the response.
  The next visitors get the new version.
- After `expire`, the cached version is no longer served: the page is regenerated before the
  response, and the visitor waits for it.

## Revalidate on demand [#revalidate-on-demand]

Call `revalidateTag` or `revalidatePath` from a route handler or a Server Action, for example when
your CMS publishes:

```ts title="app/api/revalidate/route.ts"
import { revalidateTag } from 'next/cache';

export async function POST(request: Request) {
  if (request.headers.get('authorization') !== `Bearer ${process.env.REVALIDATE_SECRET}`) {
    return new Response('Unauthorized', { status: 401 });
  }
  const tag = new URL(request.url).searchParams.get('tag');
  if (tag === null) {
    return new Response('Missing tag', { status: 400 });
  }
  revalidateTag(tag, 'max');
  return Response.json({ revalidated: tag });
}
```

| Call                                                  | Effect                                                                                  |
| ----------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `revalidateTag(tag, 'max')`                           | Pages and data with the tag become stale: served until regenerated behind the response. |
| `updateTag(tag)`, `revalidateTag(tag, { expire: 0 })` | They expire at once: the next request waits for them to be regenerated.                 |
| `revalidateTag(tag)` (one argument, deprecated)       | Expires at once, like `updateTag`.                                                      |
| `revalidatePath('/blog')`                             | The page at that path is revalidated.                                                   |
| `revalidatePath('/blog/[slug]', 'page')`              | Every page of the dynamic route is revalidated.                                         |

In the Pages Router, `res.revalidate('/path')` works as on Next.js.

## How soon changes appear [#how-soon-changes-appear]

An invalidation — `revalidatePath`, `revalidateTag`, `updateTag` — normally reaches active regions
within a few seconds: a page it reaches is not sent as it was, but rendered again, or sent stale and rendered
behind it, as on Next.js. Until a region has the version rendered since, your app answers the page
there. The lookup runs in the background, so a location can briefly serve its previous copy
before learning of the invalidation. This is not a strict propagation deadline. A regeneration of a page that went stale with time, and `res.revalidate()` in the Pages
Router, can take a minute or more to reach every region. For data that must be current on every
request, render it dynamically instead of caching it.

The edge also keeps a page it has sent in its memory, and sends it from there at once, checking the
cache for a newer version behind it. After a regeneration, it can send the version before it once
more — to a visitor or a few, however long after the regeneration they come — and sends the new
version after that. A page past its `expire` is never sent this way: it is rendered again first, as
on Next.js. Nor is a page an invalidation reached (above).

Each data center also keeps its own copy of a cached page for a few minutes, so a page visited
there recently is sent without waiting for the cache's storage. The copy is checked against the
cache on every visit that uses it: after a regeneration, a data center where the page is rarely
visited can send the version before it until that check comes back, most often to one visitor, and
sends the new version after that. A copy is only used within five minutes of being checked.

If your pages must never be sent from such a copy, turn it off for the project. Every page is then
read from the cache's storage: no change waits on a copy, and a rarely visited page takes longer to
start arriving.

```bash title="terminal"
curl -X POST https://api.arkor.dev/v1/projects/$PROJECT_ID/cache-api \
  -H "authorization: Bearer $ARKOR_TOKEN" -H 'content-type: application/json' \
  -d '{"enabled":false}'
```

`{"enabled":true}` turns it back on. The project's `cacheApi` field says which it is.

Each deployment starts from what its own build rendered. A new deployment does not reuse the cache
of the one before it.

## What is not cached [#what-is-not-cached]

- Server Actions and requests with a multipart body.
- Requests in draft mode.
- A render that answered with a status other than 200.
- Routes with `export const runtime = 'edge'`: their pages are not regenerated. `fetch` results
  they cache are kept.

## Check what was served [#check-what-was-served]

The `x-arkor-edge` response header says whether a page came from the cache and whether it was
fresh or stale; see [Response headers](/docs/caching/response-headers). To see the whole history
of a deployment's cache (every generation, invalidation and tag) turn on the
[Cache Inspector](/docs/caching/cache-inspector).

## Limits [#limits]

| Limit                                              | Value                                              |
| -------------------------------------------------- | -------------------------------------------------- |
| Length of a tag                                    | 256 characters                                     |
| Tags in one `fetch`, `cacheTag` or `revalidateTag` | 128                                                |
| Tags on one cached page, including implicit ones   | 1,024                                              |
| Size of a cached value or page                     | 25 MiB; a larger `'use cache'` value is not stored |
| Cached entries per deployment                      | 50,000                                             |
| Tags per deployment                                | 100,000                                            |
| Regenerations per deployment                       | 600 a minute                                       |

---

Text on this page: Creative Commons Attribution 4.0 International (https://creativecommons.org/licenses/by/4.0/) by Arkor, 2026.

Code samples on this page: MIT License (https://opensource.org/license/mit) by Arkor, 2026.

Scope and exceptions: https://www.arkor.dev/license
