1 Star 0 Fork 431

java8dj/likeadmin(Python版)- MIT协议-免费任意商用- 管理后台_小程序_手机H5_PC端_uni-app

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache.ts 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
Yuuu_x 提交于 2022-11-21 10:49 +08:00 . 1.0
const cache = {
key: 'like_admin_',
//设置缓存(expire为缓存时效)
set(key: string, value: any, expire?: string) {
key = this.getKey(key)
let data: any = {
expire: expire ? this.time() + expire : '',
value
}
if (typeof data === 'object') {
data = JSON.stringify(data)
}
try {
window.localStorage.setItem(key, data)
} catch (e) {
return null
}
},
get(key: string) {
key = this.getKey(key)
try {
const data = window.localStorage.getItem(key)
if (!data) {
return null
}
const { value, expire } = JSON.parse(data)
if (expire && expire < this.time()) {
window.localStorage.removeItem(key)
return null
}
return value
} catch (e) {
return null
}
},
//获取当前时间
time() {
return Math.round(new Date().getTime() / 1000)
},
remove(key: string) {
key = this.getKey(key)
window.localStorage.removeItem(key)
},
getKey(key: string) {
return this.key + key
}
}
export default cache
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/java8dj/likeadmin_python.git
git@gitee.com:java8dj/likeadmin_python.git
java8dj
likeadmin_python
likeadmin(Python版)- MIT协议-免费任意商用- 管理后台_小程序_手机H5_PC端_uni-app
master

搜索帮助