- I have an API route
/api/text-snippet/enwhich makes an API call to the database to fetch all text snippets - The admin is able to edit the text snippets and he can manually delete the text snippet cache with a click of a button
Issue: It's not working in a Vercel environment only, it's working locally.
How I define the cached function in Nuxt: /api/text-snippet/en:
export default defineCachedEventHandler(async (event) => { const { locale } = getRouterParams(event) const supabase = serverSupabaseServiceRole<Database>(event) const { data, error } = await supabase.from('text_snippet') .select('*') .eq('locale', locale) if (error) throw createError(error) return data}, { swr: true, maxAge: 86400, staleMaxAge: 172800, getKey: (event) => `text-snippet:${getRouterParams(event).locale}`})Code to invalidate the cache: /api/admin/cache/invalidate.post.ts
export default defineEventHandler(async (event) => { try { const cacheStorage = useStorage('cache') await cacheStorage.clear() return { success: true } } catch (error: any) { throw createError(error) }})These are the response headers:
age:1560cache-control:public, max-age=0, must-revalidatecontent-encoding:brcontent-type:application/jsondate:Thu, 30 Jan 2025 10:03:39 GMTlast-modified:Thu, 30 Jan 2025 10:03:37 GMTserver:Vercelstrict-transport-security:max-age=63072000x-vercel-cache:HITx-vercel-id:fra1::iad1::8mvcg-1738232980359-72dbc3df8dd6- Nuxt 3
- Production environment
