From 4cc19386fe4ec2278b6fa3fa4a42324b400d3fff Mon Sep 17 00:00:00 2001 From: Damjan Savic Date: Sun, 25 Jan 2026 06:32:09 +0100 Subject: [PATCH] auto-claude: subtask-2-1 - Add caching to getAllBlogPosts using existing Cache --- src/lib/blog.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/blog.ts b/src/lib/blog.ts index 567ae70..a8d3dfa 100644 --- a/src/lib/blog.ts +++ b/src/lib/blog.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import { cache } from '@/utils/cache'; export interface BlogPost { slug: string; @@ -130,6 +131,14 @@ function parseMarkdownPost(filename: string, content: string): BlogPost | null { } export function getAllBlogPosts(): BlogPost[] { + const cacheKey = 'blog:all-posts'; + + // Check cache first + const cachedPosts = cache.get(cacheKey); + if (cachedPosts) { + return cachedPosts; + } + if (!fs.existsSync(BLOG_POSTS_DIR)) { console.warn('Blog posts directory not found:', BLOG_POSTS_DIR); return []; @@ -151,7 +160,12 @@ export function getAllBlogPosts(): BlogPost[] { } // Sort by date descending (newest first) - return posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); + const sortedPosts = posts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); + + // Cache the results + cache.set(cacheKey, sortedPosts); + + return sortedPosts; } export function getBlogPostBySlug(slug: string): BlogPost | null {