Home > WeChat Applet > Mini Program Development > How to implement write cache and read cache for small programs

How to implement write cache and read cache for small programs

王林
Release: 2021-03-16 09:52:16
forward
2609 people have browsed it

How to implement write cache and read cache for small programs

Purpose:

Click the button in the picture below to change the journal content. When the journal changes to the first issue, the button to change to the next issue will become disabled. When the journal is the latest issue, the button to change to the previous issue will become disabled.

How to implement write cache and read cache for small programs

Implementation ideas:

1. First determine whether it is the first issue

How to implement write cache and read cache for small programs

2. Determine whether it is the latest issue

Firstly, we find that there is an interface to get the latest issue, and the latestIndex of the latest issue is in the document.

After clicking the button on the left, the index will change, and it will also overwrite the lastIndex loaded when the page is initialized. At this time, you need to save the latestIndex into the cache, and then compare the index with the latestIndex, which will always be the latest issue. Otherwise it is not.

(Learning video sharing: php video tutorial)

The steps are as follows:

1. Store in cache

How to implement write cache and read cache for small programs

2. Complete the cache writing in the callback function and pass in the index of the latest journal.

How to implement write cache and read cache for small programs

3. Read the cache

How to implement write cache and read cache for small programs

4. Compare the latestIndex and index of the read cache

How to implement write cache and read cache for small programs

5. Latest and first are defined in the classic data of the page.

How to implement write cache and read cache for small programs

Update latest and first in the click event of the page button. .

How to implement write cache and read cache for small programs

Related recommendations: 小program development tutorial

The above is the detailed content of How to implement write cache and read cache for small programs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template