Next.js Discord

Discord Forum

unstable_cache not revalidating?

Answered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Open in Discord
Avatar
Schneider’s Smooth-fronted CaimanOP
Hi

I have this setup:

export const fetchMostPopularCities = async () => {
  const supabase = await createClient();

  const cachedMostPopularCities = unstable_cache(
    async () => {
      return await supabase.from("most_popular_cities").select("*");
    },
    [CACHE_TAGS.MOST_POPULAR_CITIES],
    {
      tags: [CACHE_TAGS.MOST_POPULAR_CITIES],
      revalidate: 60 * 60 * 12, // 12 hours
    },
  );

  const { data: mostPopularCities, error } = await cachedMostPopularCities();

  if (error) {
    console.error(error);
    return [];
  }

  return mostPopularCities;
};


Caching is working fine, however it's been 12hours and the data shown is old data *on my vercel.app domain.

Am I doing something wrong, or this is a bug?
Answered by Schneider’s Smooth-fronted Caiman
I'll just revalidate manually for now
View full answer

13 Replies

Avatar
Schneider’s Smooth-fronted CaimanOP
Image
Avatar
Schneider’s Smooth-fronted CaimanOP
I triggered it manually and this worked. However it seems there's a bug in the revalidation config OR I don't understand how it works properly
Avatar
You are using unstable cache keyparts wrong
The docs is pretty bad regarding it, I did update it to be more descriptive.. but it's still in canary, so go through it directly
Avatar
Schneider’s Smooth-fronted CaimanOP
I don't immediately see how usage of keyparts is affecting the line:
revalidate: 60 * 60 * 12, // 12 hours
Avatar
Which is a very good question lol, I am also wondering why lmao
@Schneider’s Smooth-fronted Caiman quick question but you went on the site to check right?
Also go debug, set a 2 min duration and test
Avatar
Schneider’s Smooth-fronted CaimanOP
yes I checked the docs and youtube videos etc...

it's always my last resort to ask questions

I'll try and set a 2 min duration and come back
Avatar
Schneider’s Smooth-fronted CaimanOP
didn't revalidate on it's own
Avatar
Can you setup a minimal reproduction?
Avatar
Schneider’s Smooth-fronted CaimanOP
I'll just revalidate manually for now
Answer