From af6d5712a48671b96188a3d4e721c15ad7f8c2f5 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Thu, 12 Dec 2024 15:08:40 +0100 Subject: [PATCH] test better cache strat --- next-14/src/app/actions.ts | 1 + next-14/src/sanity/fetch.ts | 2 +- next-15/src/app/actions.ts | 1 + next-15/src/sanity/fetch.ts | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/next-14/src/app/actions.ts b/next-14/src/app/actions.ts index 80ca400..a147ac7 100644 --- a/next-14/src/app/actions.ts +++ b/next-14/src/app/actions.ts @@ -4,6 +4,7 @@ import type {SyncTag} from '@sanity/client' import {revalidateTag} from 'next/cache' export async function expireTags(tags: SyncTag[]) { + revalidateTag('sanity:tags') for (const tag of tags) { revalidateTag(tag) } diff --git a/next-14/src/sanity/fetch.ts b/next-14/src/sanity/fetch.ts index c614337..3f483df 100644 --- a/next-14/src/sanity/fetch.ts +++ b/next-14/src/sanity/fetch.ts @@ -13,7 +13,7 @@ export async function sanityFetch({ filterResponse: false, cacheMode: 'noStale', tag: 'fetch-sync-tags', // The request tag makes the fetch unique, avoids deduping with the cached query that has tags - next: {revalidate: 1}, // Ensure we don't opt out of ISR caching + next: {revalidate: false, tags: ['sanity:tags']}, // Ensure we don't opt out of ISR caching }) const data = await client.fetch(query, params, { cacheMode: 'noStale', diff --git a/next-15/src/app/actions.ts b/next-15/src/app/actions.ts index 80ca400..a147ac7 100644 --- a/next-15/src/app/actions.ts +++ b/next-15/src/app/actions.ts @@ -4,6 +4,7 @@ import type {SyncTag} from '@sanity/client' import {revalidateTag} from 'next/cache' export async function expireTags(tags: SyncTag[]) { + revalidateTag('sanity:tags') for (const tag of tags) { revalidateTag(tag) } diff --git a/next-15/src/sanity/fetch.ts b/next-15/src/sanity/fetch.ts index 6055508..6dac8f6 100644 --- a/next-15/src/sanity/fetch.ts +++ b/next-15/src/sanity/fetch.ts @@ -13,6 +13,7 @@ export async function sanityFetch({ filterResponse: false, cacheMode: 'noStale', tag: 'fetch-sync-tags', // The request tag makes the fetch unique, avoids deduping with the cached query that has tags + next: {revalidate: false, tags: ['sanity:tags']}, }) const data = await client.fetch(query, params, { cacheMode: 'noStale',