`unstable_cache` behavior changes with console.logs - caching issue
Unanswered
Nebelung posted this in #help-forum
NebelungOP
Hey! I have a question about Nextjs caching: I have a
Anyone know why the console.logs affect the caching behavior?
Code snippet:
I'm using Nextjs 14.3
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
5 Replies
Does it only happen in dev, or also in prod?
NebelungOP
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.@Nebelung 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:
ts
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
So do you mean when you've console.log inside, cache works, but otherwise, cache doesn't?
I don't think it should happen