0
Challenge · 21Rendering & Caching

cacheTag & invalidation granularity

Cachingused in ~75% of apps

You shipped a job board. A recruiter edits ONE listing and now you have to decide: do you blow away the whole feed cache, or just that one card? Get the tag granularity wrong and you either serve stale data forever or re-render everything on every tiny edit. This is the exact judgement interviewers probe to see if you actually understand caching, not just memorized the API.

Core idea. `cacheTag(name)` doesn't cache anything — it puts a LABEL on a `'use cache'` entry so you can invalidate it later by name. The whole skill is choosing the label's granularity (per-item like `job-42` vs per-list like `jobs`) to control the BLAST RADIUS of an invalidation: how much cache one edit throws away.
Playground, this isn't a screenshot
<ViewCount />no data yet
—

Press Visit to mount the component.

SWR CACHE (key: /views)
(empty)
SERVER (live, drifts)
1,280
visits: 0
// SWR activity log…

First visit blocks on the network. Every visit after serves the cached (stale) value instantly, then revalidates in the background and swaps in fresh data — that is the whole name made literal.

↑ play a little first, then dig in