class WHCache {
constructor(isLocal = true) {
this.storage = isLocal ? localStorage : sessionStorage;
}
setItem(key, value) {
if (value) {
this.storage.setItem(key, JSON.stringify(value));
}
}
getItem(key) {
let value = this.storage.getItem(key);
if (value) {
value = JSON.parse(value);
return value;
}
}
removeItem(key) {
this.storage.remove(key);
}
clear(key) {
this.storage.clear(key);
}
key(index) {
return this.storage.key(index);
}
length() {
return this.storage.length;
}
}
const local = new WHCache();
const session=new WHCache(false);
export {
local,session
}