Home  >  Article  >  WeChat Applet  >  How to implement write cache and read cache for small programs

How to implement write cache and read cache for small programs

王林
王林forward
2021-03-16 09:52:162526browse

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete