一个用于处理我们TS项目中缓存类
export class Cache {
static instance: Cache;
time_zone: Array<any>;
private constructor() {}
static getInstance(): Cache {
if (!this.instance) {
this.instance = new Cache();
}
return this.instance;
}
clearCache() {
this.time_zone = null;
}
}
每增加一种cache直接定义一个变量就好,如 time_zone
用法如下,Cache 实例已经定义成静态static的了,所以用的时候不需要new
import {Cache } from '.cache';
// 赋值
Cache.getInstance().time_zone = []
// 使用
Cache.getInstance().time_zone
网友评论