dm: 콘텐츠 관련 refresh
This commit is contained in:
@@ -1,9 +1,26 @@
|
||||
export const dynamic = "force-dynamic";
|
||||
import { ContentsPage } from "@/components/ui/contents";
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { Button } from "@common/components/ui/button";
|
||||
|
||||
export default async function Contents() {
|
||||
const contsSn = 28;
|
||||
const menuCd = "24";
|
||||
/**
|
||||
* 'dm-content-detail' 태그를 가진 캐시 데이터를 즉시 무효화하는 서버 액션입니다.
|
||||
* 버튼 클릭 시 실행되며, 이후 이 태그를 사용하는 모든 페이지는 최신 데이터를 다시 가져옵니다.
|
||||
*/
|
||||
async function revalidateAction() {
|
||||
"use server";
|
||||
revalidateTag("dm-content-detail");
|
||||
console.log("Cache revalidated for tag: dm-content-detail");
|
||||
}
|
||||
|
||||
return <ContentsPage contsSn={contsSn} menuCd={menuCd} />;
|
||||
return (
|
||||
<div className="container mx-auto p-10">
|
||||
<div className="bg-white p-8 rounded-xl shadow-sm border border-gray-200 text-center">
|
||||
<h1 className="text-2xl font-bold mb-2">콘텐츠 관리 도구</h1>
|
||||
<p className="text-gray-500 mb-6">변경된 콘텐츠 내용을 즉시 반영하려면 아래 버튼을 클릭하세요.</p>
|
||||
<form action={revalidateAction}>
|
||||
<Button type="submit" className="px-8">캐시 즉시 갱신 (dm-content-detail)</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,24 @@ import { unstable_cache } from "next/cache";
|
||||
import { ENDPOINT } from "@/src/shared/config";
|
||||
|
||||
|
||||
function getServerBaseUrl() {
|
||||
const port = process.env.PORT ?? process.env.NEXT_PUBLIC_PORT ?? "3000";
|
||||
const proxyHost = process.env.NEXT_PUBLIC_PROXY_HOST;
|
||||
|
||||
if (process.env.NODE_ENV === "production" && process.env.HOSTNAME) {
|
||||
return `http://${process.env.HOSTNAME}:${port}`;
|
||||
}
|
||||
|
||||
return proxyHost || `http://localhost:${port}`;
|
||||
}
|
||||
|
||||
export const getCachedContentDetail = unstable_cache(
|
||||
async (contsSn: number, menuCd: string) => {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_PROXY_HOST || "http://localhost:3015";
|
||||
const baseUrl = getServerBaseUrl();
|
||||
const res = await fetch(
|
||||
`${baseUrl}${ENDPOINT.CMS_SERVICE.CONTENTS}/${contsSn}?menuCd=${menuCd}`,
|
||||
{
|
||||
next: { revalidate: 3600, tags: [`content:${contsSn}`] },
|
||||
next: { revalidate: 0, tags: [`content:${contsSn}`] },
|
||||
}
|
||||
);
|
||||
|
||||
@@ -23,4 +33,8 @@ export const getCachedContentDetail = unstable_cache(
|
||||
return res.json();
|
||||
},
|
||||
["dm-content-detail"],
|
||||
{
|
||||
revalidate: 86400, // 1시간마다 자동 갱신 (선택 사항)
|
||||
tags: ["dm-content-detail"], // 여기에 태그를 명시해야 revalidateTag가 작동합니다.
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user