cache control added to .env

This commit is contained in:
parsa aghaei committed 2024-11-11 12:44:23 +03:30
1 parent 5123f4e2d1
commit beff602ffa
6 files changed
+15 -6

No files matched your search

+2 -1
View File
@@ -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
NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE=10
NEXT_PUBLIC_BLOG_CACHE=true
@@ -14,6 +14,9 @@ async function fetchCategoryData(
): Promise<CategoryDataType> {
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) {
@@ -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());
@@ -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 {
+3 -3
View File
@@ -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 (
<div className="flex w-full max-w-[1280px] flex-col items-center gap-[50px] pt-5 md:gap-[100px]">
<New data={homePageData.latest_posts} />
@@ -12,7 +12,9 @@ import { redirect } from "next/navigation";
async function fetchPostData(postSlug: string): Promise<PostSlugPagePostType> {
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) {