new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Next.js · API reference · all subjects

directives/use-cache-private

14 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

deploymentId impact on cache keys

The deploymentId is included in the 'use cache' cache key. When the deployment ID changes, cache entries are invalidated.

'use cache: private' directive overview

The 'use cache: private' directive allows functions to access runtime request APIs like cookies(), headers(), and searchParams within a cached scope. Results are never stored on the server; they are cached only in the browser's memory and do not persist across page reloads.

When to use 'use cache: private'

Use 'use cache: private' when you want to cache a function that already accesses runtime data and refactoring to move the runtime access outside is not practical, or when compliance requirements prevent storing certain data on the server, even temporarily.

'use cache: private' execution behavior

Because 'use cache: private' accesses runtime data, the function executes on every server render and is excluded from running during static shell generation.

'use cache: private' does not support custom cache handlers

It is not possible to configure custom cache handlers for 'use cache: private'.

Enable 'use cache: private' with cacheComponents config

To use 'use cache: private', enable the cacheComponents flag in next.config.ts or next.config.js with cacheComponents: true.

'use cache: private' not available in Route Handlers

The 'use cache: private' directive is not available in Route Handlers.

Request APIs allowed in 'use cache: private'

The following request-specific APIs can be used inside 'use cache: private' functions: cookies() (Yes), headers() (Yes), searchParams (Yes), connection() (No). The connection() API is prohibited in both 'use cache' and 'use cache: private' as it provides connection-specific information that cannot be safely cached.

Request APIs allowed in 'use cache' (non-private) for comparison

The following request-specific APIs are not allowed in standard 'use cache': cookies() (No), headers() (No), searchParams (No), connection() (No).

'use cache: private' basic example with cookies

Example showing 'use cache: private' in action: An async function getRecommendations accesses cookies using 'use cache: private', sets a cacheTag with cacheTag(`recommendations-${productId}`), and configures cache lifetime with cacheLife({ stale: 60 }). The function retrieves the session-id cookie and passes it to getPersonalizedRecommendations().

cacheLife stale time requirements for 'use cache: private'

The stale time must be at least 30 seconds for per-link prefetching to work, and at least 5 minutes for the content to be included in the route's App Shell.

'use cache: private' version history

'use cache: private' was enabled with the Cache Components feature in v16.0.0.

use cache: private reads cookies and headers

The 'use cache: private' directive allows functions to read cookies() and headers() directly while keeping results in the browser only, never cached on the server. It accepts cookies(), headers(), and searchParams, but not connection().

Private cache scope never caches on server

A scope marked with 'use cache: private' stays in the browser only and never caches on the server. To cache on the server instead, extract a value like userId and pass it into a plain 'use cache' or 'use cache: remote' function.

Give your agent this brain