---
title: "Caching in Next Fold: what is cached and what clears it"
description: "How Next Fold caches each page with Next.js Cache Components and Sanity tags, and what clears that cache when an editor publishes."
url: https://nextfold.marcopontili.com/caching
lang: en
---

# 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](https://nextfold.marcopontili.com/caching#inspector)

## This page, right now

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

_On the HTML page: when this copy of the page entered the cache, the cache tags that can expire it, and the cache headers of a fresh request for the same URL._

## 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](https://nextfold.marcopontili.com/system)
