mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Cache clubs and tournaments for 6 hours at a time
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { groupBy } from "lodash";
|
import { unstable_cache } from "next/cache";
|
||||||
|
|
||||||
import clientPromise from "@/lib/mongodb";
|
import clientPromise from "@/lib/mongodb";
|
||||||
import { Club, ClubData } from "@/types";
|
import { Club, ClubData } from "@/types";
|
||||||
@@ -38,6 +38,16 @@ const getClubs = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Clubs() {
|
export default async function Clubs() {
|
||||||
const clubs = await getClubs();
|
const clubs = await unstable_cache(
|
||||||
|
async () => {
|
||||||
|
const data = await getClubs();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
["clubs"],
|
||||||
|
{
|
||||||
|
revalidate: 60 * 60 * 6,
|
||||||
|
},
|
||||||
|
)();
|
||||||
|
|
||||||
return <ClubsDisplay clubs={clubs} />;
|
return <ClubsDisplay clubs={clubs} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { differenceInDays, isSameDay, parse } from "date-fns";
|
import { differenceInDays, isSameDay, parse } from "date-fns";
|
||||||
import { groupBy } from "lodash";
|
import { groupBy } from "lodash";
|
||||||
|
import { unstable_cache } from "next/cache";
|
||||||
|
|
||||||
import clientPromise from "@/lib/mongodb";
|
import clientPromise from "@/lib/mongodb";
|
||||||
import { TournamentData } from "@/types";
|
import { TournamentData } from "@/types";
|
||||||
@@ -8,8 +9,6 @@ import { errorLog } from "@/utils/logger";
|
|||||||
|
|
||||||
import TournamentsDisplay from "./TournamentsDisplay";
|
import TournamentsDisplay from "./TournamentsDisplay";
|
||||||
|
|
||||||
export const revalidate = 3600; // Revalidate cache every 6 hours
|
|
||||||
|
|
||||||
const getTournaments = async () => {
|
const getTournaments = async () => {
|
||||||
try {
|
try {
|
||||||
const client = await clientPromise;
|
const client = await clientPromise;
|
||||||
@@ -145,6 +144,16 @@ const getTournaments = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Tournaments() {
|
export default async function Tournaments() {
|
||||||
const tournaments = await getTournaments();
|
const tournaments = await unstable_cache(
|
||||||
|
async () => {
|
||||||
|
const data = await getTournaments();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
["tournaments"],
|
||||||
|
{
|
||||||
|
revalidate: 60 * 60 * 6,
|
||||||
|
},
|
||||||
|
)();
|
||||||
|
|
||||||
return <TournamentsDisplay tournaments={tournaments} />;
|
return <TournamentsDisplay tournaments={tournaments} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user