perf: cache des données constitution avec unstable_cache (ISR data layer)
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 <noreply@anthropic.com>
This commit is contained in:
+10
-1
@@ -1,4 +1,5 @@
|
|||||||
import {createDirectus, rest, readItems} from '@directus/sdk'
|
import {createDirectus, rest, readItems} from '@directus/sdk'
|
||||||
|
import {unstable_cache as nextCache} from 'next/cache'
|
||||||
import Container from '@mui/material/Container'
|
import Container from '@mui/material/Container'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography'
|
||||||
@@ -19,7 +20,7 @@ const navButton = {
|
|||||||
icon: <AdminPanelSettingsIcon fontSize='large' />
|
icon: <AdminPanelSettingsIcon fontSize='large' />
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getData() {
|
async function fetchConstitution() {
|
||||||
if (!apiUrl) {
|
if (!apiUrl) {
|
||||||
throw new Error('DIRECTUS_API_URL is required')
|
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() {
|
export default async function Page() {
|
||||||
const session = await auth()
|
const session = await auth()
|
||||||
const {titres, articles} = await getData()
|
const {titres, articles} = await getData()
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
## Améliorations moyennes (P3)
|
## Améliorations moyennes (P3)
|
||||||
|
|
||||||
- [ ] ISR page d'accueil (`revalidate`)
|
- [x] ISR page d'accueil (`revalidate`)
|
||||||
- [ ] Dockerisation frontend (`output: standalone`)
|
- [ ] Dockerisation frontend (`output: standalone`)
|
||||||
- [ ] Audit accessibilité WCAG 2.1
|
- [ ] Audit accessibilité WCAG 2.1
|
||||||
- [ ] Responsive mobile dashboard
|
- [ ] Responsive mobile dashboard
|
||||||
|
|||||||
Reference in New Issue
Block a user