Application and implementation of data cache mechanism for small programs

Application and implementation of data cache mechanism for small programs

Mini Program Data Cache Related Knowledge

Data cache: caches data so that when the applet is opened again after exiting, the last saved data can be read from the cache. The commonly used data cache APIs are shown in the following table:

insert image description here

Note : Stores the data at the specified key in the local cache. The original content corresponding to the key will be overwritten. The data will always be available unless the user actively deletes it or the system clears it due to storage space reasons. The maximum length of data stored in a single key is 1MB, and the upper limit for all data storage is 10MB.

parameter

For detailed parameters, please see
https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorage.html

Save data cache

// Save data cache wx.setStorage({
  key: 'key', // The key specified in the local cache
  data: 'value', // content to be stored (supports object or string)
  success: res => {}, // callback function for successful interface call	
  fail: res => {} // callback function for interface call failure})

Get data cache

// Get data cache wx.getStorage({
  key: 'key', // The key specified in the local cache
  success: res => { // Callback function of successful interface call console.log(res.data)
  }, 
  fail: res => {} // callback function for interface call failure})

Example: Storing and retrieving in onLoad

// pages/test/test.js
Page({
  onLoad: function(options) {
    // Save data cache wx.setStorage({
      key: 'key', // The key specified in the local cache
      data: 'value', // content to be stored (supports object or string)
      success: res => {
        // Get data cache wx.getStorage({
          key: 'key', // The key specified in the local cache
          success: res => { // Callback function of successful interface call console.log(res.data)
          },
          fail: res => { } // callback function for interface call failure})
      }, // callback function for successful interface call fail: res => {} // callback function for failed interface call })
  }
})

This is the end of this article about the application and implementation of the mini-program data caching mechanism. For more relevant mini-program data caching content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • WeChat Mini Program - Detailed Explanation of Data Caching
  • WeChat applet cache (local cache, asynchronous cache, synchronous cache) detailed explanation
  • How to clean up the local cache of the applet
  • WeChat applet data cache example detailed explanation
  • WeChat applet local cache data addition, deletion, modification and query example
  • Detailed explanation of writing and reading cache in WeChat applet
  • How to play cached audio files in WeChat applet in IOS
  • WeChat applet development data storage parameter transfer data cache
  • How to modify a single data in the local cache key in WeChat applet

<<:  Windows 2019 Activation Tutorial (Office2019)

>>:  Detailed explanation of the definition and usage of MySQL stored functions (custom functions)

Recommend

MySQL database implements OLTP benchmark test based on sysbench

Sysbench is an excellent benchmark tool that can ...

Error mysql Table 'performance_schema...Solution

The test environment is set up with a mariadb 5.7...

JavaScript to achieve magnifying glass effect

This article shares the specific code for JavaScr...

jQuery implements shopping cart function

This article example shares the specific code of ...

XHTML Getting Started Tutorial: XHTML Hyperlinks

It is no exaggeration to say that hyperlinks conne...

Mysql backup multiple database code examples

This article mainly introduces the Mysql backup m...

Detailed explanation of MySQL database isolation level and MVCC

Table of contents 1. Isolation Level READ UNCOMMI...

Detailed analysis of MySQL instance crash cases

[Problem description] Our production environment ...

MySQL dual-master (master-master) architecture configuration solution

In enterprises, database high availability has al...

Examples of using html unordered list tags and ordered list tags

1. Upper and lower list tags: <dl>..</dl...

js to achieve a simple magnifying glass effect

This article shares the specific code of js to ac...

Why is the disk space still occupied after deleting table data in MySQL?

Table of contents 1. Mysql data structure 2. The ...