A cache optimization method, device and equipment based on a distributed system and a medium

CN122593699APending Publication Date: 2026-08-18MALANSHAN AUDIO & VIDEO LABORATORY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610743223.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-27
Publication Date
2026-08-18

AI Technical Summary

Technical Problem

[0004]然而,现有的缓存更新方式,通常通过设定固定的缓存过期时间(即生存时间)来粗略平衡命中率与一致性,但当大量缓存数据在同一时刻过期(如设置了相同的过期时间),会引发瞬时的大规模回源请求,对数据源造成严重冲击,即使添加随机抖动分散过期时刻,也只是缓解,因此无法准确控制缓存更新时机,且设定固定缓存过期时间的方式的平衡命中率与一致性的性能较差

Benefits of technology

[0048]As can be seen, this application determines the current access heat corresponding to the target data item in the cache from several preset access heat levels based on the decaying access count result at the current moment; determines the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes; determines a cache update strategy that is compatible with both the current access heat and the current consistency window from several preset cache update strategies, as the current cache update strategy corresponding to the target data item; the access heat level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively; when the target data item in the data source is updated, the target data item in different levels of cache is updated based on the current cache update strategy to achieve cache optimization of the distributed system. Therefore, it is evident that distributed systems often employ multi-level caching. The cache update strategy specifies different update methods for each cache level, rather than setting the same update method for different levels, thus improving the compatibility between the cache and the corresponding update method. Furthermore, this application calculates the current access frequency and current consistency window for each target data item in the cache. Because this application does not set a fixed time, but rather selects a cache update strategy adapted to the current consistency window corresponding to the target data item, it ensures that the data latency corresponding to the strategy is always less than the current consistency window (the longest allowed duration), thus ensuring that data consistency meets the requirements of the target data item. Moreover, the selected cache update strategy is also adapted to the current access frequency corresponding to the target data item. Because the access popularity level is positively correlated with the initiative of the cache update strategy, and because a higher initiative level results in a faster update speed, which in turn improves the hit rate, the strategy can ensure that the data hit rate meets the requirements of the target data item. Therefore, selecting a cache update strategy that simultaneously adapts to the current access popularity and the current consistency window can achieve a precise balance between hit rate and consistency. In addition, even if a large amount of cached data expires at the same time, this cached data still needs to determine the corresponding current cache update strategy based on the current access popularity and the current consistency window, rather than being updated simultaneously. This effectively avoids large-scale data updates at the same time, prevents impact on the data source, and further ensures the security and reliability of the distributed system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122593699A_ABST
    Figure CN122593699A_ABST
Patent Text Reader

Abstract

The application discloses a cache optimization method and device based on a distributed system, equipment and a medium, and relates to the technical field of cache optimization. The method comprises the following steps: determining a current access hotness corresponding to a target data item in a cache from a plurality of preset access hotnesses in a hierarchical manner according to a decay access count result at a current time; determining a current consistency window corresponding to the target data item; determining a cache update strategy that is simultaneously adapted to the current access hotness and the current consistency window from a plurality of preset cache update strategies, and taking the cache update strategy as a current cache update strategy; the level of the access hotness is positively correlated with the initiative degree of a data update operation of the cache update strategy; the preset cache update strategy defines cache update manners corresponding to a plurality of hierarchical caches respectively; when the target data item in a data source is updated, the target data item is updated in the cache based on the current cache update strategy; and the application can accurately balance the hit rate and consistency during cache updating.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cache optimization technology, and in particular to a cache optimization method, apparatus, device and medium based on distributed systems. Background Technology

[0002] Currently, in distributed microservice systems, caching is a key performance layer connecting business logic and data storage. Caching is a core means of improving data access performance by temporarily storing hot data in high-speed storage close to computing nodes, thus avoiding accessing slow data sources (such as data sources) every time.

[0003] As the system grows, the types of data items in the cache become increasingly diverse (configuration data, user data, content data, statistical data, etc.), and the consistency and hit rate requirements for different types of data items vary greatly. The business requires that consistency-sensitive data (such as payment amounts, permission configurations, and model parameters) be updated in the cache within a controllable timeframe after changes to the data source. Simultaneously, the overall cache hit rate should not drop significantly due to frequent updates; otherwise, the data source will be overloaded by a large number of origin server requests.

[0004] However, existing cache update methods typically use a fixed cache expiration time (i.e., time to live) to roughly balance hit rate and consistency. But when a large amount of cached data expires at the same time (e.g., with the same expiration time set), it will trigger a large number of instantaneous origin requests, which will severely impact the data source. Even if random jitter is added to distribute the expiration time, it can only alleviate the problem. Therefore, it is impossible to accurately control the timing of cache updates, and the performance of balancing hit rate and consistency by setting a fixed cache expiration time is poor.

[0005] In summary, how to accurately balance hit rate and consistency during cache updates is a problem that urgently needs to be solved. Summary of the Invention

[0006] In view of this, the purpose of this invention is to provide a cache optimization method, apparatus, device, and medium based on a distributed system, which can accurately balance hit rate and consistency during cache updates. The specific solution is as follows:

[0007] Firstly, this application discloses a cache optimization method based on distributed systems, including:

[0008] Based on the decayed access count results at the current moment, the current access popularity corresponding to the target data item in the cache is determined from several preset access popularity levels.

[0009] Determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes;

[0010] From several preset cache update strategies, a cache update strategy that is simultaneously compatible with the current access popularity and the current consistency window is determined as the current cache update strategy corresponding to the target data item; the access popularity level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively;

[0011] When the target data item in the data source is updated, the target data item in different levels of cache is updated based on the current cache update strategy to optimize the cache of the distributed system.

[0012] Optionally, determining a cache update strategy that simultaneously adapts to the current access popularity and the current consistency window, as the current cache update strategy corresponding to the target data item, includes:

[0013] Based on the correspondence between preset popularity data and preset cache update strategies, and according to the current access popularity, a reference cache update strategy corresponding to the target data item is determined from several preset cache update strategies.

[0014] If the latency of the reference cache update strategy is greater than the current consistency window, then the target cache update strategy is determined as the current cache update strategy; the target cache update strategy is the first cache update strategy with a higher level of initiative than the reference cache update strategy and a latency of no more than the current consistency window when the initiative level is arranged from low to high.

[0015] If the delay time corresponding to the reference cache update strategy is not greater than the current consistency window, then the reference cache update strategy is determined as the current cache update strategy;

[0016] Accordingly, the correspondence between the preset popularity data and the preset cache update strategy includes an active push strategy for super hotspots, a message channel subscription strategy for general hotspots, a read time version number verification strategy for warm data, and an expiration and elimination strategy for cold data.

