Edge Rendering

Preview — 3 of 10 questions

What does the "use cache" directive do?

javascript
async function getChallenges(filters: Filters) {
  'use cache';
  cacheTag('challenges');
  cacheLife('minutes');
  return prisma.challenge.findMany({ where: buildWhere(filters) });
}
AIt is the same as "use server" for caching purposes
BIt turns an async function (or file, or component) into a cache boundary: the return value is cached keyed by the serializable arguments, cacheLife() picks a freshness profile, and cacheTag() attaches tags for revalidateTag. It is like unstable_cache but with colocated configuration and composability
CIt only works with fetch() calls
DIt is a browser cache directive like Cache-Control

What is the right approach?

javascript
async function updateDocument(id: string, content: string, version: number) {
  'use server';
  // prevent last-writer-wins data loss when two users edit the same doc
}
AServer Actions handle concurrency automatically
BDisable concurrent editing in the UI
COptimistic concurrency control: carry a version field, and update only if the stored version still matches (in the same WHERE clause as the ownership check, as one atomic updateMany). If zero rows update, throw a conflict error and have the client refetch and retry
DOnly use SELECT FOR UPDATE row locks for every edit

How do you implement this in one Next.js app?

javascript
tenant-a.codejump.io  Tenant A's app
tenant-b.codejump.io → Tenant B's app
codejump.io           marketing site
AIn middleware, read the subdomain from the Host header, resolve the tenant, and NextResponse.rewrite() to a tenant-scoped internal path (e.g. /app/tenant-a/…) — or attach tenant data to request headers for layouts to read — while the browser URL stays on the subdomain
BCreate a separate Next.js app per tenant
CUse a separate Vercel project per tenant
DMulti-tenancy is not possible in one Next.js app

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.