Cache Components

Next.js 16에서 캐시할 페이지·컴포넌트·함수를 명시하고 나머지는 요청 시 실행하는 모델입니다.

···
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는 캐시를 명시적으로 선택하게 합니다. use cache 지시어가 붙은 페이지·컴포넌트·함수는 생성된 캐시 키로 재사용하고, 동적 코드는 기본적으로 요청 시 실행합니다.

부분 사전 렌더링과 결합하면 재사용 가능한 콘텐츠와 요청별 콘텐츠를 한 페이지에 둘 수 있습니다. 무엇을 캐시할지와 무효화 시점을 구분해야 오래된 정보를 잘못 제공하지 않습니다.

언제 쓰나

Next.js 16 앱에서 정적·동적 경계를 세밀하게 나누고 재사용할 콘텐츠를 지정할 때 사용합니다.

페이지로 열기 ↗