small 2019-11-19
微信小程序缓存过期时间
/* *创建缓存 * @param e 缓存名称 * @param t 缓存值 * @param i 缓存时间 */ setCache: function(e, t, i) { var n = +new Date / 1000, a = true, o = { expire: i ? n + parseInt(i) : 0, value: t }; try { wx.setStorageSync(e, o) } catch (e) { a = false } return a }, /* *获取缓存 * @param e 缓存名称 * @param t 缓存值 */ getCache: function(e, t) { var i = +new Date / 1000, n = ""; i = parseInt(i); try { n = wx.getStorageSync(e), n.expire > i || 0 == n.expire ? n = n.value : (n = "", this.removeCache(e)) } catch (e) { n = void 0 === t ? "" : t } return n = n || "" }, /* *清除缓存 * @param e 缓存名称 */ removeCache: function(e) { var t = true; try { wx.removeStorageSync(e) } catch (e) { t = false } return t },