Next.js Discord

Discord Forum

unstable_cache user or global?

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
I noticed that some functions I was using unstable_cache for seemed to be caching across users...

to revalidate cache, would that tags need to include the userId?

const getPosts = cache(
  async () => {
    const response = await fetch(`https://jsonplaceholder.typicode.com/posts?userId=${loggedInUserId}`);
    return response.json();
  },
  ['posts', `${loggedInUserId}`],
  {
    tags: ['posts'],
  }
);

// or is this necessary for every call?

const getPosts = cache(
  async () => {
    const response = await fetch(`https://jsonplaceholder.typicode.com/posts?userId=${loggedInUserId}`);
    return response.json();
  },
  ['posts', `${loggedInUserId}`],
  {
    tags: [`posts-${loggedInUserId}`],
  }
);

1 Reply

Sloth bear
@Mugger Crocodile I had the exact same question, have you figured it out?

https://nextjs-forum.com/post/1192923418350333982