diff --git a/.env b/.env index 3c1b567..f7771f7 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ NEXT_PUBLIC_CATEGORIES_PER_CATEGORY_PAGE=10 NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE=10 NEXT_PUBLIC_POSTS_PER_POSTS_PAGE=10 -NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE=10 \ No newline at end of file +NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE=10 +NEXT_PUBLIC_BLOG_CACHE=true \ No newline at end of file diff --git a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx index 55485e2..b70fde9 100644 --- a/src/app/(routes)/blog/categories/[categorySlug]/page.tsx +++ b/src/app/(routes)/blog/categories/[categorySlug]/page.tsx @@ -14,6 +14,9 @@ async function fetchCategoryData( ): Promise { const res = await fetch( `${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories/${categorySlug}/posts?per_page=${searchParams.get("per_page") || process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.get("page") ? `&page=${searchParams.get("page")}` : ""}`, + { + cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store", + }, ); if (res.status === 404) { diff --git a/src/app/(routes)/blog/categories/page.tsx b/src/app/(routes)/blog/categories/page.tsx index f3ebed2..9c048fc 100644 --- a/src/app/(routes)/blog/categories/page.tsx +++ b/src/app/(routes)/blog/categories/page.tsx @@ -28,6 +28,9 @@ export const metadata: Metadata = { export default async function Categories({ searchParams }: categoryPropsType) { const CategoriesData: CategoriesListType = await fetch( `${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_CATEGORIES_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`, + { + cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store", + }, ).then((res) => res.json()); const dict = await getDictionary(getDefaultLocale()); diff --git a/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx b/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx index 8ed5f77..84ece6a 100644 --- a/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx +++ b/src/app/(routes)/blog/filtered-posts/[filter]/page.tsx @@ -77,7 +77,7 @@ export default async function FilteredPosts({ FilteredPostsData = await fetch( `${process.env.NEXT_PUBLIC_BLOG_API_URL}${filteredPostApiUrl}&per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`, { - cache: "no-store", + cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store", }, ).then((res) => res.json()); } else { diff --git a/src/app/(routes)/blog/page.tsx b/src/app/(routes)/blog/page.tsx index 3240ad2..6db9195 100644 --- a/src/app/(routes)/blog/page.tsx +++ b/src/app/(routes)/blog/page.tsx @@ -9,9 +9,9 @@ export default async function Blog() { latest_categories: []; most_viewed_posts: []; random_posts: []; - } = await fetch(`${process.env.NEXT_PUBLIC_BLOG_API_URL}/homepage`,{cache:"no-store"}).then( - (res) => res.json(), - ); + } = await fetch(`${process.env.NEXT_PUBLIC_BLOG_API_URL}/homepage`, { + cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store", + }).then((res) => res.json()); return (
diff --git a/src/app/(routes)/blog/posts/[postSlug]/page.tsx b/src/app/(routes)/blog/posts/[postSlug]/page.tsx index d167468..f95b799 100644 --- a/src/app/(routes)/blog/posts/[postSlug]/page.tsx +++ b/src/app/(routes)/blog/posts/[postSlug]/page.tsx @@ -12,7 +12,9 @@ import { redirect } from "next/navigation"; async function fetchPostData(postSlug: string): Promise { const res = await fetch( - `${process.env.NEXT_PUBLIC_BLOG_API_URL}/posts/${postSlug}`, + `${process.env.NEXT_PUBLIC_BLOG_API_URL}/posts/${postSlug}`, { + cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store", + } ); if (res.status === 404) {