[0017] Optionally, determining the current access popularity of the target data item in the cache from several preset access popularity levels based on the decaying access count result at the current moment includes:

[0018] Based on the relationship between the decayed access count result at the current moment and the preset count threshold corresponding to the preset access heat, the reference access heat corresponding to the target data item in the cache is determined from several preset access heat levels.

[0019] If the preset conditions are met, the reference access popularity is determined as the current access popularity corresponding to the target data item; the preset conditions are that the level of the reference access popularity is higher than or equal to the level of the target data item's previous access popularity at the previous moment, or that the level of the reference access popularity determined continuously within the preset time period is lower than the level of the target data item's previous access popularity.

[0020] If the preset conditions are not met, the previous access popularity will be determined as the current access popularity.

[0021] Accordingly, the formula for calculating the decayed access count result is: ;in, Represents the target data item At any moment The current decayed access count result; Represents data items At any moment The current decayed access count result; Indicates the exponential decay factor; Indicates the preset attenuation coefficient; express and The time interval between; express The number of new visits within.

[0022] Optionally, determining the current consistency window corresponding to the target data item includes:

[0023] The current consistency window corresponding to the target data item is obtained by calculating the ratio of the preset base window to the target sum; the target sum is the sum of the heat factor, business sensitivity factor and data item change frequency factor corresponding to the target data item;

[0024] in, ; Represents the target data item The heat factor, Represents the target data item At the present moment The decayed access count results, This indicates the preset general hotspot counting threshold corresponding to the general hotspot; ; Represents the target data item The data item change frequency factor; Describe the target data item The actual frequency of changes; This indicates the preset baseline change frequency.

[0025] Optionally, caching optimization methods based on distributed systems also include:

[0026] Pareto equilibrium evaluation is performed on the overall actual hit rate and overall actual inconsistency event rate corresponding to all the target data items.

[0027] If the current state is not Pareto optimal, adjust the preset base window to adjust the current consistency window, and adjust all the preset counting thresholds to adjust the current access heat, until Pareto optimal is achieved.

[0028] Optionally, adjusting the preset base window to adjust the current consistency window includes:

[0029] Identify the dominant factors that cause the current state to be non-Pareto optimal;

[0030] If the dominant factor is the hit rate, then the preset base window is reduced by a preset percentage to obtain a new preset base window;

[0031] If the dominant factor is the inconsistency event rate, then the preset base window of the preset percentage is expanded to obtain a new preset base window;

[0032] Accordingly, adjusting all the preset counting thresholds to adjust the current access popularity includes:

[0033] The excess update cost is obtained by calculating the difference between the total update cost and the preset total update cost; the total update cost is the sum of the actual update costs of all the target data items.

[0034] The heat threshold adjustment coefficient is determined based on the total update cost, the excess update cost, and the adjustment rate.

[0035] Using the heat threshold adjustment coefficient, all preset count thresholds are adjusted to increase the preset count threshold when the update cost excess is positive and decrease the preset count threshold when the update cost excess is negative.

[0036] Optionally, after determining the current access popularity of the target data item in the cache from several preset access popularity levels based on the decaying access count result at the current moment, the method further includes:

[0037] Calculate the burst access multiplier corresponding to the target data item in real time;

[0038] If the burst access rate is greater than a preset access rate threshold, then according to the preset level improvement rule, a level higher than the current access popularity is selected as the new current access popularity corresponding to the target data item; the preset level improvement rule specifies the correspondence between the target difference and the level improvement amount under each preset access popularity; the target difference is the difference between the burst access rate and the preset access rate threshold.

[0039] Secondly, this application discloses a cache optimization device based on a distributed system, comprising:

[0040] The access heat determination module is used to determine the current access heat corresponding to the target data item in the cache from several preset access heat levels based on the decaying access count results at the current moment.

[0041] The consistency window determination module is used to determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes;

[0042] The strategy determination module is used to determine, from several preset cache update strategies, a cache update strategy that is simultaneously compatible with the current access popularity and the current consistency window, and use it as the current cache update strategy corresponding to the target data item; the access popularity level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively;

[0043] The cache update module is used to update the cache of the target data item in different levels of cache based on the current cache update strategy when the target data item in the data source is updated, so as to optimize the cache of the distributed system.

[0044] Thirdly, this application discloses an electronic device, including:

[0045] Memory, used to store computer programs;

[0046] A processor is used to execute the computer program to implement the aforementioned cache optimization method based on a distributed system.

[0047] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned cache optimization method based on a distributed system.

[0048] As can be seen, this application determines the current access heat corresponding to the target data item in the cache from several preset access heat levels based on the decaying access count result at the current moment; determines the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes; determines a cache update strategy that is compatible with both the current access heat and the current consistency window from several preset cache update strategies, as the current cache update strategy corresponding to the target data item; the access heat level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively; when the target data item in the data source is updated, the target data item in different levels of cache is updated based on the current cache update strategy to achieve cache optimization of the distributed system. Therefore, it is evident that distributed systems often employ multi-level caching. The cache update strategy specifies different update methods for each cache level, rather than setting the same update method for different levels, thus improving the compatibility between the cache and the corresponding update method. Furthermore, this application calculates the current access frequency and current consistency window for each target data item in the cache. Because this application does not set a fixed time, but rather selects a cache update strategy adapted to the current consistency window corresponding to the target data item, it ensures that the data latency corresponding to the strategy is always less than the current consistency window (the longest allowed duration), thus ensuring that data consistency meets the requirements of the target data item. Moreover, the selected cache update strategy is also adapted to the current access frequency corresponding to the target data item. Because the access popularity level is positively correlated with the initiative of the cache update strategy, and because a higher initiative level results in a faster update speed, which in turn improves the hit rate, the strategy can ensure that the data hit rate meets the requirements of the target data item. Therefore, selecting a cache update strategy that simultaneously adapts to the current access popularity and the current consistency window can achieve a precise balance between hit rate and consistency. In addition, even if a large amount of cached data expires at the same time, this cached data still needs to determine the corresponding current cache update strategy based on the current access popularity and the current consistency window, rather than being updated simultaneously. This effectively avoids large-scale data updates at the same time, prevents impact on the data source, and further ensures the security and reliability of the distributed system. Attached Figure Description

[0049] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0050] Figure 1 This application discloses a flowchart of a cache optimization method based on a distributed system.

[0051] Figure 2 This application discloses a specific flowchart of a cache optimization method based on a distributed system.

