- 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:1560
cache-control:public, max-age=0, must-revalidate
content-encoding:br
content-type:application/json
date:
Thu, 30 Jan 2025 10:03:39 GMT
last-modified:Thu, 30 Jan 2025 10:03:37 GMT
server:Vercel
strict-transport-security:max-age=63072000
x-vercel-cache:HIT
x-vercel-id:fra1::iad1::8mvcg-1738232980359-72dbc3df8dd6- Nuxt 3
- Production environment
