Open JeromeD3 opened 1 year ago
当我们想强制删除缓存,一定要让组件重新请求的时候,我们可以这样子做。
直接在cache
这个map中新增一个删除函数就行啦
const cache = new Map();
const setCache = (key, cachedData) => {
cache.set(key, {
...cachedData
});
};
const getCache = key => {
return cache.get(key);
};
+const clearCache = key => {
+ if (key) {
+ const cacheKeys = Array.isArray(key) ? key : [key];
+ cacheKeys.forEach(cacheKey => cache.delete(cacheKey));
+ } else {
+ cache.clear();
+ }
+};
export { getCache, setCache, clearCache };
ahooks 提供了一个 clearCache 方法,可以清除指定 cacheKey 的缓存数据。