Open JeromeD3 opened 1 year ago
import * as cache from '../utils/cache';
import useCreation from '../../../useCreation';
const useCachePlugin = (fetchInstance, {
cacheKey,
staleTime = 0,
+ cacheTime = 5 * 60 * 1000,
+ setCache: customSetCache,
+ getCache: customGetCache
}) => {
const _setCache = (key, cachedData) => {
+ if (customSetCache) {
+ customSetCache(cachedData);
+ } else {
cache.setCache(key, cacheTime, cachedData);
+ }
};
const _getCache = (key, params) => {
+ if (customGetCache) {
+ return customGetCache(params);
+ }
return cache.getCache(key);
};
map
中
有的时候我们不想让数据缓存在一个
map
中,想通过配置 setCache 和 getCache,可以自定义数据缓存,比如可以将数据存储到 localStorage、IndexDB 等。