[0052] Figure 3 This application discloses a specific flowchart of a cache optimization method based on a distributed system.

[0053] Figure 4 This is a schematic diagram of a distributed system disclosed in this application;

[0054] Figure 5 This is a timing diagram of a multi-level cache read path disclosed in this application;

[0055] Figure 6 This is a schematic diagram of the structure of a cache optimization device based on a distributed system disclosed in this application;

[0056] Figure 7 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0057] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0058] Existing cache update methods typically use a fixed cache expiration time (i.e., time to live) to roughly balance hit rate and consistency. However, when a large amount of cached data expires at the same time (e.g., with the same expiration time set), it can trigger a massive instantaneous back-to-origin request, severely impacting the data source. Even adding random jitter to distribute the expiration time only alleviates the problem. Therefore, it is impossible to accurately control the timing of cache updates, and the method of setting a fixed cache expiration time has poor performance in balancing hit rate and consistency.

[0059] Therefore, this application proposes a cache optimization scheme based on a distributed system, which can accurately balance hit rate and consistency during cache updates.

[0060] This application discloses a cache optimization method based on a distributed system. (See also...) Figure 1 As shown, the method includes:

[0061] Step S11: Based on the decayed access count result at the current moment, determine the current access popularity of the target data item in the cache from several preset access popularity levels.

[0062] In this embodiment, the number of preset access hotspots can be determined according to the actual situation. For example, the number of preset cache update strategies can be set to the same number of hotspots. In a specific embodiment, the preset access hotspots arranged in descending order of level are super hotspot, general hotspot, warm data, and cold data.

[0063] See Table 1 for the characteristic information of different heat levels.

[0064] Table 1. Characteristic information of different heat levels

[0065]

[0066] In this embodiment, the formula for calculating the decayed access count result is as follows: ;in, Represents the target data item At any moment The current decayed access count result; Represents data items At any moment The current decayed access count result; Indicates the exponential decay factor; Indicates the preset attenuation coefficient; express and The time interval between; express The number of new visits within.

[0067] It should be noted that the preset decay coefficient (default 0.01 / second, can be adjusted according to actual conditions) controls the rate at which historical visits are forgotten. The larger the value, the faster the decay of long-term visits, and the more the count value is biased towards recent behavior.

[0068] In one specific embodiment, if the decay count of a certain data item was 500 one minute ago, with a decay coefficient of 0.01, and 80 new accesses occurred within one minute, then the decay access count result would be: It should be noted that this application uses the decaying access count result at the current moment, rather than the total number of accesses. In general, the popularity of old accesses cools down naturally over time, while new accesses continuously inject popularity, thus reflecting the real-time data popularity rather than the cumulative total.

[0069] In this embodiment, determining the current access popularity involves not only considering the popularity determined at the current moment but also the relationship between the current popularity and the popularity at the previous moment. An increase in popularity relative to the previous moment can be implemented immediately, while a decrease in popularity requires ensuring that the situation remains consistent over a certain period to avoid fluctuations in popularity. Specifically, determining the current access popularity corresponding to the target data item in the cache from several preset access popularity levels based on the decaying access count result at the current moment includes: determining the current access popularity of the target data item in the cache based on the decaying access count result at the current moment and the preset access popularity corresponding to the preset access popularity level. The design considers the relationship between threshold values ​​and determines the reference access popularity of a target data item in the cache from several preset access popularity levels. If a preset condition is met, the reference access popularity is determined as the current access popularity of the target data item. The preset condition is that the level of the reference access popularity is higher than or equal to the level of the previous access popularity of the target data item at the previous moment, or the level of the reference access popularity determined continuously within a preset time period is lower than the level of the previous access popularity of the target data item. If the preset condition is not met, the previous access popularity is determined as the current access popularity.

[0070] In one specific embodiment, if the previous access popularity was normal popularity and the current reference access popularity is super popularity, then the current access popularity is directly determined as super popularity; if the previous access popularity was normal popularity and the current reference access popularity was lukewarm popularity, then it is necessary to ensure that the reference access popularity remains lukewarm popularity for a certain period of time before the current access popularity can be determined as lukewarm popularity, otherwise the current access popularity still needs to be determined as normal popularity.

[0071] It should be noted that when heat fluctuations occur, that is, when the proportion of data items whose heat level changes more than the preset number of times within a fixed time period exceeds the preset threshold, the preset time period (i.e., the cooling observation period) can be increased, and the buffer of the corresponding heat threshold can be increased. For example, the preset time period can be extended from 5 minutes to 10 minutes, and the hot spot threshold can be changed from 200 to a lag range of 180-220, to reduce the frequent temperature rises and falls of data at the boundary.

[0072] It should be noted that when determining the reference access popularity, not only the decayed access count result and the threshold value should be considered, but the access source dispersion should also be considered. However, not all levels of popularity need to be considered; the specific value can be set according to the actual situation. Specifically, based on the relationship between the decayed access count result at the current moment and the preset count threshold (also known as the popularity threshold) corresponding to the preset access popularity, the reference access popularity corresponding to the target data item in the cache is determined from several preset access popularity levels. This includes: if the decayed access count result at the current moment is not less than the preset super hotspot count threshold and the access source dispersion is not less than the first preset dispersion, the reference access popularity corresponding to the target data item is determined as a super hotspot; if the decayed access count result at the current moment is not less than the preset general hotspot count threshold, the reference access popularity corresponding to the target data item is determined as a general hotspot; if the decayed access count result at the current moment is not less than the preset warm data count threshold, the reference access popularity corresponding to the target data item is determined as warm data; and the reference access popularity corresponding to the target data item that is not classified into the super hotspot, the general hotspot, or the warm data is determined as cold data.

[0073] It should be noted that this application only considers the dispersion of accessible sources when determining super popularity, but this does not mean that other sources must not be considered. Thresholds of dispersion that other popularity needs to meet can also be set according to actual circumstances.

[0074] In one specific embodiment, super popularity: and General popularity: Temperature: Temperature: Other situations; Among them, , , , Depending on the actual situation, in one specific embodiment, The default value is 200. The default value is 20. The default value is 1000. The default value is 0.6; access source dispersion. Defined as the proportion of different service instances accessing the data item to the total number of instances. Only high-frequency data that is widely accessed by multiple instances is a true super hotspot (high-frequency local access by a single instance is not considered a super hotspot, because it can be efficiently served by in-process caching alone).

[0075] Table 2 shows parameters such as the popularity identification threshold and cycle. The burst detection window sets the time interval for detecting burst access; details on burst access detection will be discussed later. The popularity reassessment cycle sets the time interval for determining the current data popularity.

