Does revalidatePath clear any underlying fetch caches?
Answered
Ratonero Mallorquin posted this in #help-forum
Ratonero MallorquinOP
As the question says, when calling revalidatePath on a path/url, does NextJS then also empty any fetch call caches that are used as a result of building that path? Or is that still its "own" thing, following any rules for that?
Given the existance of fetch cache tags, it's easy to intertwine these concepts.
Given the existance of fetch cache tags, it's easy to intertwine these concepts.
12 Replies
@Ratonero Mallorquin As the question says, when calling revalidatePath on a path/url, does NextJS then also empty any fetch call caches that are used as a result of building that path? Or is that still its "own" thing, following any rules for that?
Given the existance of fetch cache tags, it's easy to intertwine these concepts.
all the fetching inside that path should be invalidated
Answer
@Ray all the fetching inside that path should be invalidated
Ratonero MallorquinOP
Our use case is to for example get 2 things:
1. page specific data via fetch from CMS
2. global less changing data (main menu/footer etc) via fetch from CMS
Is there any way to revalidate only the page specific data, to not needlessly clear global data? Such data would be better cleared with a tag for example, so we don't always want to clear that.
1. page specific data via fetch from CMS
2. global less changing data (main menu/footer etc) via fetch from CMS
Is there any way to revalidate only the page specific data, to not needlessly clear global data? Such data would be better cleared with a tag for example, so we don't always want to clear that.
@Ratonero Mallorquin Our use case is to for example get 2 things:
1. page specific data via fetch from CMS
2. global less changing data (main menu/footer etc) via fetch from CMS
Is there any way to revalidate only the page specific data, to not needlessly clear global data? Such data would be better cleared with a tag for example, so we don't always want to clear that.
yes you should use tag and
revalidateTag for thatRatonero MallorquinOP
@Ray But how would we prevent the global data from being invalidated when only invalidating the page specific data?
As you said, all the fetching inside that path should be invalidated, which I assume means the global data will also be invalidated?
As you said, all the fetching inside that path should be invalidated, which I assume means the global data will also be invalidated?
@Ratonero Mallorquin <@743561772069421169> But how would we prevent the global data from being invalidated when only invalidating the page specific data?
As you said, all the fetching inside that path should be invalidated, which I assume means the global data will also be invalidated?
you have to specific a path to revalidatePath right?
like
revalidatePath("/users/1") only invalidate the data for /users/1unless you do this
@Ray you have to specific a path to revalidatePath right?
Ratonero MallorquinOP
If the code to generate that user page on path
I assume that a call to
Not 100% sure I understood you correctly in the first reply, but I interpret it as such?
Now, I know how to clear globalData specifically (just use revalidateTag), but how can I prevent it from being cleared in this scenario?
Imagine you have 100 users that all use the same "globalData". You don't want to clear this data every time a specific
/users/1 is something like this:const userData = fetch('https://api:8080/userdata?id=1');
const globalData = fetch('https://api:8080/globaldata');
// ... render page with both user specific data and global dataI assume that a call to
revalidatePath("/users/1") will also clear globalData? Because both fetch calls are used to render this page.Not 100% sure I understood you correctly in the first reply, but I interpret it as such?
Now, I know how to clear globalData specifically (just use revalidateTag), but how can I prevent it from being cleared in this scenario?
Imagine you have 100 users that all use the same "globalData". You don't want to clear this data every time a specific
/user/x has to revalidate, only when globalData is updated.Ratonero MallorquinOP
In other words, I call
And there is not way to prevent that, other than making sure they are not used when rendering the users/1 page.
Sounds about right?
revalidatePath("/users/1") in this example, it will also clear the data fetch cache for fetch('https://api:8080/userdata?id=1') and fetch('https://api:8080/globaldata')And there is not way to prevent that, other than making sure they are not used when rendering the users/1 page.
Sounds about right?
@Ratonero Mallorquin In other words, I call `revalidatePath("/users/1")` in this example, it will also clear the data fetch cache for `fetch('https://api:8080/userdata?id=1')` and `fetch('https://api:8080/globaldata')`
And there is not way to prevent that, other than making sure they are not used when rendering the users/1 page.
Sounds about right?
add a tag for them and use
revalidateTag instead of revalidatePathRatonero MallorquinOP
I'll look into that approach instead, thank you!