Improve On-Demand Revalidation(New Route Segment Config, cache
function takes tags
argument)
#59761
2chanhaeng
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
cache
function acts likereact.cache
but also takestags
argument.Non-Goals
No response
Background
I'm using Next.js and Prisma.
PrismaClient
makes it easy to fetch data from the Server Component.However, Next dosen't revalidate the cached data.
The documentation suggests some ways, but they're pretty complex and annoying to use.
Therefore, I suggest new alternatives; New Route Segment Config and
cache
function takestags
argument.Proposal
The first way is new Route Segment Config that can revlidate the cache using tags.
You can use like this,
Then the page data will revalidate on-demand by cache tag(
revalidateTag
).Yes, you can use
revalidatePage
for every page when every data revalidation needed.Or just declare tags at pages and use
revalidateTag
.The second way is
cache
function acts likereact.cache
but also takestags
argument.It works like
fetch( url, { next: { tags: [...] } } )
but not need url, so you don't have to make new Route Handler.It's still just an idea, so it may be not good, like unable to implement.
If you have any feedback on this, or if you already have a better way of doing things, please feel free to leave a comment.
Thanks for reading.
Beta Was this translation helpful? Give feedback.
All reactions