[0076] Table 2 Heat Recognition Parameters

[0077]

[0078] Step S12: Determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes.

[0079] In this embodiment, determining the current consistency window corresponding to the target data item includes: calculating the ratio of a preset base window to the target sum to obtain the current consistency window corresponding to the target data item; the target sum is the sum of the heat factor, business sensitivity factor, and data item change frequency factor corresponding to the target data item. The specific formula is: ; The preset basic window has upper and lower limit protection, which can be set according to specific circumstances. In this embodiment, the lower limit is 1 second and the upper limit is 10 minutes.

[0080] It should be pointed out that, ; Represents the target data item The heat factor, Represents the target data item At the present moment The decayed access count results, This indicates the preset general hotspot counting threshold corresponding to the general hotspot; ; Represents the target data item The data item change frequency factor; Describe the target data item The actual frequency of changes; This indicates the preset baseline change frequency.

[0081] It should be noted that business sensitivity can be obtained through business annotation and / or automatic inference. Business annotation (i.e., explicit annotation) refers to the business developers declaring the sensitivity level in the metadata of data items (such as "payment amount=10", "user nickname=2", "browsing statistics=1"). Automatic inference refers to the system automatically inferring the sensitivity level of unannotated data items based on the data table and field name pattern to which they belong. Fields containing keywords such as "amount", "balance", "password", and "permissions" have a default sensitivity of 8-10; fields containing keywords such as "name", "description", and "avatar" have a default sensitivity of 2-3; and the rest have a default sensitivity of 5. It is also possible to obtain the sensitivity of both business annotation and automatic inference at the same time, and then calculate the average or perform a weighted calculation. When performing a weighted calculation, the weights should be set according to the actual situation.

[0082] It's important to note that higher sensitivity results in a shorter calculated window, while lower sensitivity results in a longer calculated window. A higher heat factor leads to a larger factor and a shorter window, because super-hot data is requested extensively within the window, meaning the impact of a single expired data point is far greater than that of cold data. A logarithmic function ensures a gradual increase in the heat factor, preventing excessively short windows caused by extreme hot data. Similarly, a higher change frequency factor leads to a larger factor and a shorter window, as frequently changing data is more prone to inconsistencies and requires a shorter window.

[0083] In one specific embodiment, a service sensitivity of 5 and an attenuation count of 800 ( ≈2.6), changed 3 times per hour ( ≈2.1) data items, current consistency window In seconds.

[0084] It should be noted that the system allows setting a lower limit for the window. (This can be set according to actual conditions; the default value in this embodiment is 200 milliseconds) and upper limit. (This setting can be adjusted according to actual conditions; the default setting in this embodiment is 30 minutes) to prevent extreme values.

[0085] See Table 3 for details on the calculation parameters of the consistency window and their descriptions.

[0086] Table 3 Consistency Window Calculation Parameters

[0087]

[0088] Step S13: From several preset cache update strategies, determine the cache update strategy that is compatible with both the current access popularity and the current consistency window, and use it as the current cache update strategy corresponding to the target data item; the access popularity level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively.

[0089] In this embodiment, the preset cache update strategies arranged in descending order of initiative are, in order, an active push strategy, a message channel subscription strategy, a read-time version number verification strategy, and an expiration elimination strategy.

[0090] It should be noted that the proactive push strategy is as follows: When the data source changes, the update strategy manager immediately pushes the new data to all cache nodes holding that data item via a message channel, including the distributed cache cluster and the in-process cache of each service instance. The push adopts a write-to-cache, then confirmation process, that is, the new value is first written to each cache node, and the version number in the cache metadata database is updated after successful writing. To prevent inconsistencies caused by push delays, each cache node also sets a fallback expiration time (equal to the consistency window of the data item) as a safety net in case of push failure. The message channel subscription strategy is as follows: When the data source changes, the change event is published through a message channel. Each cache node subscribes to the change event of the data item it cares about, and updates its local cache upon receiving it. The difference from proactive push is that: generally, hotspots do not require the changing party to wait for confirmation from all cache nodes, which is asynchronous eventual consistency, with a slightly longer update delay (500 milliseconds to several seconds), but lower update overhead. The read-time version number verification strategy is as follows: Warm data in the cache is accompanied by a version number. During a read operation, the cache client sends a lightweight version verification request to the data source, carrying only the version number (not the complete data). If the version numbers match, the cache is used directly (hits); otherwise, the latest data is retrieved from the source and the cache is refreshed. The overhead of the version verification request is much less than reading the complete data, and is acceptable for low to medium access frequencies of warm data. To avoid verification on every read, a verification interval is set. Repeated reads within the interval use the cache directly without repeated verification. The verification interval is set to half the consistency window. The specific details of the expiration eviction policy are as follows: Cold data uses a traditional expiration time strategy. An expiration time (equal to its consistency window) is set when the cache is written. After expiration, the cache automatically expires, and the latest data is retrieved from the source on the next read. The consistency window for cold data is usually very long (minutes to hours), so the expiration frequency is very low, and almost no update overhead is incurred.

[0091] In this embodiment, the correspondence between the preset popularity data and the preset cache update strategy includes: super popularity corresponds to the active push strategy, general popularity corresponds to the message channel subscription strategy, warm data corresponds to the read-time version number verification strategy, and cold data corresponds to the expiration and eviction strategy. See Table 4 for the correspondence between popularity levels and update strategies.

[0092] Table 4. Correspondence between popularity level and update strategy

[0093]

[0094] It should be noted that a distributed system can not only have one cache. When there is a hierarchical cache, you can set your own cache update method for different levels of cache in each preset cache update strategy to adapt to multi-level cache updates. See Table 5, which shows the combination of cache and update strategy at each level in the distributed system.

[0095] Table 5 Hierarchical caching and strategy combinations

[0096]

[0097] It should be noted that the expiration time for different strategies can be set according to the actual situation, and no specific limit is set here.

[0098] In this embodiment, the consistency window not only affects the setting of the expiration time but also constrains the selection of the update strategy. When the strategy determined based on the correspondence between preset popularity data and preset cache update strategy cannot satisfy the requirement that the strategy delay time is less than the current consistency window, a strategy with a higher degree of initiative needs to be selected to ensure that the delay time of the newly selected strategy is less than the current consistency window. Specifically, determining the cache update strategy that is simultaneously compatible with the current access popularity and the current consistency window as the current cache update strategy corresponding to the target data item includes: based on the correspondence between preset popularity data and preset cache update strategy, according to the current... Based on previous access popularity, a reference cache update strategy corresponding to the target data item is determined from several preset cache update strategies. If the latency of the reference cache update strategy is greater than the current consistency window, the target cache update strategy is determined as the current cache update strategy. The target cache update strategy is the first cache update strategy with a higher level of initiative than the reference cache update strategy and a latency not greater than the current consistency window when sorted from low to high according to initiative level. If the latency of the reference cache update strategy is not greater than the current consistency window, the reference cache update strategy is determined as the current cache update strategy.

