src/utils/blog-likes.tsimport 'server-only'import { prisma } from '@/utils/prisma'import { kv, likeCountKey, likesKey } from '@/utils/kv'const TTL_SECONDS = 60 * 60 * 24 // 24h// Clears the cached like count and likers set. Use after a like/unlike write.export async function invalidateLike(id: number): Promise<void> {const p = kv.pipeline()p.del(likeCountKey(id))p.del(likesKey(id))await p.exec()}export async function getLikeCountFromDb(id: number): Promise<number> {return prisma.blogLike.count({ where: { post_id: id } })}export async function getLikeCount(id: number): Promise<number> {const cached = await kv.get<number | string>(likeCountKey(id))
Showing the first 20 lines.
Get full code