Next.js Discord

Discord Forum

How to cache a DB query in Next JS 14

Answered
Eyebrowed Thrush posted this in #help-forum
Open in Discord
Eyebrowed ThrushOP
import { prisma } from "~/lib/prisma";

export default async function Page() {
const posts = await prisma.posts.findMany();
return <div>{posts.map........?.name}</div>;
}


how I can create cache in this. I mean user refreshes I doesn't want to make request to the db
I want it something like revalidation that we use in the fetch api in next js

The code is taken from the next js official website
In my case I am using this thing to fetch /show posts

2 Replies