当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 微信小程序缓存过期时间的使用详情

微信小程序缓存过期时间的使用详情

2019年07月21日  | 移动技术网IT编程  | 我要评论

关于本地缓存

1.wx.setstorage(wx.setstoragesync)、wx.getstorage(wx.getstoragesync)、wx.clearstorage(wx.clearstoragesync)可以对本地缓存进行设置、获取和清理。本地缓存最大为10mb

2.localstorage 是永久存储

相应的api----------

wx.setstorage(object)

wx.getstorage(object)

wx.getstorageinfo(object)

wx.removestorage(object)

wx.setstoragesync(key,data)

 

wx.getstoragesync(key)

wx.getstorageinfosync

wx.clearstorage()

wx.clearstoragesync() ...

api的具体使用详见官方文档

微信小程序缓存过期时间

 /*
  *创建缓存
  * @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
 },

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网