微信小程序-详细数据缓存

每一个微信的小程序可以有它自己的本地缓存。它可以设置,获得干净的本地缓存通过wx.setstorage(Wx。setstoragesync),wx.getstorage(Wx。getstoragesync)和wx.clearstorage(Wx。clearstoragesync)最大的本地缓存是10MB。

注:localStorage是永久保存的,但我们不建议关键信息存在于所有localStorage防止用户更改设备。

Wx.setStorage(对象)



将数据存储在本地缓存中指定的密钥中,将覆盖密钥的原始内容,该密钥是异步接口。

对象参数描述:

示例代码


Wx.setStorage({
键:键
数据:值
})



Wx.setStorageSync(关键数据)

数据存储在本地缓存中指定的密钥中,该密钥将覆盖密钥的原始内容,密钥是同步接口。

对象参数描述:

示例代码


{试
Wx.setStorageSync(关键的、价值的)
} catch(e){
}


Wx.getStorage(对象)



异步地从本地缓存检索指定键的相应内容。

对象参数描述:

示例代码:


Wx.getStorage({
关键:关键的,
成功:函数(RES){
console.log(res.data)
}
})


Wx.getStorageSync(重点)



指定的密钥的相应内容是从本地缓存同步获得的。

参数描述:

示例代码:


{试
VaR值= wx.getstoragesync(关键的)
如果(值){
具有返回值的东西
}
} catch(e){
当捕获错误时做某事
}


Wx.getStorageInfo(对象)



异步获取当前存储的相关信息

对象参数描述:

成功返回参数描述:

示例代码:


Wx.getStorageInfo({
成功:函数(RES){
console.log(res.keys)
console.log(res.currentsize)
console.log(res.limitsize)
}
})


wx.getstorageinfosync



同步对当前存储信息的访问

示例代码:


{试
VaR既= wx.getstorageinfosync()
console.log(res.keys)
console.log(res.currentsize)
console.log(res.limitsize)
} catch(e){
当捕获错误时做某事
}


Wx.removeStorage(对象)



异步从本地缓存中移除指定的键。

对象参数描述:

示例代码:


Wx.removeStorage({
关键:关键的,
成功:函数(RES){
console.log(res.data)
}
})


Wx.removeStorageSync(重点)



从本地缓存中删除指定的键。

参数描述:

示例代码:


{试
Wx.removeStorageSync(关键的)
} catch(e){
当捕获错误时做某事
}


Wx.clearStorage()

清理本地数据缓存。

示例代码:


Wx.clearStorage()


Wx.clearStorageSync()



本地数据缓存的同步清理

示例代码:


{试
Wx.clearStorageSync()
} catch(e){
当捕获错误时做某事
}


以上是本文的全部内容,希望能对您有所帮助,希望大家多多支持。