Next.js Discord

Discord Forum

NextJS 13 + Prisma | Caching doesn’t work properly

Unanswered
Mandarin fish posted this in #help-forum
Open in Discord
Mandarin fishOP
I am using NextJS 13 with Prisma as my ORM for a Postgresql database. My goal is to get some data w/ a Prisma query and not revalidate the request until 30 seconds have gone by. (I just want a little time for the data to stay stale before an additional revalidation is all)

To test this, I am basically just adding a new column in the database to see if it shows up on my website after 30 seconds, but after many refreshes, nothing happens.

Every time, after the project is built, Nextjs 13 doesn't revalidate the cache. I have also tried other methods like cache: { "no-store" } and NextJS 13 acts like it wants to ONLY be static with the cache. Very frustrating.

I wrote a very simple component to identify what I am trying to do.
__
events.tsx

import EventModifier from "./components/EventModifier";

export const revalidate = 30;

async function getEvents() {
const response = await fetch("http://127.0.0.1:3000/api/test", {
next: {
revalidate: 30,
},
});
return await response.json();
}

const ModifyEntertainmentPage = async () => {
const events = await getEvents();

return (
<div>
<EventModifier events={events.success} />
</div>
);
};

export default ModifyEntertainmentPage;
__


route.tsx

import { prisma } from "@/app/_library/prisma/config";
import { NextResponse } from "next/server";

export async function GET() {
const events = await prisma.testEvent.findMany();
return NextResponse.json({ success: events });
}

1 Reply

Great Knot
I’m here seeking for similar issue as yours.
I tried with ‘no-store’, ‘no-cache’, ‘revalidate’ but all didn’t work, the API call always HIT type and return cached from built.
Setting this in route.ts works:
export const dynamic = 'force-dynamic’
Change GET to POST also works.

But I still confuse why other way didn’t work as per documents mentioned. Following your question for insight.