微信小顺序缓存逾期时候

微信小顺序缓存逾期时候

 /*
   *建立缓存
   * @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
  },
    原文作者:爱晒太阳的雪糕
    原文地址: https://segmentfault.com/a/1190000019147868
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