visus-plus/web-app/src/utils/cachedInfoUtils.jsx

18 lines
522 B
JavaScript

const cacheInfo = (key, value) => {
localStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(`${key}Timestamp`, Date.now().toString());
};
const getCachedInfo = (key) => {
const data = localStorage.getItem(key);
if (!data) return null;
return JSON.parse(data);
};
const getCacheTimestamp = (key) => {
const timestamp = localStorage.getItem(`${key}Timestamp`);
if (!timestamp) return null;
return parseInt(timestamp);
};
export {cacheInfo, getCachedInfo, getCacheTimestamp};