Cache Components

Next.js 16 explicitly caches selected pages, components, or functions while other code runs per request.

···
html
<section class="stage"><div class="heading">CACHE COMPONENTS <span class="hint">opt in per node</span></div><div class="tree"><div class="tile root">PAGE</div><div class="branches"><div class="tile cached">CATALOG <small>use cache</small></div><div class="tile dynamic">CART <small>request</small></div></div></div><div class="caption">Catalog reuses its result; cart runs per request</div></section>
css
.stage{width:min(94vw,780px);height:min(88vh,322px);padding:clamp(12px,3vmin,20px);border:1px solid var(--line);border-radius:16px;background:var(--surface);box-shadow:0 12px 36px #0001;display:flex;flex-direction:column;gap:clamp(7px,2vmin,14px);font:500 clamp(12px,3.5vmin,17px)/1.3 var(--font-sans,system-ui,sans-serif);overflow:hidden}.heading{display:flex;justify-content:space-between;align-items:center;gap:8px;font-weight:750;color:var(--accent)}.hint{color:var(--muted);font-size:clamp(12px,3.2vmin,14px);font-weight:500}.caption{margin-top:auto;color:var(--muted);font-size:clamp(12px,3.2vmin,14px)}.row{display:flex;gap:clamp(5px,1.5vmin,12px);align-items:center}.tile{padding:clamp(6px,1.8vmin,13px);border:1px solid var(--line);border-radius:9px;background:var(--bg);text-align:center;min-width:0}.arrow{color:var(--accent);font-weight:800}.stage [data-on]{transition:background .3s,border-color .3s,opacity .3s,transform .3s}.stage .on{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--surface));color:var(--accent)}.tree{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:clamp(5px,1.5vmin,12px)}.root{min-width:38%;font-weight:750}.branches{display:flex;gap:clamp(8px,3vmin,30px);width:100%;justify-content:center}.branches .tile{width:38%;max-width:190px;transition:border-color .3s,background .3s}.branches small{display:block;margin-top:5px;color:var(--muted);font:600 .75em ui-monospace,monospace}.cached{border-color:var(--accent)}.dynamic{border-color:var(--accent-3)}.stage[data-step="0"] .cached,.stage[data-step="1"] .cached,.stage[data-step="2"] .cached{background:color-mix(in srgb,var(--accent) 14%,var(--surface))}.stage[data-step="1"] .dynamic,.stage[data-step="2"] .dynamic{background:color-mix(in srgb,var(--accent-3) 18%,var(--surface))}.stage small,.stage button,.stage .cards b,.stage .phase b,.stage .pair b,.stage .tree-mini b{font-size:clamp(12px,3.2vmin,14px)!important}
js
const stage=document.querySelector(".stage");let step=0;function tick(){stage.dataset.step=String(step);step=(step+1)%3}tick();let timer=setInterval(tick,920);stage.addEventListener("pointerdown",()=>{clearInterval(timer);tick()})

Next.js 16 Cache Components make caching an explicit choice. Pages, components, or functions marked with use cache reuse entries keyed by the compiler; dynamic code runs at request time by default.

Together with partial prerendering, this puts reusable and request-specific content in one page. Cache ownership and invalidation must be clear to avoid serving stale information.

When to use

Use it in Next.js 16 to identify reusable content alongside request-specific work.

Open as page ↗