一级做爰片a视频网站试看,商标名称查询系统,xshell如何做网站,繁体网站模板localstorage原本是不带过期时间的#xff0c;xijs提供了一个带过期时间封装的store工具#xff0c;但是用起来因为文档基本等于没有#xff0c;所以干脆直接封装一个用#xff0c;其中ttl是过期时间#xff0c;以毫秒计算。
// 设置function setLocalStorageWithExpiry(…localstorage原本是不带过期时间的xijs提供了一个带过期时间封装的store工具但是用起来因为文档基本等于没有所以干脆直接封装一个用其中ttl是过期时间以毫秒计算。
// 设置function setLocalStorageWithExpiry(key, value, ttl) {const now new Date()// ttl : 毫秒const item {value: value,expiry: now.getTime() ttl,}localStorage.setItem(key, JSON.stringify(item))}
// 获取valuefunction getLocalStorageWithExpiry(key) {const itemValue localStorage.getItem(key)if (!itemValue) {return null}const item JSON.parse(itemValue)const now new Date()if (now.getTime() item.expiry) {localStorage.removeItem(key)return null}return item.value}
// 删除过期的所有keyfunction batchRemoveExpiredKeys() {const keys Object.keys(localStorage);// 过滤出过期的keyconst expiredKeys keys.filter(key {const value localStorage.getItem(key);try {const data JSON.parse(value);return data.expirey Date.now() data.expirey;} catch (e) {return false;}});// 删除过期的keyexpiredKeys.forEach(key {localStorage.removeItem(key);});}