NuxtN
Nuxt9mo ago
3 replies
enti

custom `name` parameter for Nitro `defineCachedEventHandler()`

I want to use the current language as a parameter sor my API call. Obviously, I want my cache strategy to follow these different languages possibilities:

import { fetchSuggestions } from '../utils/suggestions'

export default defineCachedEventHandler(async (event) => {
  const query = getQuery(event)
  const lang = query.lang as string || ''

  return await fetchSuggestions(
    lang,
  )
}, {
  name: `suggestions-${lang}`, // won't work, but what will ?
  maxAge: 86400, // 24h
  swr: true,
})


How can
name
receive a value depending on the query parameters?
Was this page helpful?