A system for preventing cache avalanches
Through the combination of data query parser, data update parser and cache time processor, weight calculation and active refresh mechanism are used to solve the problem of setting cache expiration time, avoid database pressure, simplify cache management, and are suitable for various scenarios.
Patent Information
- Application Number
- CN202110894079.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-05
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-08-05
AI Technical Summary
It is difficult to effectively set the cache expiration time with the existing technology. As a result, when a large amount of cached data fails at the same time, it puts huge pressure on the database and increases the risk of downtime.
The data query parser records the number of queries of the monitoring table. The data update parser updates high-frequency query data according to specific scenarios. The cache time processor uses subjective and objective weights to calculate the cache expiration time and uses an active refresh mechanism to avoid cache data failures. Database pressure.
It effectively avoids database pressure caused by the collective failure of large batches of cached data, reduces the risk of database downtime, simplifies cache management, and is suitable for various cache scenarios.
Smart Images

Figure CN113688155B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of cache security settings, in particular to a system for preventing cache avalanche. Background Art
[0002] With the rapid development of the Internet industry, more and more applications are appearing in everyone's vision. In order for an application to attract users, in addition to the usage functions that users care about, the response efficiency of the application is also a very important factor, because it is closely related to the user experience. At present, to improve the response efficiency of applications, people often use the method of caching data, that is, caching the data that is frequently used and less frequently updated. When users request this data, they directly obtain the data from the cache and then feed back the corresponding results to the user. Compared with the traditional method of reading data from the database and then feeding it back to the user, the method of caching part of the data can indeed improve the response efficiency of the application. However, the data in the cache is time-sensitive. When a large amount of cached data fails at a certain moment, the request will still go to the database to obtain the corresponding information from the database. This process will bring huge pressure to the database, and there will be a risk of database down, which will eventually make the application unavailable.
[0003] Based on the above analysis, how to set the effective time of the cache to avoid the scenario of a large amount of cached data being out of date is a technical problem that needs to be solved. Summary of the invention
[0004] The technical task of the present invention is to provide a system for preventing cache avalanche in view of the above shortcomings, so as to solve the technical problem of how to set the effective time of the cache to avoid the scenario of a large amount of cache data being outdated.
[0005] A system for preventing cache avalanche of the present invention is used to dynamically calculate the specific expiration time of current data according to the existing cache expiration time, and control the expiration time through a human weight coefficient. The system includes:
[0006] A data query parser, which is used to record the number of data queries for each monitoring table, take data that meets the predetermined query frequency as high-frequency query data, and cache the high-frequency query data;
[0007] A data update parser, which acts on cached high-frequency query data. When updating a certain high-frequency query data, the data update parser is used to update the data according to a specific scenario;
[0008] A cache time processor, wherein the cache time processor is used to calculate the expiration time that needs to be set for the data based on the weight of the data, wherein the weight of the data includes a subjective weight and an objective weight, wherein the subjective weight is a weight coefficient set manually, and the objective weight is a weight coefficient collected through a program.
[0009] Preferably, the table information of the monitoring table is manually configured in advance by an administrator;
[0010] The data query parser is used to record the number of data queries of the monitoring table manually configured in advance by the administrator.
[0011] Preferably, if the updated data is stored separately in the cache, the data update parser is used to directly obtain specific data from the cache and update the obtained data to the latest data, and call the cache time processor to obtain the cache expiration time to be set, and cache the latest data.
[0012] Preferably, if the updated data is stored together with other data in a value corresponding to a key, the data update parser is used to update the data according to the index position of the current data in the list.
[0013] Preferably, the artificially set weight coefficient is a weight coefficient of the data of the monitoring table manually set by an administrator, and a larger weight coefficient indicates a longer cache expiration time set for the table data;
[0014] The objective weight coefficient is a coefficient calculated by the access frequency of the data. The higher the access frequency of the data, the greater the objective weight coefficient of the data.
[0015] Preferably, the cache time processor is used to calculate the expiration time that needs to be set for the data according to the weight of the data, including the following operations:
[0016] Set the percentage of subjective weight and objective weight in the weight coefficient system to calculate the final weight coefficient of the target data;
[0017] Setting a cache expiration time according to the weight coefficient, and recording the cache expiration time through a cache time processor;
[0018] After calculating the cache expiration time, the cache time processor retrieves the number of times the current cache expiration time occurs from the currently stored cache expiration time set. If the number of times the cache expiration time occurs is high, the cache expiration time is calculated again. At the same time, the cache time processor starts an expiration time countdown program. When the cache expiration time arrives, a request to recalculate the cache expiration time is actively submitted through the program, and the cache data is refreshed by the data update parser.
[0019] Preferably, the data query parser is used to start a thread and process requests for refreshing invalid data through the thread.
[0020] Preferably, the program actively submits a request for recalculating the cache expiration time, and the cache data is refreshed by a thread in the data update parser.
[0021] A system for preventing cache avalanche of the present invention has the following advantages:
[0022] 1. Through a series of calculations and optimizations, the cache expiration time is set, which largely avoids the risk of data requests being routed to the underlying database due to the collective expiration of a large number of cached data, thereby causing huge pressure on the database and setting the risk of service downtime;
[0023] 2. Start a thread to handle requests to refresh invalid data. This mechanism of actively refreshing cached data can avoid the scenario where a large number of data requests are released to the database due to invalid cached data;
[0024] 3. Developers no longer need to pay attention to how to set the cache expiration time, but only need to focus on business development, thus reducing their workload;
[0025] 4. Suitable for various caching scenarios and has good applicability. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] The present invention is further described below in conjunction with the accompanying drawings.
[0028] Figure 1 A workflow for a system to prevent cache avalanches. DETAILED DESCRIPTION
[0029] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0030] The embodiment of the present invention provides a system for preventing cache avalanche, which is used to solve the technical problem of how to set the effective time of the cache to avoid the scenario of a large amount of cache data being outdated.
[0031] Embodiment: A system for preventing cache avalanche of the present invention is used to dynamically calculate the specific expiration time of current data based on the existing cache expiration time, and control the expiration time through an artificial weight coefficient. The system includes a data query parser, a data update parser and a cache time processor. The data query parser is used to record the number of data queries for each monitoring table, and regards data that meets a predetermined query frequency as high-frequency query data, and caches the high-frequency query data; the data update parser acts on the cached high-frequency query data, and when updating a certain high-frequency query data, the data update parser is used to update the data according to a specific scenario; the cache time processor is used to calculate the expiration time that needs to be set for the data according to the weight of the data, and the weight of the data includes a subjective weight and an objective weight. The subjective weight is a weight coefficient set manually, and the objective weight is a weight coefficient collected by a program.
[0032] The table information of the monitoring table is manually configured in advance by an administrator, and the data query parser is used to record the number of data queries of the monitoring table manually configured in advance by the administrator.
[0033] The data query parser is mainly used to record the number of queries on different table data. It can intuitively compare which table data has a high query frequency. For data with a high query frequency, it can be stored in the cache to improve the query efficiency of the database. There are often a lot of table data in enterprise-level projects. If the data query parser monitors all table data, it will not be worth the loss. Therefore, some business data is not critical business data, and its access volume must be very low. In order to solve this scenario, you can manually configure the table information that needs to be monitored. The data query parser will only record the query times of the pre-configured tables.
[0034] When the cached data is updated, the latest data needs to be refreshed to the cache to ensure that the user sees the latest and correct data. When updating a piece of data, the data update parser needs to update the data according to the specific scenario.
[0035] When the updated data is stored separately in the cache, the data update parser directly obtains the specific data from the cache and updates it to the latest data. The cache time processor is called to obtain the cache expiration time that should be set, and the latest data is placed in the cache.
[0036] The updated data is stored together with other data in the value corresponding to a key, so it can be updated according to the index position of the current data in the list. This can avoid the risk of a large amount of data being written into the memory, causing memory overflow.
[0037] In addition to re-refreshing the data that needs to be updated into the cache, the data update parser also starts a thread to handle requests for invalid data refresh. This mechanism of actively refreshing cached data can avoid the scenario where a large number of data requests are released to the database due to invalid cached data.
[0038] The main function of the cache time processor is to calculate the expiration time that needs to be set for the data based on the weight of the data. The data weight here includes subjective weight and objective weight, that is, the weight coefficient set manually and the weight coefficient collected through the program.
[0039] The manual weight coefficient refers to the weight coefficient of the table data manually set by the administrator. The larger the weight coefficient, the longer the cache expiration time set for the table data. This method helps to deal with some unexpected scenarios, such as promotion scenarios. In the promotion scenario, the main product may not be a best-selling product. In this case, the data of these non-best-selling products needs to be cached for as long as possible, because the promotion time is generally calculated in days, and the access frequency cannot be determined during the promotion period. The manual weight coefficient provides a controllable means for data caching, which greatly facilitates the setting of cache data in some special scenarios.
[0040] The objective weight coefficient refers to the coefficient calculated by the access frequency of the data. The higher the frequency of data access, the greater the objective weight coefficient. The data source of the objective weight coefficient is the data volume of the number of data queries provided by the data query parser.
[0041] By setting the percentage of the artificial weight coefficient and the objective weight coefficient in the weight coefficient system, the final weight coefficient of a certain business data can be calculated. According to this weight coefficient, the specific cache expiration time can be set, and the cache time processor will record the cache expiration time. After calculating the cache expiration time, the cache time processor will retrieve the number of times the current expiration time occurs from the currently stored cache expiration time set. If the number of times the expiration time occurs is high, the cache expiration time will be calculated again. At the same time, the cache time processor will start an expiration time countdown program. When the cache expiration time arrives, it will actively submit a request to re-update the expired data, and the thread in the data update parser will refresh the cache data.
[0042] like Figure 1 As shown in the figure, by optimizing the cache expiration time through a series of calculations, it is possible to avoid the risk of data requests being routed to the underlying database due to the collective expiration of large quantities of cached data, which would cause tremendous pressure on the database and set up the risk of service downtime.
[0043] The present invention has been shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the means in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. A system for preventing cache avalanche, characterized in that The system is used to dynamically calculate the specific expiration time of current data according to the existing cache expiration time, and control the expiration time through a human weight coefficient, and includes: A data query parser, which is used to record the number of data queries for each monitoring table, take data that meets a predetermined query frequency as high-frequency query data, and cache the high-frequency query data; A data update parser, which acts on cached high-frequency query data. When updating a certain high-frequency query data, the data update parser is used to update the data according to a specific scenario; A cache time processor, the cache time processor is used to calculate the expiration time that needs to be set for the data according to the weight of the data, the weight of the data includes a subjective weight and an objective weight, the subjective weight is a weight coefficient set manually, and the objective weight is a weight coefficient collected by a program; The cache time processor is used to calculate the expiration time that needs to be set for the data according to the weight of the data, including the following operations: Set the percentage of subjective weight and objective weight in the weight coefficient system to calculate the final weight coefficient of the target data; Setting a cache expiration time according to the weight coefficient, and recording the cache expiration time through a cache time processor; After calculating the cache expiration time, the cache time processor retrieves the number of times the current cache expiration time occurs from the currently stored cache expiration time set. If the number of times the cache expiration time occurs is high, the cache expiration time is calculated again. At the same time, the cache time processor starts an expiration time countdown program. When the cache expiration time arrives, a request to recalculate the cache expiration time is actively submitted through the program, and the cache data is refreshed by the data update parser.
2. A system for preventing cache avalanche according to claim 1, characterized in that The table information of the monitoring table is manually configured in advance by an administrator; The data query parser is used to record the number of data queries of the monitoring table manually configured in advance by the administrator.
3. A system for preventing cache avalanche according to claim 1, characterized in that If the updated data is stored separately in the cache, the data update parser is used to directly obtain specific data from the cache and update the obtained data to the latest data, and call the cache time processor to obtain the cache expiration time that should be set, and cache the latest data.
4. A system for preventing cache avalanche according to claim 3, characterized in that If the updated data is stored together with other data in a value corresponding to a key, the data update parser is used to update the data according to the index position of the current data in the list.
5. A system for preventing cache avalanche according to claim 1, 2, 3 or 4, characterized in that The manually set weight coefficient is a weight coefficient of the data in the monitoring table manually set by an administrator, and a larger weight coefficient indicates a longer cache expiration time set for the data in the monitoring table; The objective weight coefficient is a coefficient calculated by the access frequency of the data. The higher the access frequency of the data, the greater the objective weight coefficient of the data.
6. A system for preventing cache avalanche according to claim 1, characterized in that The data query parser is used to start a thread and process the request for refreshing the invalid data through the thread.
7. A system for preventing cache avalanche according to claim 1, characterized in that The program actively submits a request to recalculate the cache expiration time, and the cache data is refreshed by a thread in the data update parser.
Citation Information
Patent Citations
Adjustment method and system for cache management strategy
CN101866321A
Caching management method and system
CN105446909A
Resource caching method and apparatus
CN105868017A
Dynamic cache data invalidity dispatching method and device and cache system
CN108287878A
A system and method for avoiding cache avalanche through multi-level caching in micro-service
CN109669960A