[0099] It should be noted that the current consistency window It not only affects the expiration time setting, but also constrains the choice of update strategy. If the consistency window of a data item is extremely short (e.g., within 500 milliseconds), then even if its temperature level is moderate, an active push strategy must be adopted (because the delay of subscribing to updates may exceed 500 milliseconds).

[0100] In this embodiment, if the latency corresponding to the reference cache update strategy is not greater than the current consistency window, then the reference cache update strategy is determined as the current cache update strategy. However, there are special cases where the current consistency window is very long; for example, even with general popularity, it can be downgraded to a version number verification strategy to save overhead. Specifically, when the latency corresponding to the reference cache update strategy is not greater than the current consistency window, if the current consistency window is greater than a first threshold, an additional constraint can be added that the difference between the current consistency window and the latency is greater than a second threshold. In this case, the temporary cache update strategy is determined as the current cache update strategy. The temporary cache update strategy is the first cache update strategy with a lower level of initiative than the reference cache update strategy and a latency not greater than the current consistency window, when arranged from lowest to highest initiative level.

[0101] It should be noted that the aforementioned consistency window's constraint overriding of the update strategy ensures that the consistency commitment is always fulfilled.

[0102] Step S14: When the target data item in the data source is updated, the target data item in different levels of cache is updated based on the current cache update strategy to achieve cache optimization of the distributed system.

[0103] As can be seen, the distributed system in this application has multiple levels of caching. The cache update strategy specifies the cache update methods corresponding to several levels of cache, rather than setting the same cache update method for different levels of cache, thus improving the adaptability between the cache and the corresponding update method. In addition, this application calculates the current access popularity and the current consistency window for each target data item in the cache. Because this application does not set a fixed time, but selects a cache update strategy that adapts to the current consistency window corresponding to the target data item, it can ensure that the data latency time corresponding to the strategy is always less than the current consistency window (the longest allowed duration), that is, to ensure that the data consistency meets the requirements of the target data item, and the selected cache update strategy is also adapted to the current access popularity corresponding to the target data item. Because the access popularity level is positively correlated with the initiative of the cache update strategy, and because a higher initiative level results in a faster update speed, which in turn improves the hit rate, the strategy can ensure that the data hit rate meets the requirements of the target data item. Therefore, selecting a cache update strategy that is compatible with both the current access popularity and the current consistency window can achieve a precise balance between hit rate and consistency. In addition, even if a large amount of cached data expires at the same time, this cached data still needs to determine the corresponding current cache update strategy based on the current access popularity and the current consistency window, rather than being updated simultaneously. This effectively avoids large-scale data updates at the same time, prevents impact on the data source, and further ensures the security and reliability of the distributed system.

[0104] This application discloses a specific cache optimization method based on a distributed system. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution. See also... Figure 2 As shown, it specifically includes:

[0105] Step S21: Perform Pareto equilibrium evaluation on the overall actual hit rate and overall actual inconsistency event rate corresponding to all the target data items.

[0106] In this embodiment, Pareto equilibrium evaluation requires the use of deviation degree. The deviation degree represents the comprehensive deviation between the sum of the overall actual hit rate and the overall actual inconsistency event rate and the corresponding preset value. If the deviation degree is within the preset range, the current state is considered to be Pareto optimal, and the current consistency window corresponding to the target data item remains unchanged. If the deviation degree is not within the preset range, the current state is considered not to be Pareto optimal.

[0107] Specifically, the degree of deviation is ;in, This indicates the overall actual hit rate; This indicates the overall preset hit rate; This indicates a shortfall in hit rate (a positive value indicates that the hit rate is below standard). This represents the overall actual inconsistency rate; This indicates the overall pre-set inconsistency event rate; This indicates a consistency gap (positive values ​​indicate excessive inconsistency). and The weights are indicated by the preset values ​​and the user-defined values. These can be determined based on actual conditions. In this embodiment, all weights are set to 0.5. It should be noted that in this embodiment, the overall preset hit rate can be set to 95% by default, and the preset inconsistency event rate can be set to 1%.

[0108] It should be noted that the hit rate estimation process is as follows: This formula is used to estimate the impact of different update strategies on the hit rate, aiding in global optimization decisions; where, This represents an approximate cache hit rate for data item k, equal to 1 minus the "miss rate"; This indicates the average miss window corresponding to the update strategy after each data change. Internally, read requests may encounter expired or invalid cached data (i.e., a cache miss, requiring a request to retrieve data from the origin server). The shorter the update time, the more proactive the update strategy (in one specific embodiment, a proactively pushed miss window is approximately 0.2 seconds, and an expired miss window is half its expiration time). Divide by This is because the higher the total number of read requests, the higher the hit rate, while the absolute number of misses remains relatively constant.

[0109] It should be noted that the above calculation yields an estimated hit rate for a single target data item. To calculate the total hit rate globally, the specific calculation should be based on the formula. It's important to note that the global optimization goal is to maximize the weighted total hit rate (the hit rate of each data item multiplied by its access volume, i.e., the total number of actual hit requests). Dividing the total number of actual hit requests by the total number of requests yields the overall actual hit rate. It's worth noting that calculating the actual hit rate based on the weighted total hit rate is more reasonable than simply averaging the hit rate. For example, a 1% increase in the hit rate of a super-hot data item with 100,000 daily accesses is far more valuable than a 10% increase in the hit rate of a cold data item with 10 daily accesses.

[0110] Step S22: When the current state is not Pareto optimal, adjust the preset base window to adjust the current consistency window, and adjust all the preset counting thresholds to adjust the current access heat, until Pareto optimal is achieved.

[0111] In this embodiment, when the current state is not Pareto optimal, it is necessary to adjust the current consistency window and the current access popularity. Specifically, since the popularity level has divided the data into four levels, each corresponding to a fixed update strategy, optimization is actually transformed into adjusting the popularity threshold. Relaxing the popularity threshold (more data is regarded as cold data) can reduce update overhead but may violate the consistency window constraint; tightening the threshold (more data is regarded as hot data) can improve consistency but increase overhead. Therefore, it is necessary to iteratively adjust the current consistency window and the current access popularity to achieve a balance, specifically by adjusting the popularity threshold and the preset base window.

