Image and text details WeChat applet data cache

Source: Internet
Author: User
Each applet can have its own local cache. This article mainly introduces the applet-detailed description of the data cache, which can be set, retrieved, and cleared by functions, for more information, see. Each applet can have its own local cache. This article mainly introduces the applet-detailed description of the data cache, which can be set, retrieved, and cleared by functions, for more information, see.

Each applet can have its own local cache. setStorage (wx. setStorageSync), wx. getStorage (wx. getStorageSync), wx. clearStorage (wx. clearStorageSync) allows you to set, retrieve, and clear local caches. The local cache size is up to 10 MB.

Note: localStorage is permanently stored, but it is not recommended that all key information be stored in localStorage to prevent users from changing devices.

Wx. setStorage (OBJECT)

Storing data in the specified key in the local cache overwrites the content corresponding to the original key. this is an asynchronous interface.

OBJECT parameter description:

wx.setStorage({ key:"key" data:"value"})

Wx. setStorageSync (KEY, DATA)

Storing data in the specified key in the local cache will overwrite the content corresponding to the original key, which is a synchronous interface.

OBJECT parameter description:

try {  wx.setStorageSync('key', 'value')} catch (e) {  }

Wx. getStorage (OBJECT)

Asynchronously retrieves the content of a specified key from the local cache.

OBJECT parameter description:

wx.getStorage({ key: 'key', success: function(res) {   console.log(res.data) } })

Wx. getStorageSync (KEY)

Synchronously obtains the content of the specified key from the local cache.

Parameter description:

try { var value = wx.getStorageSync('key') if (value) {   // Do something with return value }} catch (e) { // Do something when catch error}

Wx. getStorageInfo (OBJECT)

Asynchronously obtains information about the current storage.

OBJECT parameter description:

wx.getStorageInfo({ success: function(res) {  console.log(res.keys)  console.log(res.currentSize)  console.log(res.limitSize) }})

Wx. getStorageInfoSync

Synchronously obtain information about the current storage

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)

Asynchronously removes the specified key from the local cache.

OBJECT parameter description:

wx.removeStorage({ key: 'key', success: function(res) {  console.log(res.data) } })

Wx. removeStorageSync (KEY)

Synchronously remove a specified key from the local cache.

Parameter description:

try { wx.removeStorageSync('key')} catch (e) { // Do something when catch error}

Wx. clearStorage ()
Clear the local data cache.

Sample code:


wx.clearStorage()

Wx. clearStorageSync ()

Clean up local data cache synchronously

Sample code:


try {  wx.clearStorageSync()} catch(e) { // Do something when catch error}

The above is the detailed description of the small program data cache. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.