const Cache = {
	// 设置缓存(expire为缓存时效，单位秒)
	set(key, value, expire=360000000) {
		console.log(key,value);
		let data = {
			expire: expire ? (this.time() + expire) : this.time() +360000000,
			value
		}
		if (typeof data === 'object')
			data = JSON.stringify(data);
		try {
			uni.setStorageSync(key, data)
		} catch (e) {
			return;
		}
	},
	get(key) {
		try {
			let data = uni.getStorageSync(key)
			const {
				value,
				expire
			} = JSON.parse(data)
			if (expire && expire < this.time()) {
				uni.removeStorageSync(key)
				return;
			} else {
				return value
			}
		} catch (e) {
			return;
		}
	},
	//获取当前时间
	time() {
		return Math.round(new Date() / 1000);
	},
	remove(key) {
		if (key) {
			uni.removeStorageSync(key)
		}
	}
}

export default Cache;