[0112] In this embodiment, when the current state is not Pareto optimal, it is necessary to determine which of the two factors—hit rate and inconsistency event rate—is the primary factor causing the non-Pareto optimality, and to decide how to adjust the window based on the dominant factor. Specifically, adjusting the preset base window to adjust the current consistency window includes: determining the dominant factor causing the current state to be non-Pareto optimal; if the dominant factor is the hit rate, then reducing the preset base window by a preset percentage to obtain a new preset base window; if the dominant factor is the inconsistency event rate, then expanding the preset base window by a preset percentage to obtain a new preset base window.

[0113] It should be noted that the dominant factor between the hit rate gap and the inconsistency event rate gap can be determined by the magnitude of those gaps; specifically, the larger gap indicates the dominant factor. When the hit rate gap is large, the hit rate is the dominant factor, and in this case, the preset base window should be enlarged. This allows cached data to survive longer and improves the hit rate; when the inconsistency event rate gap is large, the inconsistency event rate becomes the dominant factor, at which point the preset base window is reduced, specifically... This enables faster cache updates and improved consistency; It is usually set to 0.1 (10%).

[0114] It should be pointed out that, The adjustment range is small, ensuring that the system converges smoothly rather than oscillates violently.

[0115] In this embodiment, the level of initiative is related to the update cost; the higher the initiative, the higher the update cost. Therefore, the popularity threshold can be adjusted based on the sum of the actual update costs of all the target data items, along with the number of data items categorized under different strategies. When the sum of the actual update costs of all the target data items is far below the budget, the threshold can be lowered to allow more data to benefit from a more proactive update strategy, thus increasing update cost. Conversely, when the sum of the actual update costs of all the target data items exceeds the budget, the popularity threshold can be increased (multiplied by a factor greater than 1) to reduce the number of data items classified as hotspots, thereby decreasing update cost. Specifically, adjusting all the preset count thresholds to adjust the current access popularity includes: calculating the difference between the total update cost and the preset total update cost to obtain the update cost excess; the total update cost is the sum of the actual update costs of all the target data items; determining the popularity threshold adjustment coefficient based on the total update cost, the update cost excess, and the adjustment rate; and adjusting all the preset count thresholds using the popularity threshold adjustment coefficient to increase the preset count threshold when the update cost excess is positive and decrease it when the update cost excess is negative.

[0116] It should be noted that the formula for calculating the heat threshold adjustment coefficient is as follows: ;in, This indicates the total cost of updating. This indicates that the update cost has exceeded the limit. This indicates the adjustment rate, which can be set according to the actual situation. In this embodiment, the default value is 0.2.

[0117] It should be noted that the formula for calculating the actual update cost of the target data item is as follows: ;in, This represents the actual update cost of the target data item k; Indicates the cost coefficient of the update strategy used for the target data item; Indicates the frequency of changes to the target data item (e.g., the number of changes per hour); This represents the update fan-out, which is the number of cache nodes that need to receive the update (active push requires pushing to all nodes holding the data, resulting in the largest fan-out; expired data does not require active push, and the fan-out is 0, but it is calculated as 1 here to represent the basic overhead of passive origin retrieval). It should be noted that the more proactive the update strategy, the more frequent the data changes, and the more nodes that need to be notified, the greater the update overhead.

[0118] It should be noted that if, during the calculation of hit rate and inconsistency time rate, it is found that the hit rate and / or consistency of a certain level of popularity deviate significantly from the preset value of popularity, the parameters of that popularity (popularity threshold, including the preset counting threshold) can be adjusted locally without affecting the popularity of other levels.

[0119] In this embodiment, the necessary data needs to be collected before performing the Pareto equilibrium assessment. Specifically, the data is collected through monitoring, and the specific data collected is shown in Table 6 (including the data required for the Pareto equilibrium assessment and other data).

[0120] Table 6 Monitoring Data Collection

[0121]

[0122] The specific usage method has been clearly explained in the above content, and will not be described in detail here.

[0123] As can be seen, this application performs a Pareto equilibrium evaluation on the overall actual hit rate and overall actual inconsistency event rate corresponding to all the aforementioned target data items; when the current state is not Pareto optimal, the preset base window is adjusted to adjust the current consistency window, and all the preset counting thresholds are adjusted to adjust the current access popularity, until Pareto optimality is achieved. Therefore, it is evident that this application, by iteratively adjusting the current consistency window and current access popularity to achieve Pareto optimality when the current state is not Pareto optimal, further ensures the balance between hit rate and consistency.

[0124] This application discloses a specific cache optimization method based on a distributed system. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution. See also... Figure 3 As shown, it specifically includes:

[0125] Step S31: Calculate the burst access multiplier corresponding to the target data item in real time.

[0126] In this embodiment, the formula for calculating the burst access multiplier is: ;in, This indicates the number of times data item k was accessed within the shortest time window ending at time t (the value is set according to the actual situation; in this embodiment, the default is 5 minutes). This represents the average number of visits during the same historical period. Indicates an extremely small quantity, to prevent division by zero.

[0127] Step S32: If the burst access multiplier is greater than the preset multiplier threshold, then according to the preset level improvement rule, select a level higher than the current access popularity as the new current access popularity corresponding to the target data item; the preset level improvement rule specifies the correspondence between the target difference and the level improvement amount under each preset access popularity; the target difference is the difference between the burst access multiplier and the preset multiplier threshold.

[0128] In this embodiment, the burst access rate is greater than a preset access rate threshold. (Set according to actual situation, the default value in this embodiment is 3.0) When it is determined to be a sudden access, the popularity level of the data item is temporarily increased and continues until the sudden access ends.

[0129] It should be noted that the popularity level can be increased based on the correspondence between the target difference and the level increase under each preset access popularity. It can be set to increase the level by a fixed amount regardless of the target difference, for example, always by one level, such as from moderate popularity to general popularity. Different difference ranges can be set to correspond to different levels, with the larger the difference, the higher the level. However, the current data popularity level must also be considered. If it is general popularity, although different difference ranges are set to correspond to different levels, it can only be increased by one level.

[0130] In one specific embodiment, a certain data item was accessed an average of 20 times every 5 minutes in history, but was accessed 100 times in the last 5 minutes. The burst access rate = 100 / 20 = 5.0 > 3.0, and it is determined to be a burst.

[0131] As can be seen, this application calculates the burst access multiplier corresponding to the target data item in real time; if the burst access multiplier is greater than a preset multiplier threshold, then according to a preset level increase rule, a level higher than the current access popularity is selected as the new current access popularity corresponding to the target data item; the preset level increase rule specifies the correspondence between the target difference and the level increase amount under each preset access popularity; the target difference is the difference between the burst access multiplier and the preset multiplier threshold. Therefore, this application fully considers burst access situations when determining the current access popularity, improving the accuracy of current access popularity determination.

