Is it even possible to use 'use cache' in a dynamic route segment?
Unanswered
Barbary Lion posted this in #help-forum
Barbary LionOP
Whenever I try to use 'use cache' in my products/[id]/page.tsx,
I get an error that looks like this:
Here is the code, it's super simple. Happens whether or not I generateStaticParams.
I imagine this has something to do with the prerender not having access to params..
I get an error that looks like this:
Error while saving cache key: 1:07b:["Q3q5ylEKRQOizGVF--YrQ","c08d79aa5ec384bebec6fb78b6f88bd7b51df235bd",[{"params":"$@1","searchParams":"$@2"},"$undefined"]] Error: Connection closed.
at h (.next/server/chunks/118.js:1:7947)
at R (.next/server/chunks/118.js:1:6910)
at v (.next/server/chunks/118.js:1:6162)
Error occurred prerendering page "/products/[id]". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Connection closed.Here is the code, it's super simple. Happens whether or not I generateStaticParams.
'use cache';
export async function generateStaticParams() {
await new Promise((resolve) => setTimeout(resolve, 1000));
return [{ id: '1' }, { id: '2' }, { id: '3' }];
}
export default async function Page({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
return <div className="">{id}</div>;
}I imagine this has something to do with the prerender not having access to params..
2 Replies
Not sure you're supposed to put "use cache" at the very top of your file, it needs to go inside the function you wanna cache
If everything is cacheable the page end up beng cached as well, I think i read that somewhere