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().