微信小程序数据缓存API整理
2017-06-06 17:20
330 查看
1、wx.getStorage(OBJECT)
从本地缓存中异步获取指定 key 对应的内容wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) } , fail: function(){}, complete: function(){} })
2、wx.setStorageSync(KEY,DATA)
将 data 存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个同步接口try { wx.setStorageSync('key', 'value') } catch (e) { }
3、wx.getStorage(OBJECT)
从本地缓存中异步获取指定 key 对应的内容wx.getStorage({ key: 'key', success: function(res) { console.log(res.data) }, fail: function(){}, complete: function(){} })
4、wx.getStorageSync(KEY)
从本地缓存中同步获取指定 key 对应的内容try { var value = wx.getStorageSync('key') if (value) { // Do something with return value } } catch (e) { // Do something when catch error }
5、wx.getStorageInfo(OBJECT)
异步获取当前storage的相关信息wx.getStorageInfo({ success: function(res) { console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) }, fail: function(){}, complete: function(){} })
6、wx.getStorageInfoSync
同步获取当前storage的相关信息try { var res = wx.getStorageInfoSync() console.log(res.keys) console.log(res.currentSize) console.log(res.limitSize) } catch (e) { // Do something when catch error }
7、wx.removeStorage(OBJECT)
从本地缓存中异步移除指定 keywx.removeStorage({ key: 'key', success: function(res) { console.log(res.data) }, fail: function(){}, complete: function(){} })
8、wx.removeStorageSync(KEY)
从本地缓存中同步移除指定 keytry { wx.removeStorageSync('key') } catch (e) { // Do something when catch error }
9、wx.clearStorage()
清理本地数据缓存wx.clearStorage()
10、wx.clearStorageSync()
同步清理本地数据缓存try { wx.clearStorageSync() } catch(e) { // Do something when catch error }
本地数据缓存大小限制为10MB。
相关文章推荐
- 微信小程序本地缓存数据增删改查实例详解
- 微信小程序之数据缓存的实例详解
- 微信小程序之数据缓存
- 小程序文档整理之 -- API(数据分析)
- 微信小程序API之网络(三)下载数据
- 微信小程序 - 数据缓存 模拟 cookie
- 微信小程序数据缓存
- 微信小程序API之网络(二)上传数据
- 微信小程序之数据缓存
- 微信小程序本地缓存数据增删改查
- 微信小程序之数据缓存
- ASP.NET整理:缓存机制之数据缓存
- android例子程序(ApiDemo)的简单分类整理
- note : OD操作整理-API断点的设置;寄存器的修改;数据的查看
- 关于LittleSis网站数据API的简单整理
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- 禁止ajax缓存获取程序最新数据的方法
- 程序数据层研究(三) NHibernate中的API
- jsp程序不从缓存里读取数据
- PHP应用系列之三:用Memcache守护程序把数据缓存到内存中