CedsTrash
CedsTrash
NNuxt
Created by CedsTrash on 3/10/2025 in #❓・help
Error message when using LRU store driver
No description
14 replies
NNuxt
Created by CedsTrash on 3/10/2025 in #❓・help
Nuxt 3 on Vercel - Store cache in memory vs Vercel KV ?
Hi everyone, I developed this habit of always tying every new Nuxt project to a Vercel KV store. But every now an then, I'm facing this issue where the store reaches 5-7k keys (300b to 12kb each) , even though I only have 50 pages on some of the websites, and I can't seem to delete a single key or even flush the entire store using useStorage().removeItem() or useStorage().clear() from my Nitro event handler. I don't exactly remember the error message but it was a Redis error related to the store being to big or having too many keys. I use this setup to store my API responses so I don't have to fetch the same content over and over. I set up a process in order to clear some cache entries on content updates on the CMS and also on Vercel deployments. But sometimes it's hard to know every single part of the website you need to clear the cache for, so I get some pages that don't reflect the latest changes. Where am I going with all this....I'm suddenly asking myself if this whole KV thing is actually giving me some advantages compared to a simple memory storage, knowing that I don't need this data to be persisted between deployments. Using the memory driver, I could still invalidate some pages cache the same way I do it at the moment, and the entire cache would be flushed on a new Vercel deployment. It would work perfectly for me, I don't think I really need a KV store, but I wonder if I would feel some big difference in terms of performance. I'm also looking at the LRU cache driver. I'd greatly appreciate your input on this.
5 replies
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