From e0ba56659f01ceddc42f8b878c78c19323c50ced Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Sun, 19 Jan 2025 01:36:59 -0500 Subject: [PATCH] Finished Adding Chacing --- actions/update-board/index.ts | 3 ++- .../(dashboard)/board/[boardId]/layout.tsx | 23 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/actions/update-board/index.ts b/actions/update-board/index.ts index 7220098..3a0d4c9 100644 --- a/actions/update-board/index.ts +++ b/actions/update-board/index.ts @@ -1,7 +1,7 @@ 'use server'; import { auth } from '@clerk/nextjs/server'; -import { revalidatePath } from 'next/cache'; +import { revalidatePath, revalidateTag } from 'next/cache'; import { ACTION, ENTITY_TYPE } from '@prisma/client'; import { db } from '@/lib/db'; @@ -74,6 +74,7 @@ const handler = async (data: InputType): Promise => { }; } + revalidateTag(`board-${id}`); revalidatePath(`/board/${id}`); return { data: board }; }; diff --git a/app/(platform)/(dashboard)/board/[boardId]/layout.tsx b/app/(platform)/(dashboard)/board/[boardId]/layout.tsx index 96d6c20..cd7b803 100644 --- a/app/(platform)/(dashboard)/board/[boardId]/layout.tsx +++ b/app/(platform)/(dashboard)/board/[boardId]/layout.tsx @@ -4,6 +4,7 @@ import { notFound, redirect } from 'next/navigation'; import { db } from '@/lib/db'; import { BoardNavbar } from './_components/board-navbar'; import { BoardLiveblocks } from './_components/board-liveblocks'; +import { unstable_cache } from 'next/cache'; export async function generateMetadata(props: { params: Promise<{ boardId: string }>; @@ -37,13 +38,23 @@ const BoardIdLayout = async (props: { if (!orgId) redirect('/select-org'); - const board = await db.board.findUnique({ - where: { - id: params.boardId, - orgId, + const getBoard = unstable_cache( + async () => { + return await db.board.findUnique({ + where: { + id: params.boardId, + orgId, + }, + }); }, - cacheStrategy: { ttl: 30, swr: 60 }, - }); + [`board-${params.boardId}`], + { + tags: [`board-${params.boardId}`], + revalidate: false, + } + ); + + const board = await getBoard(); if (!board) notFound();