In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the method of data caching in WeChat Mini Programs". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn "the method of data caching in WeChat Mini Programs".
Each WeChat Mini Programs can have its own local cache, which can be set, acquired and cleaned through wx.setStorage (wx.setStorageSync), wx.getStorage (wx.getStorageSync) and wx.clearStorage (wx.clearStorageSync). The maximum local cache is 10MB.
Note: localStorage is permanently stored, but we do not recommend storing all critical information in localStorage in case users change devices.
Wx.setStorage (OBJECT)
Storing the data in the key specified in the local cache will overwrite the corresponding content of the original key, which is an asynchronous interface.
OBJECT parameter description:
Sample code
Wx.setStorage ({key: "key" data: "value"})
Wx.setStorageSync (KEY,DATA)
Storing the data in the key specified in the local cache will overwrite the corresponding content of the original key, which is a synchronization interface.
OBJECT parameter description:
Sample code
Try {wx.setStorageSync ('key',' value')} catch (e) {}
Wx.getStorage (OBJECT)
Gets the content corresponding to the specified key asynchronously from the local cache.
OBJECT parameter description:
Sample code:
Wx.getStorage ({key: 'key', success: function (res) {console.log (res.data)}})
Wx.getStorageSync (KEY)
Gets the content corresponding to the specified key synchronously from the local cache.
Parameter description:
Sample code:
Try {var value = wx.getStorageSync ('key') if (value) {/ / Do something with return value}} catch (e) {/ / Do something when catch error}
Wx.getStorageInfo (OBJECT)
Obtain information about the current storage asynchronously
OBJECT parameter description:
Success return parameter description:
Sample code:
Wx.getStorageInfo ({success: function (res) {console.log (res.keys) console.log (res.currentSize) console.log (res.limitSize)})
Wx.getStorageInfoSync
Get the information about the current storage synchronously
Sample code:
Try {var res = wx.getStorageInfoSync () console.log (res.keys) console.log (res.currentSize) console.log (res.limitSize)} catch (e) {/ / Do something when catch error}
Wx.removeStorage (OBJECT)
Removes the specified key asynchronously from the local cache.
OBJECT parameter description:
Sample code:
Wx.removeStorage ({key: 'key', success: function (res) {console.log (res.data)}})
Wx.removeStorageSync (KEY)
Removes the specified key synchronously from the local cache.
Parameter description:
Sample code:
Try {wx.removeStorageSync ('key')} catch (e) {/ / Do something when catch error}
Wx.clearStorage ()
Clean up the local data cache.
Sample code:
Wx.clearStorage ()
Wx.clearStorageSync ()
Synchronously clean up the local data cache
Sample code:
Try {wx.clearStorageSync ()} catch (e) {/ / Do something when catch error} Thank you for your reading. This is the content of "the method of data caching in WeChat Mini Programs". After the study of this article, I believe you have a deeper understanding of the method of data caching in WeChat Mini Programs, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.