import Link from 'next/link'; import { cacheTag, updateTag } from 'next/cache'; async function getCachedNonDeterministicValues() { 'use cache'; cacheTag('cache-lab:nondet'); const random1 = Math.random(); const random2 = Math.random(); const now = Date.now(); const uuid = crypto.randomUUID(); const bytes = crypto.getRandomValues(new Uint8Array(8)); return { random1, random2, now, uuid, bytes: Array.from(bytes), }; } async function refresh() { 'use server'; updateTag('cache-lab:nondet'); } export default async function UseCacheNonDeterministicPage() { const data = await getCachedNonDeterministicValues(); return (
← Back to Cache Lab

use cache: non-deterministic

Per docs, non-deterministic operations inside a use cache{' '} scope run once and then stay stable for all requests until you invalidate.

random1
{data.random1}
random2
{data.random2}
now (Date.now)
{data.now}
uuid
{data.uuid}
bytes
{JSON.stringify(data.bytes)}

Expected: Reloading the page should keep values identical across requests.

Click the button (Server Action) to run updateTag and refresh the cached entry.

); }