關于本地緩存
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 },
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com