I am trying to use the react cache to avoid calling the database twice in a single request for the same data.
In my file I have
const getCocktailInfoForIngredients = cache(async (ingredients: string[]):Promise<{ingLabel:string,canUrl:string,cocktails:CocktailSer[]}> => {
console.log("called getCocktailInfoForIngredients");
Later I have
export default async function Page({ params }: { params: { ingredients: string[] } }) {
const {ingLabel,canUrl,cocktails} = await getCocktailInfoForIngredients(params.ingredients);
...
}
export async function generateMetadata(
{ params }: { params: { ingredients: string[] } },
parent: ResolvingMetadata
): Promise<Metadata> {
const {ingLabel,canUrl,cocktails} = await getCocktailInfoForIngredients(params.ingredients);
...
When the page loads I see two log outputs for getCocktailInfoForIngredients - I was expecting to only see that once.