Cache data from DB at build time for dynamic page
Unanswered
Milkfish posted this in #help-forum
MilkfishOP
I would like to cache data at build time in a dynamic page.
My page is dynamic because it needs to react to changing URL search params.
The data I want to cache is fetched via Prisma. I wrap the functions in React's
The page uses these cached data fetches.
The data is always the same, no matter the URL search params (they're used for filtering, not data fetching).
Is it possible to fetch the data at build time, cache it, but still have a dynamic page that reacts to URL search param changes?
I tried these in the page, but they don't have the effect I was expecting:
With this setup, the page still executes the DB call (
My page is dynamic because it needs to react to changing URL search params.
The data I want to cache is fetched via Prisma. I wrap the functions in React's
cache. For example:export const findPosts = cache(async () => {
return await prisma.post.findMany()
})The page uses these cached data fetches.
The data is always the same, no matter the URL search params (they're used for filtering, not data fetching).
Is it possible to fetch the data at build time, cache it, but still have a dynamic page that reacts to URL search param changes?
I tried these in the page, but they don't have the effect I was expecting:
export const dynamic = "force-dynamic"
export const revalidate = "force-cache"With this setup, the page still executes the DB call (
findPosts) at runtime.