@trieb.work/nextjs-turbo-redis-cache 1.16.2 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +11 -2
- package/.github/workflows/release.yml +8 -157
- package/ARCHITECTURE.md +86 -47
- package/README.md +91 -25
- package/dist/index.d.mts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.js +264 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -7
- package/release.config.cjs +6 -25
- package/src/CacheComponentsHandler.ts +141 -111
- package/src/RedisStringsHandler.ts +37 -25
- package/src/SyncedMap.ts +16 -2
- package/src/index.ts +7 -0
- package/src/utils/cacheTtl.ts +71 -0
- package/src/utils/compareAndUnlink.ts +29 -0
- package/src/utils/redisConnection.ts +17 -0
- package/src/utils/tagRevalidation.ts +162 -0
- package/test/README.md +13 -13
- package/test/nextjs-test-projects/next-app-15-4-11/pnpm-lock.yaml +1 -1
- package/test/nextjs-test-projects/next-app-16-0-11/pnpm-lock.yaml +1 -1
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/next.config.ts +2 -0
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/pnpm-lock.yaml +1 -1
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/src/app/api/expire-matrix/revalidate/route.ts +34 -0
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/src/app/api/expire-matrix/route.ts +23 -0
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/src/app/cache-lab/page.tsx +22 -0
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/src/app/cache-lab/revalidate-durations/page.tsx +106 -0
- package/test/nextjs-test-projects/next-app-16-0-11-cache-components/src/app/cache-lab/use-cache-remote/page.tsx +85 -0
- package/test/nextjs-test-projects/next-app-16-2-6/pnpm-lock.yaml +1 -1
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/next.config.ts +2 -0
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/pnpm-lock.yaml +1 -1
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/api/expire-matrix/revalidate/route.ts +34 -0
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/api/expire-matrix/route.ts +23 -0
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/cache-lab/page.tsx +22 -0
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/cache-lab/revalidate-durations/page.tsx +106 -0
- package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/cache-lab/use-cache-remote/page.tsx +85 -0
- package/test/nextjs-test-projects/next-app-16-3-0/README.md +36 -0
- package/test/nextjs-test-projects/next-app-16-3-0/eslint.config.mjs +18 -0
- package/test/nextjs-test-projects/next-app-16-3-0/next.config.ts +7 -0
- package/test/nextjs-test-projects/next-app-16-3-0/package.json +28 -0
- package/test/nextjs-test-projects/next-app-16-3-0/pnpm-lock.yaml +4284 -0
- package/test/nextjs-test-projects/next-app-16-3-0/postcss.config.mjs +7 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/cached-static-fetch/route.ts +18 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/nested-fetch-in-api-route/revalidated-fetch/route.ts +27 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/revalidatePath/route.ts +15 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/revalidateTag/route.ts +20 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/revalidated-fetch/route.ts +17 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/api/uncached-fetch/route.ts +15 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/favicon.ico +0 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/globals.css +26 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/layout.tsx +59 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/page.tsx +755 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/cached-static-fetch/default--force-dynamic-page/page.tsx +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/cached-static-fetch/revalidate15--default-page/page.tsx +34 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/cached-static-fetch/revalidate15--force-dynamic-page/page.tsx +25 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/no-fetch/default-page/page.tsx +55 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/revalidated-fetch/default--force-dynamic-page/page.tsx +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/revalidated-fetch/revalidate15--default-page/page.tsx +35 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/revalidated-fetch/revalidate15--force-dynamic-page/page.tsx +25 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/uncached-fetch/default--force-dynamic-page/page.tsx +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/uncached-fetch/revalidate15--default-page/page.tsx +32 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/pages/uncached-fetch/revalidate15--force-dynamic-page/page.tsx +25 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/revalidation-interface.tsx +267 -0
- package/test/nextjs-test-projects/next-app-16-3-0/src/app/update-tag-test/page.tsx +25 -0
- package/test/nextjs-test-projects/next-app-16-3-0/tsconfig.json +34 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/README.md +36 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/cache-handler.js +3 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/eslint.config.mjs +18 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/next.config.ts +15 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/package.json +28 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/pnpm-lock.yaml +4284 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/postcss.config.mjs +7 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/public/file.svg +1 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/public/globe.svg +1 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/public/next.svg +1 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/public/vercel.svg +1 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/public/window.svg +1 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/cached-static-fetch/route.ts +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/cached-with-cachelife/route.ts +24 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/cached-with-tag/route.ts +21 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/expire-matrix/revalidate/route.ts +34 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/expire-matrix/route.ts +23 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/revalidate-tag/route.ts +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/api/revalidated-fetch/route.ts +19 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/cachelife-short/page.tsx +110 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/page.tsx +112 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/revalidate-durations/page.tsx +106 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/runtime-data-suspense/page.tsx +127 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/stale-while-revalidate/page.tsx +130 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/tag-invalidation/page.tsx +127 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/use-cache-nondeterministic/page.tsx +110 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/cache-lab/use-cache-remote/page.tsx +85 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/favicon.ico +0 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/globals.css +26 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/layout.tsx +57 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/page.tsx +755 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/revalidation-interface.tsx +267 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/src/app/update-tag-test/page.tsx +22 -0
- package/test/nextjs-test-projects/next-app-16-3-0-cache-components/tsconfig.json +34 -0
- package/test/nextjs-test-projects/next-pages-16-2-6/pnpm-lock.yaml +4 -4
- package/test/nextjs-test-projects/next-pages-16-3-0/README.md +16 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/eslint.config.mjs +18 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/next.config.ts +7 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/package.json +26 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/pnpm-lock.yaml +3939 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/src/pages/api/revalidate.ts +24 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/src/pages/index.tsx +11 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/src/pages/isr/[slug].tsx +49 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/src/pages/static-forever.tsx +20 -0
- package/test/nextjs-test-projects/next-pages-16-3-0/tsconfig.json +34 -0
- package/test/playwright/cache-lab.spec.ts +75 -0
- package/test/vitest/integration/cache-components/cache-components.integration.test.ts +194 -36
- package/test/vitest/integration/nextjs-cache-handler.integration.test.ts +67 -34
- package/test/vitest/integration/pages-router.integration.test.ts +16 -6
- package/test/vitest/unit/SyncedMap-orphan-cleanup.test.ts +111 -0
- package/test/vitest/unit/cache-components-update-tags.test.ts +350 -0
- package/test/vitest/unit/cache-ttl.test.ts +67 -0
- package/test/vitest/unit/compare-and-unlink.test.ts +22 -0
- package/test/vitest/unit/index.test.ts +17 -0
- package/test/vitest/unit/pages-router-kinds.test.ts +11 -0
- package/test/vitest/unit/redis-connection.test.ts +39 -0
- package/test/vitest/unit/tag-revalidation.test.ts +178 -0
- package/CHANGELOG.md +0 -404
|
@@ -561,7 +561,7 @@ packages:
|
|
|
561
561
|
'@trieb.work/nextjs-turbo-redis-cache@file:../../..':
|
|
562
562
|
resolution: {directory: ../../.., type: directory}
|
|
563
563
|
peerDependencies:
|
|
564
|
-
next: '>=15.0.3 <
|
|
564
|
+
next: '>=15.0.3 <17.0.0'
|
|
565
565
|
redis: 4.7.0
|
|
566
566
|
|
|
567
567
|
'@tybys/wasm-util@0.10.1':
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { revalidateTag } from 'next/cache';
|
|
3
|
+
|
|
4
|
+
type Profile =
|
|
5
|
+
| 'max'
|
|
6
|
+
| 'default'
|
|
7
|
+
| 'seconds'
|
|
8
|
+
| 'minutes'
|
|
9
|
+
| 'hours'
|
|
10
|
+
| 'days'
|
|
11
|
+
| 'weeks'
|
|
12
|
+
| { expire: number };
|
|
13
|
+
|
|
14
|
+
export async function POST(request: Request) {
|
|
15
|
+
const body = (await request.json()) as {
|
|
16
|
+
tag?: string;
|
|
17
|
+
profile?: Profile | null;
|
|
18
|
+
};
|
|
19
|
+
const tag = body.tag || 'expire-matrix-default';
|
|
20
|
+
|
|
21
|
+
if (body.profile === undefined || body.profile === null) {
|
|
22
|
+
// Deprecated single-arg form: Next.js calls updateTags(tags) with no durations.
|
|
23
|
+
(revalidateTag as (tag: string) => void)(tag);
|
|
24
|
+
} else {
|
|
25
|
+
revalidateTag(tag, body.profile);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return NextResponse.json({
|
|
29
|
+
revalidated: true,
|
|
30
|
+
tag,
|
|
31
|
+
profile: body.profile ?? null,
|
|
32
|
+
timestamp: Date.now(),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { cacheLife, cacheTag } from 'next/cache';
|
|
3
|
+
|
|
4
|
+
let counter = 0;
|
|
5
|
+
|
|
6
|
+
export async function GET(request: Request) {
|
|
7
|
+
const id = new URL(request.url).searchParams.get('id') || 'default';
|
|
8
|
+
const data = await getExpireMatrixData(id);
|
|
9
|
+
return NextResponse.json({ ...data, id });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function getExpireMatrixData(id: string) {
|
|
13
|
+
'use cache';
|
|
14
|
+
// Long time-based lifetime so only tag invalidation can change the value.
|
|
15
|
+
cacheLife({ stale: 300, revalidate: 3600, expire: 86_400 });
|
|
16
|
+
cacheTag(`expire-matrix-${id}`);
|
|
17
|
+
|
|
18
|
+
counter += 1;
|
|
19
|
+
return {
|
|
20
|
+
counter,
|
|
21
|
+
timestamp: Date.now(),
|
|
22
|
+
};
|
|
23
|
+
}
|
package/test/nextjs-test-projects/next-app-16-2-6-cache-components/src/app/cache-lab/page.tsx
CHANGED
|
@@ -70,6 +70,28 @@ export default function CacheLabIndexPage() {
|
|
|
70
70
|
it into a cached component to show correct boundaries.
|
|
71
71
|
</p>
|
|
72
72
|
</Link>
|
|
73
|
+
|
|
74
|
+
<Link
|
|
75
|
+
className="rounded-lg border p-5 hover:bg-slate-50"
|
|
76
|
+
href="/cache-lab/use-cache-remote"
|
|
77
|
+
>
|
|
78
|
+
<h2 className="text-lg font-medium">use cache: remote</h2>
|
|
79
|
+
<p className="mt-1 text-sm text-slate-600">
|
|
80
|
+
Exercises <code>cacheHandlers.remote</code> with Redis-backed
|
|
81
|
+
streams and <code>updateTag</code>.
|
|
82
|
+
</p>
|
|
83
|
+
</Link>
|
|
84
|
+
|
|
85
|
+
<Link
|
|
86
|
+
className="rounded-lg border p-5 hover:bg-slate-50"
|
|
87
|
+
href="/cache-lab/revalidate-durations"
|
|
88
|
+
>
|
|
89
|
+
<h2 className="text-lg font-medium">revalidateTag durations</h2>
|
|
90
|
+
<p className="mt-1 text-sm text-slate-600">
|
|
91
|
+
Deferred tag invalidation via{' '}
|
|
92
|
+
<code>revalidateTag(tag, {'{ expire }'})</code> and SWR behavior.
|
|
93
|
+
</p>
|
|
94
|
+
</Link>
|
|
73
95
|
</section>
|
|
74
96
|
|
|
75
97
|
<section className="mt-12 rounded-lg border bg-slate-50 p-5">
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import Link from 'next/link';
|
|
2
|
+
import { Suspense } from 'react';
|
|
3
|
+
import { cacheLife, cacheTag, revalidateTag } from 'next/cache';
|
|
4
|
+
|
|
5
|
+
function sleep(ms: number): Promise<void> {
|
|
6
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function getSlowTaggedValue() {
|
|
10
|
+
'use cache';
|
|
11
|
+
|
|
12
|
+
cacheLife({ stale: 60, revalidate: 120, expire: 300 });
|
|
13
|
+
cacheTag('cache-lab:durations');
|
|
14
|
+
|
|
15
|
+
await sleep(2500);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
computedAt: Date.now(),
|
|
19
|
+
value: Math.random(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function triggerDeferredRevalidateTag() {
|
|
24
|
+
'use server';
|
|
25
|
+
revalidateTag('cache-lab:durations', { expire: 2 });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function CachedPanel() {
|
|
29
|
+
const data = await getSlowTaggedValue();
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="rounded-lg border p-5">
|
|
33
|
+
<div className="text-sm text-slate-700">
|
|
34
|
+
<div>
|
|
35
|
+
<span className="font-medium">computedAt:</span>{' '}
|
|
36
|
+
<span data-testid="computedAt" className="font-mono">
|
|
37
|
+
{data.computedAt}
|
|
38
|
+
</span>
|
|
39
|
+
</div>
|
|
40
|
+
<div className="mt-1">
|
|
41
|
+
<span className="font-medium">value:</span>{' '}
|
|
42
|
+
<span data-testid="value" className="font-mono">
|
|
43
|
+
{data.value}
|
|
44
|
+
</span>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default function RevalidateDurationsPage() {
|
|
52
|
+
return (
|
|
53
|
+
<main className="mx-auto max-w-3xl p-10">
|
|
54
|
+
<div className="mb-6">
|
|
55
|
+
<Link
|
|
56
|
+
className="text-sm text-blue-600 hover:underline"
|
|
57
|
+
href="/cache-lab"
|
|
58
|
+
>
|
|
59
|
+
← Back to Cache Lab
|
|
60
|
+
</Link>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<header className="mb-6">
|
|
64
|
+
<h1 className="text-2xl font-semibold">
|
|
65
|
+
revalidateTag durations (SWR stale window)
|
|
66
|
+
</h1>
|
|
67
|
+
<p className="mt-2 text-sm text-slate-600">
|
|
68
|
+
Calls <code>revalidateTag(tag, {'{ expire: 2 }'})</code>. The handler
|
|
69
|
+
should mark the tag stale immediately while keeping the Redis entry so
|
|
70
|
+
the next request can serve stale content (SWR) during refresh.
|
|
71
|
+
</p>
|
|
72
|
+
</header>
|
|
73
|
+
|
|
74
|
+
<Suspense
|
|
75
|
+
fallback={
|
|
76
|
+
<div className="rounded-lg border bg-slate-50 p-5 text-sm text-slate-700">
|
|
77
|
+
Loading cached content… (first load can take ~2.5s)
|
|
78
|
+
</div>
|
|
79
|
+
}
|
|
80
|
+
>
|
|
81
|
+
<CachedPanel />
|
|
82
|
+
</Suspense>
|
|
83
|
+
|
|
84
|
+
<form action={triggerDeferredRevalidateTag} className="mt-6">
|
|
85
|
+
<button
|
|
86
|
+
className="rounded-md border border-blue-600 bg-white px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-50"
|
|
87
|
+
type="submit"
|
|
88
|
+
>
|
|
89
|
+
revalidateTag('cache-lab:durations', {'{ expire: 2 }'})
|
|
90
|
+
</button>
|
|
91
|
+
</form>
|
|
92
|
+
|
|
93
|
+
<div className="mt-6 rounded-lg border bg-slate-50 p-5 text-sm text-slate-700">
|
|
94
|
+
<p className="font-medium">How to observe SWR invalidation</p>
|
|
95
|
+
<ol className="mt-2 list-decimal space-y-1 pl-5">
|
|
96
|
+
<li>Load once (expect ~2.5s).</li>
|
|
97
|
+
<li>Click the button, then reload immediately.</li>
|
|
98
|
+
<li>
|
|
99
|
+
The reload should still show the old values (fast SWR). After
|
|
100
|
+
background refresh (~2.5s), values should change.
|
|
101
|
+
</li>
|
|
102
|
+
</ol>
|
|
103
|
+
</div>
|
|
104
|
+
</main>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Link from 'next/link';
|
|
2
|
+
import { Suspense } from 'react';
|
|
3
|
+
import { cacheTag, updateTag } from 'next/cache';
|
|
4
|
+
|
|
5
|
+
async function getRemoteCachedValue() {
|
|
6
|
+
'use cache: remote';
|
|
7
|
+
|
|
8
|
+
cacheTag('cache-lab:remote');
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
value: Math.random(),
|
|
12
|
+
computedAt: Date.now(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function triggerUpdateTag() {
|
|
17
|
+
'use server';
|
|
18
|
+
updateTag('cache-lab:remote');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function RemotePanel() {
|
|
22
|
+
const data = await getRemoteCachedValue();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className="rounded-lg border p-5">
|
|
26
|
+
<div className="text-sm text-slate-700">
|
|
27
|
+
<div>
|
|
28
|
+
<span className="font-medium">computedAt:</span>{' '}
|
|
29
|
+
<span data-testid="computedAt" className="font-mono">
|
|
30
|
+
{data.computedAt}
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
33
|
+
<div className="mt-1">
|
|
34
|
+
<span className="font-medium">value:</span>{' '}
|
|
35
|
+
<span data-testid="value" className="font-mono">
|
|
36
|
+
{data.value}
|
|
37
|
+
</span>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default function UseCacheRemotePage() {
|
|
45
|
+
return (
|
|
46
|
+
<main className="mx-auto max-w-3xl p-10">
|
|
47
|
+
<div className="mb-6">
|
|
48
|
+
<Link
|
|
49
|
+
className="text-sm text-blue-600 hover:underline"
|
|
50
|
+
href="/cache-lab"
|
|
51
|
+
>
|
|
52
|
+
← Back to Cache Lab
|
|
53
|
+
</Link>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<header className="mb-6">
|
|
57
|
+
<h1 className="text-2xl font-semibold">use cache: remote</h1>
|
|
58
|
+
<p className="mt-2 text-sm text-slate-600">
|
|
59
|
+
Exercises the <code>cacheHandlers.remote</code> handler backed by
|
|
60
|
+
Redis. Values should stay stable across reloads until{' '}
|
|
61
|
+
<code>updateTag</code> runs.
|
|
62
|
+
</p>
|
|
63
|
+
</header>
|
|
64
|
+
|
|
65
|
+
<Suspense
|
|
66
|
+
fallback={
|
|
67
|
+
<div className="rounded-lg border bg-slate-50 p-5 text-sm text-slate-700">
|
|
68
|
+
Loading remote cached content…
|
|
69
|
+
</div>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<RemotePanel />
|
|
73
|
+
</Suspense>
|
|
74
|
+
|
|
75
|
+
<form action={triggerUpdateTag} className="mt-6">
|
|
76
|
+
<button
|
|
77
|
+
className="rounded-md border border-blue-600 bg-white px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-50"
|
|
78
|
+
type="submit"
|
|
79
|
+
>
|
|
80
|
+
updateTag('cache-lab:remote')
|
|
81
|
+
</button>
|
|
82
|
+
</form>
|
|
83
|
+
</main>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
First, run the development server:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
# or
|
|
10
|
+
yarn dev
|
|
11
|
+
# or
|
|
12
|
+
pnpm dev
|
|
13
|
+
# or
|
|
14
|
+
bun dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
+
|
|
19
|
+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
|
20
|
+
|
|
21
|
+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
|
22
|
+
|
|
23
|
+
## Learn More
|
|
24
|
+
|
|
25
|
+
To learn more about Next.js, take a look at the following resources:
|
|
26
|
+
|
|
27
|
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
28
|
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
29
|
+
|
|
30
|
+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
|
31
|
+
|
|
32
|
+
## Deploy on Vercel
|
|
33
|
+
|
|
34
|
+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
35
|
+
|
|
36
|
+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import nextVitals from "eslint-config-next/core-web-vitals";
|
|
3
|
+
import nextTs from "eslint-config-next/typescript";
|
|
4
|
+
|
|
5
|
+
const eslintConfig = defineConfig([
|
|
6
|
+
...nextVitals,
|
|
7
|
+
...nextTs,
|
|
8
|
+
// Override default ignores of eslint-config-next.
|
|
9
|
+
globalIgnores([
|
|
10
|
+
// Default ignores of eslint-config-next:
|
|
11
|
+
".next/**",
|
|
12
|
+
"out/**",
|
|
13
|
+
"build/**",
|
|
14
|
+
"next-env.d.ts",
|
|
15
|
+
]),
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export default eslintConfig;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "next-app-16-3-0",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start",
|
|
9
|
+
"lint": "eslint"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"next": "16.3.0",
|
|
13
|
+
"react": "19.2.0",
|
|
14
|
+
"react-dom": "19.2.0",
|
|
15
|
+
"redis": "4.7.0",
|
|
16
|
+
"@trieb.work/nextjs-turbo-redis-cache": "file:../../../"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tailwindcss/postcss": "^4",
|
|
20
|
+
"@types/node": "^20",
|
|
21
|
+
"@types/react": "^19",
|
|
22
|
+
"@types/react-dom": "^19",
|
|
23
|
+
"eslint": "^9",
|
|
24
|
+
"eslint-config-next": "16.3.0",
|
|
25
|
+
"tailwindcss": "^4",
|
|
26
|
+
"typescript": "^5"
|
|
27
|
+
}
|
|
28
|
+
}
|