db cache updated

This commit is contained in:
Owen Rees
2023-06-15 13:24:45 +02:00
parent 0bca6488a4
commit fb9966fc25
5 changed files with 87 additions and 70 deletions
+9 -6
View File
@@ -1,5 +1,4 @@
import clientPromise from "@/lib/mongodb";
import { cache } from "react";
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
/**
@@ -7,16 +6,20 @@ import { dateOrderingFrance } from "@/utils/dbDateOrdering";
* @route /api/tournaments/france
* @internal
*/
export const revalidate = 86400;
export const GET = cache(async function () {
// TODO add headers to response content-type application/json
export const revalidate = 3600; // revalidate cache every 6 hours
async function GET() {
const headers = {
"Content-Type": "application/json",
};
try {
const client = await clientPromise;
const db = client.db("tournamentsFranceDB");
const data = await dateOrderingFrance(db);
return new Response(JSON.stringify(data), { status: 200 });
return new Response(JSON.stringify(data), { status: 200, headers });
} catch (error) {
return new Response(JSON.stringify(error), { status: 500 });
return new Response(JSON.stringify(error), { status: 500, headers });
}
});
}
+1 -1
View File
@@ -4,7 +4,7 @@ import Layout from "@/components/Layout";
import TournamentTable from "@/components/TournamentTable";
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
export const revalidate = 86400; // cache for 24 hours
export const revalidate = 3600; // revalidate cache every 6 hours
/**
* Imports the tournament map component, ensuring CSR only.