#`unstable_cache` behavior changes with console.logs - caching issue

1 messages · Page 1 of 1 (latest)

untold hound
#

Hey! I have a question about Nextjs caching: I have a getCachedProducts function using unstable_cache that works when it has console.logs but stops working when I remove them. The function is tagged with 'products' and gets revalidated via webhooks.

Anyone know why the console.logs affect the caching behavior?

Code snippet:

export const getCachedProducts = async (supabase: SupabaseClient) => {
  return unstable_cache(
    async () => {
      const { data: products } = await supabase
        .from('products')
        .select('*, prices(*)')
        .eq('active', true)
        .eq('prices.active', true)
        .order('metadata->index')
        .order('unit_amount', { referencedTable: 'prices' })
      return products as ProductWithPrices[]
    },
    ['products-cache'],
    { tags: ['products'] }
  )()
}

I'm using Nextjs 14.3

rigid elkBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

hybrid vine
#

Does it only happen in dev, or also in prod?

untold hound
#

only in prod. dev is fine. i'm also sure it was working some time ago. in the meantime supabase was paused but i don't know if that could affect something.

#

I tried changing the unstable_cache key to a different name (products-cache-v2) and for now it seems to have fixed the issue. I don't know if it's a long term fix.

hybrid vine