Next.js Discord

Discord Forum

unstable_cache changing every time?

Unanswered
Netherland Dwarf posted this in #help-forum
Open in Discord
Netherland DwarfOP
How come my unstable cache is being refreshed on every reload? I don't think I'm doing anything wrong so I'm a bit surprised to see it not working.

export async function getRecommendations(supabase: DatabaseClient, userId: string) {
  const getDashboardRecommendations = unstable_cache(
    async () => {
      const { data, error } = await supabase.rpc("getDashboardOverviewRecommendations");
      if (error) throw new DatabaseError("Try again later", { error, message: "There was an issue getting user recommendations" });
      return data.map((recommended) => {
        const discoverLink = recommended.discoverLink?.split("/");
        const state = abbreviationsToState[discoverLink?.[2].toUpperCase() as keyof typeof abbreviationsToState];
        const updatedDiscoverLink = `/discover/${discoverLink?.[0]}/${discoverLink?.[1]}/${state.toLowerCase()}/${discoverLink?.[3]}`;

        return { ...recommended, discoverLink: encodeURI(updatedDiscoverLink) };
      });
    },

    [`dashboard-recommendations-${userId}`],
    { revalidate: 60 * 60 }
  );

  return getDashboardRecommendations();
}

1 Reply

Netherland DwarfOP
Calling that function from a server component