Cache hit and miss

캐시 히트·미스

A cache hit answers without contacting the origin. A miss fetches from the origin and fills the cache.

···
html
<div class="demo"><div class="head"><strong>CACHE</strong><span id="outcome">HIT</span></div><div class="scene"><div class="chip" id="client">browser</div><span class="arrow">→</span><div class="chip" id="cache">cache</div><span class="arrow">→</span><div class="chip" id="origin">origin</div></div><div class="foot"><span id="route">browser → cache → browser</span><span>tap to switch</span></div></div>
css
.demo{width:min(92vw,660px);height:min(86vh,310px);border:1px solid var(--line);border-radius:14px;background:var(--surface);padding:clamp(10px,2.5vmin,20px);display:flex;flex-direction:column;gap:clamp(6px,1.7vmin,12px);box-shadow:0 10px 35px rgba(0,0,0,.07);font:500 clamp(10px,2.8vmin,15px)/1.35 ui-monospace,SFMono-Regular,Consolas,monospace}
.head,.foot{display:flex;align-items:center;justify-content:space-between;gap:8px}.head strong{color:var(--accent);font-size:1.05em}.foot{color:var(--muted);font-size:.85em;min-height:1.4em}.scene{flex:1;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.5vmin,12px)}.chip{border:1px solid var(--line);background:var(--bg);border-radius:7px;padding:.4em .6em;text-align:center}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important;color:var(--accent)!important}.dim{opacity:.42}.arrow{color:var(--muted)}
.scene .chip{min-width:20%;height:50%;display:grid;place-items:center}.scene .arrow{font-size:1.5em}
js
let miss=false;function advance(){miss=!miss;document.getElementById("outcome").textContent=miss?"MISS · fill cache":"HIT · return";document.getElementById("origin").classList.toggle("on",miss);document.getElementById("origin").classList.toggle("dim",!miss);document.getElementById("cache").classList.add("on");document.getElementById("route").textContent=miss?"browser → cache → origin → cache":"browser → cache → browser"}advance();const timer=setInterval(advance,1300);document.querySelector(".demo").addEventListener("pointerdown",()=>{clearInterval(timer);advance()})

A cache stores frequently used responses near the requester. A valid value for the key is a hit; an absent or expired value is a miss.

The demo alternates between request routes. A hit returns at the cache; a miss reaches the origin and fills the cache. Expiration and invalidation rules matter as much as speed.

When to use

Use it to reduce repeated lookup latency and origin load. Design cache keys so private responses are not shared across users.

Open as page ↗