Next.js · Middle · Question 14 of 75

How do you avoid a double DB query if both generateMetadata and the page call getUser(id)?

Explanation

cache() memoizes calls with the same arguments for the duration of one server render. Next.js deduplicates fetch with identical parameters itself, but ORMs and SDKs need cache(). A global variable would mix different users' data.

Further reading

Problem with a question

Next.js · Middle · question 14

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz