What kind of data is suitable to be stored in the cache?

I am currently learning the development of WeChat Mini Programs. For caching, I have the following questions:
1. What kind of data is suitable for caching?
2. What kind of environment is suitable for Synchronize caching and what kind of environment is suitable for asynchronous caching?
looking forward to reply, thank you!


have done some Mini Program, but also have a little experience. for reference only:
first of all, understand that Mini Program is a product of mobile, and cache is also on mobile, such as mobile phones. Of course, the memory of the mobile phone cannot be compared with that of the PC, so although the cache is a good thing, it still needs to be used in the right place. At the same time, you also need to understand Mini Program's global variables, many times the global variables can replace the cache.
1. What kind of data is suitable for caching?

  • static data, picture address, etc. for example, if you have a list where the data is obtained from the server, a lot of images and content will be loaded, and these pictures and data will not be updated in a short period of time. Then caching is recommended. In this way, except that the user calls the meeting for the first time to request the server, it can be obtained directly from the cache later, which will greatly speed up the loading speed.
  • Page jump carries data . It is usually used in the scene of jump details. For example, for a list of items, you need to jump to the details page of an item after clicking on it. In order to speed up the response, you do not need to request the data of the corresponding product every time you jump to the details page, but store the data of this item in the cache when you click to jump, and the details page can obtain the cache directly.
  • data that is needed globally. this is actually very similar to the function of global variables, but how to choose depends on the needs of the actual project.

2. How to use Synchronize and asynchronous cache?
you need to understand the difference between the two before using it: Synchronize cache will block the current task, but asynchrony will not.

  • Synchronize usage scenario: when the data processing behind depends on the previous cached data. When my business has to get the data in the cache first, and then perform subsequent operations based on this data, I use Synchronize cache. This avoids the situation where the later code has been executed without getting the previously cached data.
  • Asynchronous usage scenario : the first point is, of course, contrary to Synchronize. It can be used freely when there is no dependency. The second point is that when getting multiple cache objects, it is better to use asynchrony. If you need to get many cache objects at a time, asynchronism can avoid the impact of blocking.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e7ae-e968.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e7ae-e968.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?