Question presented to candidate:
"Our product page has a marketing header that almost never changes, a price that changes a few times a day, and a greeting that depends on the visitor's cookie. In older Next.js the whole route ended up either static or dynamic. How do Cache Components and the 'use cache' directive let one page mix all three?"
What a strong answer should cover:
cacheComponents: trueinnext.config.tsturns the model on: data access is dynamic by default and you opt in to caching. In 16.3+ it is set together withpartialPrefetching, and 16.4 makes it thecreate-next-appdefault.'use cache'marks an async function, component or whole file as cacheable; the cache key is built from the build ID, a function ID and the serialized arguments (including captured closure variables).cacheLifesets the lifetime (stale, revalidate, expire) andcacheTagattaches tags for on-demand invalidation; withoutcacheLifethedefaultprofile applies.- Partial Prerendering is the result: cached and static output goes into a prerendered static shell, while runtime data (
cookies(),headers(), uncached fetches) streams in behind<Suspense>. - Constraints: no
cookies()/headers()inside a cached scope (read outside and pass as arguments), arguments must be serializable, and uncached data outside<Suspense>fails the build. - The old flags are gone:
experimental.ppr,experimental_pprandexperimental.dynamicIOnow produce errors that point tocacheComponents.
Clarifying questions expected:
- "Is
cacheComponentsalready enabled, or are we migrating a route-segment-config app?" β the migration path differs. - "How stale may the price be, and who triggers updates?" β that decides the
cacheLifeprofile and whether tags are needed. - "Where do we host?" β the default cache is in memory per instance, which matters for serverless.
Code / implementation expected: Yes β a page with a cached component, a runtime component in <Suspense>, and the config flag.