cache control added to .env
This commit is contained in:
parent
5123f4e2d1
commit
beff602ffa
1
.env
1
.env
@ -2,3 +2,4 @@ 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_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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user