Is there a way you can 100% reliably clear all cache wherever a tag was used?
for example, I have a route handler.
export async function POST(req: Request) {
const body = await req.json()
const post = await db.post.create({
data: {
title: body.title,
content: body.content,
},
})
revalidateTag('posts')
return NextResponse.json({ success: true, message: 'Created post' }, { status: 200 })
}
I call this route handler in /admin/edit/posts - a route completely seperate to where this data is being used.
I want to invalidate ALL of the cache with anything tagged as posts
.
getPosts()
is a function that queries the db, gets all of the posts, caches the data with unstable_cache, and tags it as posts
. That function is used on /blog
and /top-100-posts
etc etc (used on multiple pages)
If I call this route handler, but before I do 100 people visit /blog
and /top-100-posts
(where the data is tagged as posts
), they will not get the new updated data until they hard refresh or the client-side router cache is invalid.
Is there a way I can get around this? I want to take advantage of the data cache but I don’t want to serve stale data to a user just because they have visited that route and it’s now cached in the client-router cache.
Is this maybe solved in Next 15?