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.
Implementation ideas:
1. First determine whether it is the first issue
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
2. Complete the cache writing in the callback function and pass in the index of the latest journal.
3. Read the cache
4. Compare the latestIndex and index of the read cache
5. Latest and first are defined in the classic data of the page.
Update latest and first in the click event of the page button. .
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!