vue-admin-core
Version:
A Component Library for Vue 3
32 lines (30 loc) • 738 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();
}
};
export { clearCache, getCache, setCache };
//# sourceMappingURL=cache.mjs.map