Nextjs Fundamentals · Caching & Revalidation

Refreshing uncached data

refresh()

Refreshing uncached data

Not all data on a page is cached. A notification count, a live metric, a status indicator — these are fetched uncached and shown alongside cached shells and static content. After a Server Action changes one of them, the page still needs to re-render. refresh is the new Server Actions-only API in Next.js 16 that does exactly that.

'use server';

import { refresh } from 'next/cache';

export async function markNotificationAsRead(notificationId: string) {
  await db.notifications.markAsRead(notificationId);
  // Refresh the uncached notification count in the header
  refresh();
}

refresh touches no cache at all — it re-renders the route so that uncached data is fetched again. That is the difference from revalidateTag and updateTag, which both invalidate cached entries. It is the server-side complement to the client-side router.refresh(): use it when an action must refresh dynamic data displayed elsewhere on the page, while the cached page shells and static content stay fast. Cached content is not re-fetched, so the update is cheap.

You are about to answer a short quiz on refresh().

  1. refresh() refreshes uncached data only and does not touch the cache.
  2. refresh() is a Server ___-only API.
  3. refresh() is the server-side complement to the client-side router.refresh().
  4. Calling refresh() invalidates cached entries carrying a tag.
  5. A good use of refresh() is updating a notification ___ displayed in the header.
  6. After refresh(), cached page shells and static content stay fast while uncached data re-fetches.