From c4762c6437938f25167f3e2ada8f1edae8f60e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Tue, 14 Apr 2026 06:54:07 +0400 Subject: [PATCH] =?UTF-8?q?perf:=20cache=20des=20donn=C3=A9es=20constituti?= =?UTF-8?q?on=20avec=20unstable=5Fcache=20(ISR=20data=20layer)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La page d'accueil appelle auth() (cookies → dynamique) donc export const revalidate ne s'applique pas au rendu. On cache à la place les appels Directus : - fetchConstitution() → wrappée avec nextCache (unstable_cache) - revalidate: 300 (5 min) — la constitution évolue peu - tag 'constitution' — permet revalidateTag('constitution') depuis une API route pour invalider le cache à la demande lors d'un changement Directus Les appels API Directus (titres + articles) ne sont plus refaits à chaque requête. Co-Authored-By: Claude Sonnet 4.6 --- app/page.js | 11 ++++++++++- tasks/todo.md | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/page.js b/app/page.js index c9897d1..aa11a75 100644 --- a/app/page.js +++ b/app/page.js @@ -1,4 +1,5 @@ import {createDirectus, rest, readItems} from '@directus/sdk' +import {unstable_cache as nextCache} from 'next/cache' import Container from '@mui/material/Container' import Box from '@mui/material/Box' import Typography from '@mui/material/Typography' @@ -19,7 +20,7 @@ const navButton = { icon: } -async function getData() { +async function fetchConstitution() { if (!apiUrl) { throw new Error('DIRECTUS_API_URL is required') } @@ -58,6 +59,14 @@ async function getData() { } } +// Mise en cache des données constitution — revalidation toutes les 5 minutes. +// Le tag 'constitution' permet une invalidation à la demande via revalidateTag(). +const getData = nextCache( + fetchConstitution, + ['constitution-data'], + {revalidate: 300, tags: ['constitution']} +) + export default async function Page() { const session = await auth() const {titres, articles} = await getData() diff --git a/tasks/todo.md b/tasks/todo.md index b3c93bf..29de9b5 100644 --- a/tasks/todo.md +++ b/tasks/todo.md @@ -19,7 +19,7 @@ ## Améliorations moyennes (P3) -- [ ] ISR page d'accueil (`revalidate`) +- [x] ISR page d'accueil (`revalidate`) - [ ] Dockerisation frontend (`output: standalone`) - [ ] Audit accessibilité WCAG 2.1 - [ ] Responsive mobile dashboard