Files
gunshiz 9580407a90
CI / Verify (push) Successful in 1m56s
CI / Build immutable images and deploy (push) Successful in 3m12s
perf : cache
2026-10-08 23:21:34 +07:00

42 lines
1.3 KiB
TypeScript

import "server-only";
import { cacheLife, cacheTag } from "next/cache";
import { getPublicGuide, getPublicGuideSummary, listPublicGuideCards } from "@/lib/guides/queries";
import {
CATALOG_CACHE_TAG,
DIRECTORY_CACHE_TAG,
GLOSSARY_CACHE_TAG,
pageCacheTag,
} from "@/lib/cache/tags";
export async function getCachedPublicGuideCards() {
"use cache: remote";
cacheTag(CATALOG_CACHE_TAG);
cacheLife({ stale: 30, revalidate: 60, expire: 60 * 60 });
cacheTag(DIRECTORY_CACHE_TAG);
cacheTag(GLOSSARY_CACHE_TAG);
return listPublicGuideCards();
}
export async function getCachedPublicGuide(slug: string, section = "overview") {
"use cache: remote";
cacheTag(CATALOG_CACHE_TAG);
cacheLife({ stale: 15, revalidate: 60, expire: 60 * 60 });
const result = await getPublicGuide(slug, section);
cacheTag(GLOSSARY_CACHE_TAG);
if (result) cacheTag(pageCacheTag(result.id));
else cacheTag(DIRECTORY_CACHE_TAG);
return result;
}
export async function getCachedPublicGuideSummary(slug: string) {
"use cache: remote";
cacheTag(CATALOG_CACHE_TAG);
cacheLife({ stale: 15, revalidate: 60, expire: 60 * 60 });
const result = await getPublicGuideSummary(slug);
if (result) cacheTag(pageCacheTag(result.id));
else cacheTag(DIRECTORY_CACHE_TAG);
return result;
}