架构陷阱(续)
import { unstable_cache } from "next/cache";
import { prisma } from "@/lib/prisma";
// 包裹数据库查询
export const getPosts = unstable_cache(
async () => {
return await prisma.post.findMany();
},
["posts"], // 缓存键
{
revalidate: 3600, // 每小时更新
tags: ["posts"], // 标签
}
);
// 使用
const posts = await getPosts();