Next.js · Senior · Question 42 of 75

How do you make sure a 'use cache' function doesn't cache different users' data together?

Explanation

The cache key is built from arguments and captured values, so getDashboard(userId) creates separate entries. Reading cookies() inside a cached function is forbidden. Note that personal data in a shared server cache is a reason to consider 'use cache: private'.

Further reading

Problem with a question

Next.js · Senior · question 42

Test yourself

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

Take this quiz