@slan-health/taro-vueuse
Version:
taro vue版本hooks
36 lines (35 loc) • 915 B
JavaScript
import { isNil } from "./index.js";
const CACHE_MAP = /* @__PURE__ */ new Map();
const getCache = (cacheKey) => {
if (isNil(cacheKey)) return;
const data = CACHE_MAP.get(cacheKey);
return data;
};
const setCache = (cacheKey, cacheTime, data) => {
const oldCache = CACHE_MAP.get(cacheKey);
if (oldCache == null ? void 0 : oldCache.timer) {
clearTimeout(oldCache.timer);
}
const timer = setTimeout(() => CACHE_MAP.delete(cacheKey), cacheTime);
CACHE_MAP.set(cacheKey, {
...data,
timer
});
};
const clearCache = (cacheKey) => {
var _a;
if (cacheKey) {
const timer = (_a = CACHE_MAP.get(cacheKey)) == null ? void 0 : _a.timer;
timer && clearTimeout(timer);
CACHE_MAP.delete(cacheKey);
} else {
CACHE_MAP.forEach((i) => i.timer && clearTimeout(i.timer));
CACHE_MAP.clear();
}
};
export {
clearCache,
getCache,
setCache
};
//# sourceMappingURL=cache.js.map