UNPKG

vue-hooks-plus

Version:
38 lines (37 loc) 995 B
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); 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 = void 0; if (cacheTime > -1) { timer = setTimeout(() => { cache.delete(key); }, cacheTime); } cache.set(key, { ...cachedData, timer }); }; const getCache = (key) => { return cache.get(key); }; const getCacheAll = () => { return Object.fromEntries(cache.entries()); }; 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.getCacheAll = getCacheAll; exports.setCache = setCache;