mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 07:56:01 +00:00
This commit is contained in:
22
packages/web/src/utility/storageCache.js
Normal file
22
packages/web/src/utility/storageCache.js
Normal 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];
|
||||
}
|
||||
Reference in New Issue
Block a user