nuxt / nuxt

The Intuitive Vue Framework.

Home Page:https://nuxt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion for useFetch Documentation: Add cache Option

nd2024 opened this issue · comments

I recently encountered an issue while using useFetch where I needed to prevent caching in a request. Unfortunately, it took me several hours of research to discover that a cache option exists for useFetch since it wasn't explicitly mentioned in the documentation. As a beginner, this was quite challenging and led to some frustration.

I believe adding a cache option to the documentation would greatly benefit users like myself. Clear documentation plays a crucial role in making tools accessible, especially for those who are just starting. By explicitly mentioning the cache option and providing usage examples, beginners would be able to leverage this functionality more efficiently, saving time and effort.

Example:

const { data, error} = await useFetch<GeneralResponse>('/bookmark/add', {
        method: 'post',
        cache: false,
        headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${token.value}`
        },
        body: {
           id: id
        },
    });

Related lines of code so documentation is easier:

cache: typeof opts.cache === 'boolean' ? undefined : opts.cache,

Though I am wondering - is this actively doing something at the moment? 🤔
The setting is passed to ofetch but I can't find the cache property there.

It is passed to fetch itself I think, so refers to https://developer.mozilla.org/en-US/docs/Web/API/fetch#cache I guess? 🤔
Might be better suited/documented in ofetch in general?