vue-admin-core
Version:
A Component Library for Vue 3
36 lines (33 loc) • 800 B
JavaScript
;
const cache = /* @__PURE__ */ new Map();
const setCache = (key, cacheTime, cachedData) => {
const currentCache = cache.get(key);
if (currentCache == null ? void 0 : currentCache.timer) {
clearTimeout(currentCache.timer);
}
let timer;
if (cacheTime > -1) {
timer = setTimeout(() => {
cache.delete(key);
}, cacheTime);
}
cache.set(key, {
...cachedData,
timer
});
};
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();
}
};
exports.clearCache = clearCache;
exports.getCache = getCache;
exports.setCache = setCache;
//# sourceMappingURL=cache.js.map