小程序 缓存过期问题

时间:2019-06-20 18:47:10   收藏:0   阅读:174
1 module.exports = {
2   set: function(k, v, time) {
3     var effTime = parseInt(Date.parse(new Date())) + 86400000 * time; //有效时期时间戳
4     wx.setStorageSync(k, v ? v : effTime);
5   }
6 };
7 //86400000 就是一天等于多少毫秒

 

1  // 点击推送通知按钮设置7天有效时间缓存
2   openNotice: function() {
3     Storage.set(‘oldStorTime‘, ‘‘, 7); 
4   }

 

1 //判断
2 Off:function(){
3      var currentTime = Date.parse(new Date()); //当前时间戳
4      if (currentTime < wx.getStorageSync(‘oldStorTime‘)) {
5        //console.log("缓存时间有效")
6      } else {
7       //console.log("缓存时间已过期")
8      }
9 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!