nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
53.11k stars 4.87k forks source link

additional caching strategies for data fetching composables #14699

Open danielroe opened 1 year ago

danielroe commented 1 year ago

For data fetching composables, we offer initialCache which can either be switched on or off. But in some cases, users may have more advanced strategies, such as refetching after a certain time period or when the tab is reactivated.

Some use cases:

pi0 commented 1 year ago

Related PR and description: nuxt/framework#3985

initialCache flag was introduced in nuxt/framework#3985 as a way to revert the effect of the change we have. It is not a caching strategy.

We could have another issue for force-fetch or track via (#2973). It is not a caching strategy exactly either and removed in same nuxt/framework#3985 PR to be supported back via a better API and also cancel support.

More I think higher-order composables or asyncData handlers with a cache wrapper can provide caching strategies for fetcher. The handler can return the cached value. And such wrapper could be more veastile than having a built-in fixed implementation of cached functions i was initially proposing in nuxt/framework#3985.