Hi gang, I'm a bit stuck with how to handle cache revalidation with Nextjs and Vercel.
I have an api endpoint where I get some posts from, and I tagged the request so I can later revalidate the cache:
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/api/get-public-posts`, { next: {tags: ['public-posts'] } });In the api route I have set some headers so that vercel picks these up and uses the Edge cache:
return new Response(JSON.stringify({ ads, total }), { status: 200, headers: { 'Cache-Control': 'public, s-maxage=60, stale-while-revalidate=59', 'Content-Type': 'application/json', 'Cache-Tag': 'public-posts', }, });And Finally, when a new post is added, I'm running:
revalidateTag('public-posts');Which doesn't seem to do anything. It all works fine after 1 minute, when the cache expires on its own, but it doesn't work when I try to clear the cache manually.
Am I doing this wrong?