微信小程序如何调整缓存过期时间的具体操作步骤?

更新于
2026-10-02 11:11:14
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计394个文字,预计阅读时间需要2分钟。

关于本地缓存,`wx.setStorage`(或`wx.setStorageSync`)用于设置本地缓存,`wx.getStorage`(或`wx.getStorageSync`)用于获取本地缓存,`wx.clearStorage`(或`wx.clearStorageSync`)用于清理本地缓存。本地缓存最大为10MB。`localStorage`则是永久存储。

关于本地缓存

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 },

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。

标签:使用详情

本文共计394个文字,预计阅读时间需要2分钟。

关于本地缓存,`wx.setStorage`(或`wx.setStorageSync`)用于设置本地缓存,`wx.getStorage`(或`wx.getStorageSync`)用于获取本地缓存,`wx.clearStorage`(或`wx.clearStorageSync`)用于清理本地缓存。本地缓存最大为10MB。`localStorage`则是永久存储。

关于本地缓存

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 },

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。

标签:使用详情