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

How to install MySQL database on Ubuntu

Ubuntu is a free and open source desktop PC opera...

Example of how to configure nginx in centos server

Download the secure terminal MobaXterm_Personal F...

Common commands for mysql authorization, startup, and service startup

1. Four startup methods: 1.mysqld Start mysql ser...

Which one should I choose between MySQL unique index and normal index?

Imagine a scenario where, when designing a user t...

Detailed explanation of the usage of Object.assign() in ES6

Table of contents 2. Purpose 2.1 Adding propertie...

Detailed steps for installing and configuring MySQL 8.0 on CentOS 7.4 64-bit

Step 1: Get the MySQL YUM source Go to the MySQL ...

How to use the Linux seq command

1. Command Introduction The seq (Sequence) comman...

Randomly generate an eight-digit discount code and save it to the MySQL database

Currently, many businesses are conducting promoti...

Detailed explanation of JS browser event model

Table of contents What is an event A Simple Examp...

Explanation of MySQL index types Normal, Unique and Full Text

MySQL's index types include normal index, uni...

K3s Getting Started Guide - Detailed Tutorial on Running K3s in Docker

What is k3d? k3d is a small program for running a...

Use iptables and firewalld tools to manage Linux firewall connection rules

Firewall A firewall is a set of rules. When a pac...

Not all pop-ups are rogue. Tips on designing website pop-ups

Pop-up news is common in domestic Internet servic...

Solutions to MySQL batch insert and unique index problems

MySQL batch insert problem When developing a proj...