Caching

Cached until something changes

Every page here is built once and served from the cache until its content changes. Publishing in Sanity expires only the pages that used the changed document.

Inspect this page

This page, right now

When it was cached, what clears it, and a live request.

Cached
…
Cleared by
A publish
via the cache tag page:caching
Content
Seed
Bundled with the site

Request a page

Request a page twice: the second answer comes from the cache.

Requests to /caching

  1. …… ms

What happens when an editor publishes

  1. Build

    The build renders every known page and stores it with tags: one for the page, plus one for each Sanity document it read.

  2. Serve

    Visitors get the stored copy. Vercel's CDN keeps it close to them, so the server does no work.

  3. Publish

    An editor publishes in the Studio, and Sanity's Live Content API tells the site which documents changed.

  4. Expire

    The site expires the tags for those documents. A signed webhook does the same when no browser has the site open.

  5. Render again

    The next request renders a fresh copy and stores it. Pages that did not use the document stay cached.

Where a page can come from

  • Sanity's CDN

    Queries for published content go to Sanity's API CDN, so even a fresh render is quick.

  • The Next.js cache

    Each page and query result is stored with 'use cache' under tags. Tags decide what expires, so a publish never clears the whole site.

  • Vercel's CDN

    Finished pages are served from the edge. The x-vercel-cache header says whether a response was a hit.

The rest of the system

Hosting, DNS, security headers, and the release flow around this cache.

How it's run

This page comes from the seed copy bundled with the site, until the Sanity dataset publishes its own version.