CedsTrash
CedsTrash
NNuxt
Created by CedsTrash on 1/27/2025 in #❓・help
Empty Nitro cache on Vercel deployment
Hi everyone, I'm trying to figure out how to clear my Nitro cache when deploying to vercel. I thought it would be automatic, but only he Vercel cache is properly cleared, not the Nitro one. I have to manually call my custom endpoint in order to call cache.removeItem('nitro:handlers:......) PS: I use KV for storage. Any idea? Thanks!
6 replies
NNuxt
Created by CedsTrash on 8/22/2024 in #❓・help
defineCachedEventHandler - set maxAge from environment variable
Hi everyone, I'm trying to figure out how to set my maxAge value from my config because I want it to be different in staging vs production:
export default defineCachedEventHandler(async (event) => {
const config = useRuntimeConfig()

const body = await readBody(event)

let url = config.public.BASE_API_URL + '/collections/' + body.type + '/entries?filter[site]=' + body.locale + '&filter[url]=' + body.url
if ('previewToken' in body) {
url += '&token=' + body.previewToken
}
const result = await $fetch(url)

return {
data: result.data,
fetchedAt: new Date()
}
}, {
maxAge: 1, // Change back to 30
swr: false,
shouldBypassCache: async (event) => {
const body = await readBody(event)
return 'previewToken' in body
},
getKey: async (event) => {
const body = await readBody(event)

return body.cacheKey
}
})
export default defineCachedEventHandler(async (event) => {
const config = useRuntimeConfig()

const body = await readBody(event)

let url = config.public.BASE_API_URL + '/collections/' + body.type + '/entries?filter[site]=' + body.locale + '&filter[url]=' + body.url
if ('previewToken' in body) {
url += '&token=' + body.previewToken
}
const result = await $fetch(url)

return {
data: result.data,
fetchedAt: new Date()
}
}, {
maxAge: 1, // Change back to 30
swr: false,
shouldBypassCache: async (event) => {
const body = await readBody(event)
return 'previewToken' in body
},
getKey: async (event) => {
const body = await readBody(event)

return body.cacheKey
}
})
I would like to set maxAge to config.NITRO_CACHE_TTL but since it expects a number I can't use a function. Would someone know how to do achieve this? Thanks.
9 replies