Clarification NextJS Caching Revalidation

Hi! i have the function:
const getData = unstable_cache(
async () => {
const usersData = await db.select().from(users);
return { users: usersData };
},
["users"],
{
revalidate: false
},
);

export default async function Page() {
const data = await getData();

return (
<main className="container mx-auto p-4">
<h1 className="mb-6 text-3xl font-bold">User and Course Management</h1>
<CreateCoursePopup />
<UsersTable users={data.users} />
</main>
);
}
const getData = unstable_cache(
async () => {
const usersData = await db.select().from(users);
return { users: usersData };
},
["users"],
{
revalidate: false
},
);

export default async function Page() {
const data = await getData();

return (
<main className="container mx-auto p-4">
<h1 className="mb-6 text-3xl font-bold">User and Course Management</h1>
<CreateCoursePopup />
<UsersTable users={data.users} />
</main>
);
}
and I have the update function:
"use server";

import { adminAction } from "@/server/api/actions";
import { updateUserInput } from "@/validators/users";
import { revalidatePath, revalidateTag } from "next/cache";
import { users } from "@/server/db/schema";
import { db } from "@/server/db";
import { eq } from "drizzle-orm";
import { z } from "zod";

export const updateUserAction = adminAction
.schema(updateUserInput)
.action(async ({ parsedInput }) => {
await db.update(users).set(parsedInput).where(eq(users.id, parsedInput.id));
revalidateTag("users");
});

export const deleteUserAction = adminAction
.schema(z.object({ id: z.string() }))
.action(async ({ parsedInput }) => {
await db.delete(users).where(eq(users.id, parsedInput.id));
revalidateTag("users");
});
"use server";

import { adminAction } from "@/server/api/actions";
import { updateUserInput } from "@/validators/users";
import { revalidatePath, revalidateTag } from "next/cache";
import { users } from "@/server/db/schema";
import { db } from "@/server/db";
import { eq } from "drizzle-orm";
import { z } from "zod";

export const updateUserAction = adminAction
.schema(updateUserInput)
.action(async ({ parsedInput }) => {
await db.update(users).set(parsedInput).where(eq(users.id, parsedInput.id));
revalidateTag("users");
});

export const deleteUserAction = adminAction
.schema(z.object({ id: z.string() }))
.action(async ({ parsedInput }) => {
await db.delete(users).where(eq(users.id, parsedInput.id));
revalidateTag("users");
});
and the data on the page is not revalidatnig when I call the functions, I've tried revalidatePath, same issue. I know the function works because when I Crtl + Shift + R the data is correct. Any insights into why?
4 Replies
Ani
AniOP4mo ago
nextjs 15 and also the page is showing a static icon even tho the page is clearly dynamic what am i missing? i'm also router.refresh() ing and it doesn't work same on build and dev with and without turbopack
Benfa
Benfa2w ago
have you find out why? i'm having a similar problem
Ani
AniOP2w ago
because giving unstable cache a key isn't the same as tagging it
const getData = unstable_cache(
async () => {
const usersData = await db.select().from(users);
return { users: usersData };
},
["users"],
{
revalidate: false,
tags: ["users"], // add this line here
},
);
const getData = unstable_cache(
async () => {
const usersData = await db.select().from(users);
return { users: usersData };
},
["users"],
{
revalidate: false,
tags: ["users"], // add this line here
},
);
you'd do something like that it isn't intutive at all but I guess dynamic IO should fix that problem
Benfa
Benfa2w ago
it sill doesn't work for me, i eneded up exporting dynamic = "force-dynamic"

Did you find this page helpful?