Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAsyncData not cache #15727

Closed
lyoko515 opened this issue Dec 4, 2022 · 7 comments
Closed

useAsyncData not cache #15727

lyoko515 opened this issue Dec 4, 2022 · 7 comments

Comments

@lyoko515
Copy link

lyoko515 commented Dec 4, 2022

Environment

Nuxi 3.0.0 09:55:06
09:55:07
RootDir: /app 09:55:07
Nuxt project info: 09:55:07


  • Operating System: Linux
  • Node Version: v18.12.1
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: app, typescript, runtimeConfig, build, modules, dayjs
  • Runtime Modules: @nuxtjs/tailwindcss@6.1.3, @nathanchase/nuxt-dayjs-module@1.0.11, @nuxt/image-edge@1.0.0-27827328.bc9ddc0
  • Build Modules: -

Reproduction

<script setup> const { data:datanew, pending, refresh } = await useAsyncData('testDataNew', () => $fetch(`https://api.nuxtjs.dev/mountains`)) const callapinew = async () => { datanew.value = await useAsyncData('testDataNew', () => $fetch(`https://api.nuxtjs.dev/mountains`)) } </script>
Call api
{{ datanew }}

Describe the bug

AsyncData does not cache even if the key is present. Is AsyncData not caching anymore?

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

That's right, useAsyncData does not cache by default. You can implement your own cache if you would like.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2022
@lyoko515
Copy link
Author

lyoko515 commented Dec 4, 2022

Thanks

@talaxasy
Copy link

talaxasy commented Dec 6, 2022

@danielroe Could you show in what place and when did they decide to change it?

@manniL
Copy link
Member

manniL commented Dec 6, 2022

@danielroe Could you show in what place and when did they decide to change it?

nuxt/framework#8885

@kirtan403
Copy link

kirtan403 commented Dec 15, 2022

How to provide the caching mechanism then? For the static site, if on client-side navigation, the cache is not being fetched, the site breaks and starts throwing error as the fetch failed. Any other options? or examples to implement custom cache (as @danielroe mentioned)?

@talaxasy
Copy link

How to provide the caching mechanism then? For the static site, if on client-side navigation, the cache is not being fetched, the site breaks and starts throwing error as the fetch failed. Any other options? or examples to implement custom cache (as @danielroe mentioned)?

I think it can be provided via useSWRV + $fetch in theory

@talaxasy
Copy link

It might look smth like this const {data, pending } = useSWRV('myUniqKey', () => $fetch('api/getPosts')). But you won't be able to enjoy the benefits of using use(Lazy)AsyncData or use(Lazy)Fetch 😒

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants