Next.js Discord

Discord Forum

revalidateTag invalidates more than it should

Unanswered
Cuban Crocodile posted this in #help-forum
Open in Discord
Cuban CrocodileOP
I have a page component using use cache rendering tournament detail

export default async function TournamentPairingsAllPage({ params }: { params: Promise<{ id: string }> }) {
  'use cache';
  const { id } = await params;
  unstable_cacheTag(getTournamentCacheKey(id));
  console.log(`cache miss: all pairings: ${getTournamentCacheKey(id)}`);

  const tournamentResult = await loadTournament(id);
  if (!tournamentResult) {
    return null;
  }

  return <Pairings tournament={tournamentResult} />;
}


and a server action for uploading tournaments that revalidates cache

console.log(`uploading: ${tournamentId}`);
    revalidateTag(getAllTournamentsCacheKey());
    console.log(`revalidated: ${getAllTournamentsCacheKey()}`);
    revalidateTag(getOrganizationTournamentsCacheKey(orgId));
    console.log(`revalidated: ${getOrganizationTournamentsCacheKey(orgId)}`);
    revalidateTag(getTournamentCacheKey(tournamentId));
    console.log(`revalidated: ${getTournamentCacheKey(tournamentId)}`);


I start app, render detail for tournament A and B. I get "cache miss" for both. Reload does not print anything. After calling upload for A which causes revalidate for A, following reloads of A and B print cache miss again. Only A should be reloaded, B should be still cached. Am I missing something?

7 Replies

Cuban CrocodileOP
Output from my app to see how cache tags look like:

uploading: 0196ef07-2726-7333-960f-38d5f0e66dd4
revalidated: all_tournaments
revalidated: org_tournaments:org_2vYcFBOC2JkMbSPalnCKdS2L3qw
revalidated: single_tournament:0196ef07-2726-7333-960f-38d5f0e66dd4
cache miss: layout: single_tournament:0196ef07-2726-7333-960f-38d5f0e66dd4
cache miss: my pairings: single_tournament:0196ef07-2726-7333-960f-38d5f0e66dd4
cache miss: layout metadata: single_tournament:0196ef07-2726-7333-960f-38d5f0e66dd4
cache miss: layout: single_tournament:0196fefa-359f-7605-ad87-7b3dc333a6e2
cache miss: roster: single_tournament:0196fefa-359f-7605-ad87-7b3dc333a6e2
cache miss: layout metadata: single_tournament:0196fefa-359f-7605-ad87-7b3dc333a6e2
can you try console.logging what the cache key returns, when you run getTournamentCacheKey, and is it a async function or normal function?
Cuban CrocodileOP
It's sync function. It returns string single_tournament:uuid. See console output one message up.
use cache is a beta user, its a good idea to open a issue on nextjs github
it might be a issue with the code also, but I don't think so
Github*
Nextjs github*