Experimental Astro route caching

Astro 실험적 경로 캐시

Astro 6 experiments with route-level cache lifetime and invalidation for server-rendered responses.

···
html
<section class="stage"><div class="heading">ROUTE CACHE <span class="hint">miss / hit / invalidate</span></div><div class="cache-flow"><div class="tile request">GET /news</div><div class="arrow">→</div><div class="cache-box">CACHE <b id="cache-state">MISS</b></div><div class="arrow">→</div><div class="tile renderer">RENDER</div></div><div class="caption" id="cache-caption">First request fills the cache</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)}.cache-flow{flex:1;display:flex;align-items:center;justify-content:center;gap:clamp(3px,1.3vmin,12px)}.cache-flow .tile,.cache-box{flex:1;max-width:145px;min-width:0;min-height:70px;display:flex;flex-direction:column;align-items:center;justify-content:center}.cache-box{border:2px solid var(--accent);border-radius:9px;background:color-mix(in srgb,var(--accent) 10%,var(--surface));font-weight:700}.cache-box b{color:var(--accent);margin-top:5px}.renderer{opacity:1;transition:opacity .3s}.stage[data-step="1"] .renderer{opacity:.2}.stage[data-step="2"] .cache-box{border-color:var(--accent-3)}.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"),state=document.getElementById("cache-state"),caption=document.getElementById("cache-caption"),states=["MISS","HIT","PURGE"],notes=["First request fills the cache","Stored response skips rendering","Invalidation forces fresh output"];let step=0;function tick(){stage.dataset.step=String(step);state.textContent=states[step];caption.textContent=notes[step];step=(step+1)%3}tick();let timer=setInterval(tick,1000);stage.addEventListener("pointerdown",()=>{clearInterval(timer);tick()})

Astro 6 experimental route caching stores SSR responses and lets a route declare lifetime and tags. A cache hit serves the stored response without rendering again.

At release, the built-in memory provider is mainly suited to the Node adapter; check platform support separately. The demo cycles through miss, hit, invalidation, and regeneration.

When to use

Evaluate it for repeated Astro SSR responses after checking the experimental API and provider support.

Open as page ↗