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

useRequest custom cache support async getCache #182

Open
4 tasks done
BreathlessWay opened this issue Jan 29, 2024 · 8 comments
Open
4 tasks done

useRequest custom cache support async getCache #182

BreathlessWay opened this issue Jan 29, 2024 · 8 comments
Labels
help wanted Extra attention is needed PR welcome welcome to PR todo Things to do
Milestone

Comments

@BreathlessWay
Copy link

Description

能否支持异步调用的 getCache

Suggested solution

useCachePlugin.js 中的 方法 getCache 使用 async await 调用

Alternative

No response

Additional context

No response

Validations

@BreathlessWay BreathlessWay added the enhancement: pending triage issue pending triage label Jan 29, 2024
@XiaoDaiGua-Ray
Copy link
Contributor

能否给一个示例,否则不知道你的使用场景和需求是什么

@BreathlessWay
Copy link
Author

能否给一个示例,否则不知道你的使用场景和需求是什么

因为想使用 localforage 进行数据缓存,而 localforage 的 getItem 是一个异步行为

@XiaoDaiGua-Ray
Copy link
Contributor

或许你可以自己使用 Promise 包裹一层,这边暂时不考虑异步行为。

@BreathlessWay
Copy link
Author

或许你可以自己使用 Promise 包裹一层,这边暂时不考虑异步行为。

但是文档中提及可以使用 IndexDB,IndexDB 本身也是异步的

image

如果在 geCache 中进行 Promise 返回,那返回的值被转为 ref 时会直接变成 undefined,缓存就失效了

image

image

如果 getCache 中是同步行为,就不存在缓存失效的问题
image

image

@XiaoDaiGua-Ray
Copy link
Contributor

你的写法有点不对,明天我尝试还原你的使用场景给你一个答复。感谢你的支持~

@NelsonYong NelsonYong added help wanted Extra attention is needed and removed enhancement: pending triage issue pending triage labels Feb 21, 2024
@NelsonYong
Copy link
Contributor

@BreathlessWay 后续会考虑支持

@NelsonYong
Copy link
Contributor

目前 getCache 确实不支持异步的。

@NelsonYong NelsonYong added PR welcome welcome to PR todo Things to do labels May 15, 2024
@NelsonYong NelsonYong added this to the 2.x milestone May 15, 2024
@NelsonYong
Copy link
Contributor

@BreathlessWay 我们将在 2.x 探索如何进行优雅的异步获取缓存

@NelsonYong NelsonYong reopened this May 15, 2024
@NelsonYong NelsonYong changed the title 能否支持异步调用的 getCache useRequest custom cache support async getCache May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed PR welcome welcome to PR todo Things to do
Projects
None yet
Development

No branches or pull requests

3 participants