nextjs - 💡(How to fix) Fix use cache: private not working [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87304Fetched 2026-04-08 02:07:21
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
commented ×2closed ×1issue_type_added ×1labeled ×1

Root Cause

I created a new issue because the previous one isn't being assigned and I haven't seen an update since the original issue was uploaded. (Issue #85672)

Code Example

// lib/user.ts
import { cookies } from "next/headers";
import { cacheTag, cacheLife } from "next/cache";

export async function getUser() {
    "use cache: private";
    cacheTag(`userdata`);
    cacheLife({ stale: 30 });
    
    const sessionId = (await cookies()).get('session-id')?.value || 'guest'
    
    console.log("Fetching user data"); // This logs on every navigation
    await new Promise((resolve) => setTimeout(resolve, 5000));
    const timestamp = new Date().toISOString();

    return {
        user: {
            name: "Ajay",
            email: "[email protected]"
        },
        timestamp: timestamp,
    }
}

---

// app/about/page.tsx
import { Suspense } from "react";
import { getUser } from "../../lib/user";

export default async function Page() {
  return (
    <div>
      <h1>About Page</h1>
      <Suspense fallback={<p>Loading...</p>}>
        <Content />
      </Suspense>
    </div>
  );
}

async function Content() {
  const data = await getUser();
  return (
    <div>
      <h1>{data.user.name}</h1>
      <p>Fetched at: {data.timestamp}</p>
    </div>
  );
}

---

// next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  cacheComponents: true,
};

export default nextConfig;

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132
  Available memory (MB): 24576
  Available CPU cores: 10
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.0.2-canary.3 // Latest available version is detected (16.0.2-canary.3).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/ajaykarthikr/next-16-use-cache-private-bug

To Reproduce

I created a new issue because the previous one isn't being assigned and I haven't seen an update since the original issue was uploaded. (Issue #85672)

Link to the code that reproduces this issue https://github.com/ajaykarthikr/next-16-use-cache-private-bug

To Reproduce

  1. Create a cached function with "use cache: private" that uses cookies():
// lib/user.ts
import { cookies } from "next/headers";
import { cacheTag, cacheLife } from "next/cache";

export async function getUser() {
    "use cache: private";
    cacheTag(`userdata`);
    cacheLife({ stale: 30 });
    
    const sessionId = (await cookies()).get('session-id')?.value || 'guest'
    
    console.log("Fetching user data"); // This logs on every navigation
    await new Promise((resolve) => setTimeout(resolve, 5000));
    const timestamp = new Date().toISOString();

    return {
        user: {
            name: "Ajay",
            email: "[email protected]"
        },
        timestamp: timestamp,
    }
}
  1. Use this function in a Server Component page:
// app/about/page.tsx
import { Suspense } from "react";
import { getUser } from "../../lib/user";

export default async function Page() {
  return (
    <div>
      <h1>About Page</h1>
      <Suspense fallback={<p>Loading...</p>}>
        <Content />
      </Suspense>
    </div>
  );
}

async function Content() {
  const data = await getUser();
  return (
    <div>
      <h1>{data.user.name}</h1>
      <p>Fetched at: {data.timestamp}</p>
    </div>
  );
}
  1. Configure next.config.ts:
// next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  cacheComponents: true,
};

export default nextConfig;
  1. Navigate to the page (e.g., /about), then navigate away, then navigate back using client-side navigation (e.g. <Link />).

Current vs. Expected behavior

Expected: The cached function should return the cached result during the 30-second stale period, showing the same timestamp and not logging "Fetching user data" on subsequent navigations.

Actual: The function re-executes on every client-side navigation, showing a new timestamp each time and logging "Fetching user data" in the console.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132
  Available memory (MB): 24576
  Available CPU cores: 10
Binaries:
  Node: 22.20.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.0.2-canary.3 // Latest available version is detected (16.0.2-canary.3).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply) Use Cache

Which stage(s) are affected? (Select all that apply) next start (local), Vercel (Deployed)

Additional context The "use cache: private" directive is supposed to work with cookies() API according to the documentation This appears to be related to Router Cache interaction with function-level caching during client-side navigation The 2-second artificial delay in the reproduction makes it easy to observe when the function re-executes

extent analysis

TL;DR

The issue can be addressed by investigating the interaction between Router Cache and function-level caching during client-side navigation, potentially requiring adjustments to caching directives or navigation handling.

Guidance

  • Review the documentation for use cache: private and cookies() API to ensure correct usage and compatibility with Next.js version 16.0.2-canary.3.
  • Investigate the Router Cache interaction with function-level caching during client-side navigation to identify potential conflicts or misconfigurations.
  • Consider adding logging or debugging statements to track cache hits and misses, as well as function re-executions, to better understand the caching behavior.
  • Evaluate the possibility of using a different caching strategy or directive, such as use cache: public, to see if it resolves the issue.

Example

No code example is provided as the issue requires further investigation into the caching behavior and potential misconfigurations.

Notes

The issue appears to be related to the interaction between Router Cache and function-level caching, which may be specific to Next.js version 16.0.2-canary.3. Further investigation and testing are required to determine the root cause and appropriate solution.

Recommendation

Apply workaround: Investigate and adjust caching directives or navigation handling to resolve the conflict between Router Cache and function-level caching. This approach allows for a targeted solution without relying on potential fixes in future versions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING