NextJS 13 + Prisma | Cache will not revalidate nor will it cooperate at all.
Unanswered
Mandarin fish posted this in #help-forum
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 });
}
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 });
}