[0132] See Figure 4The diagram illustrates a distributed system. It shows the application layer, multi-level cache, data source layer, and cache management layer. Specifically, the in-process cache (local cache within each microservice instance) has the lowest access latency but the smallest capacity and serves as the first-level cache. The distributed cache cluster (a separately deployed shared cache service with larger capacity and millisecond-level access latency) serves as the second-level cache.

[0133] Data source: persistent data storage; when data changes, change events are published through a change message channel.

[0134] Change Message Channel: The propagation channel for data source change events, supporting publish / subscribe modes, routing change events to the update strategy manager. Hotspot Identification Engine: Receives cache access logs from each service instance in real time, maintains a decaying access counter and burst detection status for each data item, classifies data items into four temperature (popularity) levels, and writes them to the cache metadata database. Cache Metadatabase: Stores cache metadata for each data item, including popularity level, decay counter value, consistency window, current update strategy, data version number, and business sensitivity tag. Consistency Window Calculator: Dynamically calculates the consistency window value for each data item based on three factors: business sensitivity, current access popularity, and change frequency, and sets time constraints for the update strategy accordingly. Update Strategy Manager: Selects and switches cache update strategies (active push / subscribe update / version number verification / expiration eviction) for each data item based on its temperature (popularity) level and consistency window; receives change events sent by the data source through the message channel and distributes updates to each level of cache according to the strategy. Collaborative Feedback Tuner: Continuously collects metrics such as hit rate, inconsistency event rate, and update overhead for each heat level, assesses the current operating status in the hit rate-consistency two-dimensional space, and automatically fine-tunes the consistency window parameters and temperature (heat) threshold.

[0135] See Figure 5The diagram illustrates a multi-level cache read path timing. When a microservice instance reads data item k, if the in-process cache L1 hits and the data hasn't expired, it returns the hit data. If the in-process cache L1 misses, it reads data item k from the distributed cache L2. If the distributed cache L2 hits, it queries the data metadata database for the temperature (heat) level. If it determines the data is not warm (warm / hot), it retrieves the cached data from the distributed cache L2. If it is warm (warm / hot), based on the version verification strategy, the distributed cache L2 first sends the version number. If the versions match, the cached data that was hit in L2 will be returned. If the versions do not match, the latest data will be returned from the data source to the distributed cache L2 and refreshed. Then, the latest data will be returned from the distributed cache L2 to the microservice instance, and the latest data will be used to populate the in-process cache L1. If the distributed cache L2 is not hit, the microservice instance will directly read from the metadata and return it to the microservice instance. The returned data will be used to populate the in-process cache L1 and the distributed cache L2, and the access event will be reported to the hotspot identification engine.

[0136] In one specific embodiment, the AI ​​content creation platform comprises 30 microservices, using a distributed cache to store various types of business data: user session information, AI model configuration parameters, material resource metadata, content review rules, user work lists, etc. Among these, "AI model configuration parameters" (such as the inference model version number, parameter thresholds, feature switches, etc.) represent a typical conflicting scenario: operations personnel adjust model parameters multiple times daily (moderate change frequency), while the inference service needs to read these parameters thousands of times per second (extremely high access frequency). In a traditional solution: if the cache expiration time is set to 60 seconds, the inference service will still use the old parameters for a maximum of 60 seconds after a parameter change, which is unacceptable in a model canary release scenario; if the expiration time is shortened to 5 seconds, although consistency is improved, the cache expires every 5 seconds, instantly generating a large number of origin server requests that overwhelm the database under millisecond-level high-frequency reads, causing the hit rate to plummet from 98% to 70%. Worse still, the same 60-second expiration time is applied to all data; the user work list (which changes less than once a day but is read tens of thousands of times daily) could have been cached for several hours, but it frequently expires due to the uniform policy. However, in this application, the hotspot identification engine identifies "AI model configuration parameters" as super hotspot (read thousands of times per second from multiple inference service instances) and "user work list" as warm data (low-frequency changes, medium-frequency reads). The multi-level cache update strategy proactively pushes updates to super hotspot data. When operations personnel modify model parameters, the changes are immediately pushed to all cache nodes, and the inference service reads the new parameters within 200 milliseconds without waiting for expiration; simultaneously, the consistency window for this data is dynamically calculated to 500 milliseconds. The "user work list," on the other hand, is configured for version number verification updates, with the consistency window widened to 10 minutes. Reading only requires comparing the version number (with minimal overhead), and most of the time the cache is directly hit. Upward, the following final effects can be achieved: (1) The hit rate of AI model configuration parameters is maintained at 97%, push updates avoid the loss of hit rate due to expiration and failure, and the duration of data inconsistency is controlled within 500 milliseconds; (2) The hit rate of the user's work list is increased from 85% to 99% because it is no longer dragged down by unnecessary short expiration time; (3) The overall cache back-to-origin request volume decreases by 65%, and the database pressure is significantly reduced.

[0137] Accordingly, embodiments of this application also disclose a cache optimization device based on a distributed system, see [link to relevant documentation]. Figure 6 As shown, the device includes:

[0138] The access heat determination module 11 is used to determine the current access heat corresponding to the target data item in the cache from several preset access heat levels based on the decay access count result at the current moment.

[0139] The consistency window determination module 12 is used to determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes.

[0140] The strategy determination module 13 is used to determine, from several preset cache update strategies, a cache update strategy that is simultaneously compatible with the current access popularity and the current consistency window, and use it as the current cache update strategy corresponding to the target data item; the access popularity level is positively correlated with the degree of initiative of the cache update strategy in performing data update operations; the preset cache update strategy specifies the cache update methods corresponding to several levels of cache respectively;

[0141] The cache update module 14 is used to update the cache of the target data item in different levels of cache based on the current cache update strategy when the target data item in the data source is updated, so as to achieve cache optimization of the distributed system.

[0142] The more specific working process of each of the above modules can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0143] Furthermore, embodiments of this application also provide an electronic device. Figure 7 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0144] Figure 7 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the distributed system-based cache optimization method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0145] In this embodiment, the power supply 26 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 24 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0146] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon may include computer programs 221, and the storage method may be temporary storage or permanent storage. The computer programs 221 may include, in addition to computer programs capable of performing the distributed system-based cache optimization method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, computer programs capable of performing other specific tasks.

