fix: cache

This commit is contained in:
Benno Tielen 2026-09-25 12:11:05 +02:00
parent efdd00d2f0
commit 58683d3c4d
2 changed files with 9 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import { CollectionConfig } from 'payload' import { CollectionConfig } from 'payload'
import { hide, isAdminOrEmployee } from '@/collections/access/admin' import { hide, isAdminOrEmployee } from '@/collections/access/admin'
import { revalidateTagHook } from '@/utils/revalidate'
export const ContactPerson: CollectionConfig = { export const ContactPerson: CollectionConfig = {
slug: 'contactPerson', slug: 'contactPerson',
@ -54,4 +55,10 @@ export const ContactPerson: CollectionConfig = {
update: isAdminOrEmployee(), update: isAdminOrEmployee(),
delete: isAdminOrEmployee(), delete: isAdminOrEmployee(),
}, },
hooks: {
// Pages and events embed contacts via relationships, so their caches
// hold a copy of the contact and must be invalidated on change.
afterChange: [revalidateTagHook('pages'), revalidateTagHook('events')],
afterDelete: [revalidateTagHook('pages'), revalidateTagHook('events')],
},
} }

View file

@ -28,5 +28,6 @@ export async function fetchPageBySlug(
return unstable_cache(fetchPage, ['pages', slug], { return unstable_cache(fetchPage, ['pages', slug], {
tags: ['pages', `pages-${slug}`], tags: ['pages', `pages-${slug}`],
revalidate: 3600,
})() })()
} }