This commit is contained in:
Jan Prochazka
2021-09-25 12:08:20 +02:00
parent f92153d957
commit 065af0b4a8
6 changed files with 76 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
const cache = {};
export function getLocalStorage(key) {
if (key in cache) return cache[key];
const item = localStorage.getItem(key);
if (item) {
const res = JSON.parse(item);
cache[key] = res;
return res;
}
return undefined;
}
export function setLocalStorage(key, value) {
localStorage.setItem(key, JSON.stringify(value));
delete cache[key];
}
export function removeLocalStorage(key) {
localStorage.removeItem(key);
delete cache[key];
}