同一个微信用户,同一个小程序 storage 上限为 10MB。storage 以用户维度隔离,同一台设备上,A 用户无法读取到 B 用户的数据。
操作缓存的方法:
1、wx.setStorage/wx.setStorageSync、
2、wx.getStorage/wx.getStorageSync、
3、wx.clearStorage/wx.clearStorageSync,
4、wx.removeStorage/wx.removeStorageSync ,Sync 是同步版本。
示例
//设置某个缓存
wx.setStorage({
key: 'key',
data: 'value'
})
//清除某个缓存
wx.getStorage({
key: 'key',
success(res) {
console.log(res.data)
}
})
//清理本地缓存
wx.clearStorage()
//从本地缓存中移除指定 key
wx.removeStorage({
key: 'key',
success(res) {
console.log(res)
}
})