perf: optimize public content caching
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { revalidatePath, revalidateTag } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { CMS_CACHE_TAG } from '@/lib/cms-cache'
|
||||
|
||||
const CACHE_PATHS = [
|
||||
'/sitemap.xml',
|
||||
@@ -45,6 +46,8 @@ function normalizeReturnPath(value: FormDataEntryValue | null) {
|
||||
export async function clearFrontendCache(formData: FormData) {
|
||||
const returnTo = normalizeReturnPath(formData.get('returnTo'))
|
||||
|
||||
revalidateTag(CMS_CACHE_TAG)
|
||||
|
||||
for (const path of CACHE_PATHS) {
|
||||
revalidatePath(path)
|
||||
}
|
||||
@@ -59,6 +62,7 @@ export async function clearFrontendCache(formData: FormData) {
|
||||
export async function refreshSitemapCache(formData: FormData) {
|
||||
const returnTo = normalizeReturnPath(formData.get('returnTo'))
|
||||
|
||||
revalidateTag(CMS_CACHE_TAG)
|
||||
revalidatePath('/sitemap.xml')
|
||||
|
||||
redirect(`${returnTo}${returnTo.includes('?') ? '&' : '?'}sitemap=refreshed`)
|
||||
|
||||
Reference in New Issue
Block a user