lpmagal
lpmagal
NNuxt
Created by lpmagal on 11/29/2024 in #❓・help
dumb question: cache usage with useFetch
Hey guys - I couldn't find the answer in the official docs. What is the correct way to cache API responses based on keys ? I understand that passing a key is to de-duplicate requests between server/side rendering, but I thought it alone would be enough to cache requests - to avoid hitting the API and instead grab from disk cache. Apparently I need to pass a cache key - is that it ? Indeed I need to force cache whenever I need to ? Thanks in advance brothers.
const { data: response, error } = await useFetch(
'/api/...',
{
method: 'GET',
cache: 'force-cache',
key: 'my-key-here',
}
)
const { data: response, error } = await useFetch(
'/api/...',
{
method: 'GET',
cache: 'force-cache',
key: 'my-key-here',
}
)
5 replies