Skip to content

Commit 63c6dd5

Browse files
authored
fix hallucination (#31)
1 parent 8cccab0 commit 63c6dd5

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

src/mcp-resources/nextjs-16-knowledge/02-public-caches.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
## <a id="public-cache"></a>4. Public Cache Mechanics
22

3-
### Pattern 1: File-Level 'use cache'
3+
### Pattern 1: Function-Level 'use cache'
44

55
```typescript
66
// Test Source: test/e2e/app-dir/use-cache/app/(partially-static)/cache-life/page.tsx
77

8-
'use cache'
98
import { cacheLife } from 'next/cache'
109

1110
async function getCachedRandom() {
@@ -23,6 +22,8 @@ export default async function Page() {
2322
// - Initial load: x = 0.12345
2423
// - Refresh: x = 0.12345 (SAME VALUE - cached!)
2524
// - Different arg: Different cache entry
25+
//
26+
// NOTE: 'use cache' is at FUNCTION level, not file level
2627
```
2728

2829
### Pattern 2: Component-Level 'use cache'

src/mcp-resources/nextjs-16-knowledge/07-cache-invalidation.md

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,41 +77,34 @@ export async function oldPattern() {
7777
**Test Source**: `test/e2e/app-dir/use-cache/app/(partially-static)/form/page.tsx`
7878

7979
```typescript
80-
'use cache'
81-
import { cacheLife, cacheTag } from 'next/cache'
80+
import { updateTag, cacheTag } from 'next/cache'
8281

83-
async function getTime() {
84-
'use cache'
85-
cacheTag('time')
86-
cacheLife('hours')
87-
return Date.now()
82+
async function refresh() {
83+
'use server'
84+
updateTag('home')
8885
}
8986

9087
export default async function Page() {
91-
const time = await getTime()
88+
'use cache'
89+
cacheTag('home')
9290

9391
return (
94-
<>
95-
<p id="t">{time}</p>
96-
<form action={async () => {
97-
'use server'
98-
await revalidateTag('time')
99-
refresh() // ← Refresh current page
100-
}}>
101-
<button id="refresh" type="submit">Refresh</button>
102-
</form>
103-
</>
92+
<form action={refresh}>
93+
<button id="refresh">Refresh</button>
94+
<p id="t">{new Date().toISOString()}</p>
95+
</form>
10496
)
10597
}
10698

107-
// TEST BEHAVIOR (lines 612-633):
108-
// 1. Initial load: time1 = 1234567890
109-
// 2. Reload page: time2 = 1234567890 (same, cached)
110-
// 3. Click refresh button:
111-
// - revalidateTag('time') called
112-
// - refresh() called
113-
// - Page updates in place
114-
// 4. Check time: time3 ≠ time2 (updated!)
99+
// ACTUAL TEST BEHAVIOR:
100+
// 1. Initial load: timestamp = "2024-01-01T12:00:00.000Z"
101+
// 2. Click refresh button:
102+
// - updateTag('home') called (invalidates cache)
103+
// - Page re-renders with new timestamp
104+
// 3. New timestamp displayed (cache was invalidated)
105+
//
106+
// NOTE: This uses updateTag(), not revalidateTag()
107+
// refresh() here is the server action name, not the next/cache function
115108
```
116109

117110
---

0 commit comments

Comments
 (0)