Replies: 1 comment 4 replies
-
试试这个自定义设置缓存,然后自己全局实现一套缓存逻辑(比如在状态管理库的 store 中实现),然后缓存就由你来控制了,clearCache, getCache 都不是问题,自己封装逻辑就好了。 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
背景
比如,
第一个地方,直接通过useRequest获取,并设置slateTime,这个没问题
第二个地方,并不是通过useRequest来获取数据,所以没办法直接复用之前缓存的值
请问这种场景有没有好的解决办法
我们的思考
第一种方式,就是存在应用全局状态,然后读取,但这个改造成本大,维护麻烦
第二种方式,利用自定义缓存(例如localStorage),然后第二个地方直接从localStorage获取
也可行,但是又要维护localStorage很麻烦
第三种方式,ahooks返回getCache方法,直接从ahook内存中获取
我看到有暴露clearCache的方法,但是没有暴露getCache,现在实现不了
Beta Was this translation helpful? Give feedback.
All reactions