有些场景,异步缓存不适合,必须同步去写入缓存,总结如下(可以避免一些坑)
try{
wx.setStorageSync(key, value);
} catch (e) {
wx.setStorage(key, value);
}
},
xbGetStorage: function (key) {
try{
return wx.getStorageSync(key);
}catch (e) {
return wx.getStorage(key);
}
},
xbRemoveStorage: function (key) {
try{
wx.removeStorage(key)
}catch (e){
wx.removeStorage(key);
}
},
小程序清除缓存
可以用wx.removeStorage,或者wx.removeStorageSync来清除小程序缓存,当然,你也可以从小程序列表中,把小程序删除,本地缓存就没有了。同一个小程序的开发版、体验版、线上版的缓存是共用的,你需要同时删除这三个版本的小程序,缓存才会被删除。