I’m have written code similar to this
async function getPostData() {
const res = await fetch('https://api.example.com/post')
if (!res.ok) {
throw new Error('Failed to fetch data')
}
return res.json()
}
calling this Method inside generateMetadata method like
export async function generateMetadata(props : Props) {
const postData = await getPostData();
}
and same getPostData method calling inside Page Component Method like
const PostPage = async (props: Props) => {
const postData = await getPostData();
}
Here I’m calling same method Two Times then the Same API getting called Two times on Server
If I’m trying to use revalidate with 60 seconds like below code
fetch('https://...', { next: { revalidate: 60 } })
then also same API getting called Twice on server while re-validating cache.
So, just I want to know, Is there any way to share same response data between both Method generateMetadata and PostPage