[0147] Furthermore, embodiments of this application also disclose a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned cache optimization method based on a distributed system.

[0148] The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0149] The various embodiments in this application are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts between the various embodiments, refer to each other. As for the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section.

[0150] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0151] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0152] Finally, it should be noted that in this document, relational terms such as "first" and "first" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0153] The above provides a detailed description of a cache optimization method, apparatus, device, and storage medium based on a distributed system provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A cache optimization method based on a distributed system, characterized in that, include: Based on the decayed access count results at the current moment, the current access popularity corresponding to the target data item in the cache is determined from several preset access popularity levels. Determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes; From several preset cache update strategies, determine the cache update strategy that is compatible with both the current access popularity and the current consistency window, and use it as the current cache update strategy for the target data item. The access popularity level is positively correlated with the degree of initiative in data update operations by the cache update strategy; the preset cache update strategy specifies the cache update methods corresponding to several cache levels; When the target data item in the data source is updated, the target data item in different levels of cache is updated based on the current cache update strategy to optimize the cache of the distributed system.

2. The cache optimization method based on a distributed system according to claim 1, characterized in that, The step of determining a cache update strategy that simultaneously adapts to the current access popularity and the current consistency window, as the current cache update strategy corresponding to the target data item, includes: Based on the correspondence between preset popularity data and preset cache update strategies, and according to the current access popularity, a reference cache update strategy corresponding to the target data item is determined from several preset cache update strategies. If the latency of the reference cache update strategy is greater than the current consistency window, then the target cache update strategy is determined as the current cache update strategy; the target cache update strategy is the first cache update strategy with a higher level of initiative than the reference cache update strategy and a latency of no more than the current consistency window when the initiative level is arranged from low to high. If the delay time corresponding to the reference cache update strategy is not greater than the current consistency window, then the reference cache update strategy is determined as the current cache update strategy; Accordingly, the correspondence between the preset popularity data and the preset cache update strategy includes an active push strategy for super hotspots, a message channel subscription strategy for general hotspots, a read time version number verification strategy for warm data, and an expiration and elimination strategy for cold data.

3. The cache optimization method based on a distributed system according to claim 2, characterized in that, The step of determining the current access popularity of a target data item in the cache from several preset access popularity levels based on the decaying access count result at the current moment includes: Based on the relationship between the decayed access count result at the current moment and the preset count threshold corresponding to the preset access heat, the reference access heat corresponding to the target data item in the cache is determined from several preset access heat levels. If the preset conditions are met, the reference access popularity is determined as the current access popularity corresponding to the target data item; the preset conditions are that the level of the reference access popularity is higher than or equal to the level of the target data item's previous access popularity at the previous moment, or that the level of the reference access popularity determined continuously within the preset time period is lower than the level of the target data item's previous access popularity. If the preset conditions are not met, the previous access popularity will be determined as the current access popularity. Accordingly, the formula for calculating the decayed access count result is: ;in, Represents the target data item At any moment The current decayed access count result; Represents data items At any moment The current decayed access count result; Indicates the exponential decay factor; Indicates the preset attenuation coefficient; express and The time interval between; express The number of new visits within.

4. The cache optimization method based on a distributed system according to claim 3, characterized in that, Determining the current consistency window corresponding to the target data item includes: The current consistency window corresponding to the target data item is obtained by calculating the ratio of the preset base window to the target sum; the target sum is the sum of the heat factor, business sensitivity factor and data item change frequency factor corresponding to the target data item; in, ; Represents the target data item The heat factor, Represents the target data item At the present moment The decayed access count results, This indicates the preset general hotspot counting threshold corresponding to the general hotspot; ; Represents the target data item The data item change frequency factor; Describe the target data item The actual frequency of changes; This indicates the preset baseline change frequency.

5. The cache optimization method based on a distributed system according to claim 4, characterized in that, Also includes: Pareto equilibrium evaluation is performed on the overall actual hit rate and overall actual inconsistency event rate corresponding to all the target data items. If the current state is not Pareto optimal, adjust the preset base window to adjust the current consistency window, and adjust all the preset counting thresholds to adjust the current access heat, until Pareto optimal is achieved.

6. The cache optimization method based on a distributed system according to claim 5, characterized in that, The adjustment of the preset base window to adjust the current consistency window includes: Identify the dominant factors that cause the current state to be non-Pareto optimal; If the dominant factor is the hit rate, then the preset base window is reduced by a preset percentage to obtain a new preset base window; If the dominant factor is the inconsistency event rate, then the preset base window of the preset percentage is expanded to obtain a new preset base window; Accordingly, adjusting all the preset counting thresholds to adjust the current access popularity includes: The excess update cost is obtained by calculating the difference between the total update cost and the preset total update cost; the total update cost is the sum of the actual update costs of all the target data items. The heat threshold adjustment coefficient is determined based on the total update cost, the excess update cost, and the adjustment rate. Using the heat threshold adjustment coefficient, all preset count thresholds are adjusted to increase the preset count threshold when the update cost excess is positive and decrease the preset count threshold when the update cost excess is negative.

7. The cache optimization method based on a distributed system according to any one of claims 1 to 6, characterized in that, After determining the current access popularity of the target data item in the cache from several preset access popularity levels based on the decayed access count result at the current moment, the method further includes: Calculate the burst access multiplier corresponding to the target data item in real time; If the burst access rate is greater than a preset access rate threshold, then according to the preset level improvement rule, a level higher than the current access popularity is selected as the new current access popularity corresponding to the target data item; the preset level improvement rule specifies the correspondence between the target difference and the level improvement amount under each preset access popularity; the target difference is the difference between the burst access rate and the preset access rate threshold.

8. A cache optimization device based on a distributed system, characterized in that, include: The access heat determination module is used to determine the current access heat corresponding to the target data item in the cache from several preset access heat levels based on the decaying access count results at the current moment. The consistency window determination module is used to determine the current consistency window corresponding to the target data item; the current consistency window represents the maximum allowed duration of the old target data item data in the cache after the data source changes; The strategy determination module is used to determine, from several preset cache update strategies, a cache update strategy that is compatible with both the current access popularity and the current consistency window, and use it as the current cache update strategy corresponding to the target data item. The access popularity level is positively correlated with the degree of initiative in data update operations by the cache update strategy; the preset cache update strategy specifies the cache update methods corresponding to several cache levels; The cache update module is used to update the cache of the target data item in different levels of cache based on the current cache update strategy when the target data item in the data source is updated, so as to optimize the cache of the distributed system.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the cache optimization method based on a distributed system as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the cache optimization method based on a distributed system as described in any one of claims 1 to 7.