Cache data updating method, device, equipment, storage medium and program

By obtaining the historical update time information of the original data, dynamically adjusting the effective time of cached data, solving the problem of frequent or inaccurate updates of cached data in the existing technology, and achieving efficient and accurate updates of cached data.

CN114185905BActive Publication Date: 2025-03-25LANXIN MOBILE (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111481355.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2025-03-25
Estimated Expiration
2041-12-06

AI Technical Summary

Technical Problem

In the prior art, it is difficult to set the effective time of data cache, resulting in frequent updates or inaccurate cached data.

Method used

By obtaining the historical update time information of the original data corresponding to the cached data, the time range for data changes is determined, and the effective duration of the cached data is dynamically adjusted according to the time range to flexibly update the cached data.

Benefits of technology

It avoids multiple unnecessary updates outside the data change time range, reduces the workload of cached data updates, and ensures the accuracy and response speed of cached data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114185905B_ABST
    Figure CN114185905B_ABST
Patent Text Reader

Abstract

The present invention provides a cache data update method, device, equipment, storage medium and program. The cache data update method includes: obtaining the historical update time information of the first original data corresponding to the cache data; determining the time range of the data change according to the historical update time information; determining the effective duration of the cache data according to the time range of the data change, and updating the cache data according to the effective duration. At this time, the effective duration of the cache data is not a fixed value. The time range of the data change can correspond to a shorter effective duration of the cache data, and other time ranges can also set the corresponding effective duration of the cache data. Based on this, the effective duration of the cache data corresponding to different time ranges can be flexibly adjusted, thereby avoiding multiple unnecessary updates to the cache data outside the time range of the data change, and reducing the workload of updating the cache data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a cache data updating method, device, equipment, storage medium and program. Background Art

[0002] With the explosive growth of mobile Internet users, the rapid response capability of the server is facing unprecedented challenges. Among them, data caching technology can directly and efficiently improve the rapid response capability of the server.

[0003] In the prior art, data is generally cached in memory and a fixed effective duration is configured. The cached data is updated at intervals of the effective duration. If the effective duration is short, it is easy for the original data to remain unchanged for a long time, but the cached data is frequently updated. If the effective duration is long, the cached data may not be accurate. Therefore, how to set an appropriate effective duration is a technical problem that technicians in this field need to solve urgently. Summary of the invention

[0004] In view of the problems in the prior art, embodiments of the present invention provide a cache data updating method, apparatus, device, storage medium and program.

[0005] Specifically, the embodiment of the present invention provides the following technical solutions:

[0006] In a first aspect, an embodiment of the present invention provides a cache data update method. The cache data update method includes:

[0007] Obtain historical update time information of first original data corresponding to the cached data;

[0008] Determine the time range of data changes based on the historical update time information;

[0009] Determine the validity period of the cached data according to the time range of the data change;

[0010] The cached data is updated according to the validity period.

[0011] Further, determining the validity period of the cached data according to the time range of the data change, and updating the cached data according to the validity period, includes:

[0012] Within the time range of the data change, determining the validity period as a first validity period, and updating the cached data according to the first validity period to obtain new cached data;

[0013] Outside the time range of the data change, the effective duration is determined to be a second effective duration, and the cached data is updated according to the second effective duration to obtain new cached data; the first effective duration is less than the second effective duration.

[0014] Furthermore, the second effective duration is equal to the first preset duration minus the duration of the time range of the data change.

[0015] Further, updating the cache data according to the first effective duration includes:

[0016] After the cache duration of the cache data reaches the first effective duration, obtaining the i-th batch of second original data corresponding to the cache data; i is an integer greater than 1;

[0017] If the response time of the i-th batch of second original data is longer than the second preset time, obtaining the (i+1)-th batch of second original data corresponding to the cached data after a third preset time;

[0018] If the response time of the i-th batch of second original data is less than or equal to the second preset time, the i+1-th batch of second original data corresponding to the cached data is obtained.

[0019] Furthermore, the method further comprises:

[0020] If updating the cache data fails, the first effective time length is increased.

[0021] Furthermore, after receiving the cache data read request, the method further includes:

[0022] Determining whether the cached data is valid;

[0023] If the cache data is valid, reading corresponding data from the cache data;

[0024] If the cache data is invalid, determining whether to execute an update operation of the cache data according to a cache data update identifier;

[0025] If the update operation of the cached data is not performed, then performing a step of determining the validity period of the cached data according to the time range of the data change;

[0026] If the update operation of the cache data is being executed, the corresponding data continues to be read from the cache data.

[0027] Furthermore, before determining that the cache data update operation has not been performed and performing the cache data update operation, the method further includes: updating the state of the cache data update identifier to a first state; the first state is used to indicate that the cache data update operation is being performed;

[0028] After updating the cache data, the method further includes: updating the state of the cache data update flag to a second state; the second state is used to indicate that the cache data update operation has not been performed.

[0029] In a second aspect, an embodiment of the present invention further provides a cache data updating device, including:

[0030] An acquisition module, used to acquire historical update time information of first original data corresponding to the cached data;

[0031] A processing module, used to determine a time range of data changes according to the historical update time information;

[0032] The processing module is further used to determine the effective duration of the cached data according to the time range of the data change, and update the cached data according to the effective duration.

[0033] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the cache data update method described in the first aspect are implemented.

[0034] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the cache data updating method described in the first aspect.

[0035] In a fifth aspect, an embodiment of the present invention further provides a computer program product having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the steps of the cache data updating method described in the first aspect.

[0036] The cache data update method, device, equipment, storage medium and program provided by the embodiments of the present invention can obtain the historical update time information of the first original data corresponding to the cache data, so that the time range of data change of the first original data corresponding to the cache data can be determined according to the historical update time information. When the cache data is updated, the effective time of the cache data is determined according to the time range of the data change, and the cache data is updated according to the effective time. At this time, the effective time of the cache data is not a fixed value. The time range of data change, that is, within the time range in which the original data may change, can be set to a shorter effective time of the cache data. For other time ranges, the effective time of the corresponding cache data can also be set according to actual conditions. Based on this, the effective time of the cache data corresponding to different time ranges can be flexibly adjusted, thereby avoiding multiple unnecessary updates to the cache data outside the time range of data change, and reducing the workload of cache data update. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are 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.

[0038] Figure 1 An application scenario diagram of an embodiment of the cache data update method provided by the present invention;

[0039] Figure 2 A schematic diagram of a flow chart of an embodiment of a cache data updating method provided by the present invention;

[0040] Figure 3 A schematic diagram of a flow chart of another embodiment of the cache data updating method provided by the present invention;

[0041] Figure 4 A schematic flow chart of another embodiment of the cache data updating method provided by the present invention;

[0042] Figure 5 It is a structural diagram of an embodiment of a cache data updating device provided by the present invention;

[0043] Figure 6 It is a structural schematic diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] In the related art, the server caches frequently used data in memory to improve the server's ability to respond quickly. When the server caches data in memory, a fixed effective duration is generally configured. The cached data is updated at each effective duration. When a request from a client is received, the cached data in the memory is used first to speed up data access. If the cached data expires, new original data is requested again and cached. If the effective duration is short, it is easy for the original data to remain unchanged for a long time, but the cached data is frequently updated. If the effective duration is long, the cached data may not be accurate. Therefore, how to set a suitable effective duration is a technical problem that technicians in this field urgently need to solve. In addition, if the cached data expires, the request for new original data also fails, which will cause the client's request to fail. If the amount of cached data is relatively large, once the cache expires, the pull of new data will occupy a large amount of network bandwidth, which may affect other services.

[0046] The method of the embodiment of the present invention can be applied to cache data update scenarios, and update in different time ranges with corresponding appropriate effective durations, for example, cache data update of a browser.

[0047] Figure 1 The application scenario diagram provided by an embodiment of the present invention, optionally, as Figure 1 As shown, the application scenario includes at least one user device 11, an electronic device 12 and a server 13; the user device 11 can be a terminal device where the user's client is located, such as a desktop computer, a laptop computer, a tablet, a mobile phone, etc.

[0048] Among them, the user equipment 11, the electronic device 12, and the server 13 can be connected through a network, such as a communication network such as 4G, 5G, or Wireless Fidelity (WIFI).

[0049] The electronic device 12 is mainly used to obtain the first original data corresponding to the cached data and the historical update time information of the first original data from the server 13. The electronic device 13 is also used to determine the time range of data change according to the historical update time information; determine the effective time of the cached data according to the time range of data change, and update the cached data according to the effective time.

[0050] The method provided by the present invention can be implemented by an electronic device 12 such as a processor executing a corresponding software code, or it can be implemented by the electronic device 12 executing the corresponding software code while interacting with the server 13, such as the server executing some operations to control the electronic device to execute the cache data update method.

[0051] The cache data updating method of the embodiment of the present invention defines the time range of data change of the first original data according to the historical update time information of the first original data corresponding to the cache data. According to the time range of the data change, the effective time of the corresponding cache data is set, and the effective time of the cache data corresponding to different time ranges can be flexibly adjusted. According to the time range of the data change, the effective time of the cache data is determined, and the cache data is updated according to the effective time.

[0052] The following embodiments are all described with electronic devices as the execution subject. Figure 2-Figure 4 The technical solution of the present invention is described in detail with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0053] Figure 2 It is a flow chart of an embodiment of a cache data updating method provided by an embodiment of the present invention.

[0054] like Figure 2 As shown, the method provided by the embodiment of the present invention includes:

[0055] Step 101: Obtain historical update time information of first original data corresponding to cached data.

[0056] Specifically, cached data refers to data cached in memory. The cached data is cached data acquired by a computer program based on the GO language or other computer languages. The first original data corresponding to the cached data is the original data of the cached data stored in the server. The historical update time information is the timestamp of each change of the first original data corresponding to the cached data.

[0057] The method for obtaining the historical update time information of the first original data corresponding to the cached data may be to record the update time information of the first original data corresponding to the cached data when updating the cached data, and obtain the historical update time information of the first original data based on the recorded multiple update time information. Alternatively, the historical update time information corresponding to the first original data may be recorded in the server, and the method for obtaining the historical update time information of the first original data corresponding to the cached data may also be to periodically obtain the historical update time information of the first original data corresponding to the cached data from the server.

[0058] For example, the cache data of a website of a public institution is updated 100 times a day, that is, the first original data corresponding to the cache data is obtained 100 times a day. In this process, each time the first original data is obtained, the update time information of the first original data can be obtained at the same time. The update time information of the first original data is obtained for 7 consecutive days, 1 consecutive month, or 1 consecutive year, and then summarized to obtain the historical update time information.

[0059] Step 102: Determine the time range of data changes based on historical update time information.

[0060] The time range of the data change may be a time range including all historical update timestamps of the first original data, or may be a time range in which most timestamps appear among the historical update timestamps of the first original data.

[0061] Specifically, according to the historical update time information obtained in step 101, the time range of the data change can be determined by statistical analysis methods, or the historical update time information can be processed using a machine learning model to determine the time range of the data change.

[0062] For example, for a website of a certain institution, according to the historical update time information of the first original data obtained in step 101, that is, the historical update time information of the original data of the website server of the institution, statistical analysis shows that the change timestamp of the first original data (the original data of the website of the institution) appears between 9:00 and 18:00 on working days. From 18:00 to 9:00 of the next day, no historical update timestamp appears. At this point, it can be determined that the time range of the data change of the website of the institution is 9:00 to 18:00.

[0063] For another example, for a shopping website, according to the historical update time information of its first original data (the original data of the server of the shopping website), statistical analysis shows that the change timestamp of the original data (first original data) of the shopping website appears between 20:00 and 21:00 every day, and no historical update timestamp appears from 21:00 to 20:00 the next day. At this time, it can be determined that the time range of the data change of the shopping website is 20:00 to 21:00.

[0064] Step 103: Determine the effective duration of the cached data according to the time range of the data change.

[0065] Specifically, the effective duration of cached data can be set according to the frequency of data changes. For example, if the first original data of a website changes 6 times per hour every day, the effective duration of cached data can be set to 10 minutes. For another example, if the first original data of a website changes once per hour every day, the effective duration of cached data can be set to 1 hour.

[0066] For example, for a website of a certain public institution, the time range of data changes of the first original data is 9:00-18:00 on weekdays. At this time, the effective duration of the corresponding cached data is 10 minutes. Therefore, within the time range of 9:00-18:00 on weekdays, the cached data is updated with 10 minutes as the effective duration of the cached data.

[0067] Step 103: Update cache data according to the effective time

[0068] For example, for a complete shopping trip, the time range of data change of the first original data is 20:00-21:00 every day. At this time, the valid time of the corresponding cached data is 5 minutes. Then, within the time range of 20:00-21:00 every day, the cached data is updated with 5 minutes as the valid time of the cached data.

[0069] It should be understood that in practical applications, the time range of data changes can be further divided into a first time range in which data changes frequently and a second time range in which data changes less frequently. Accordingly, when updating cached data, the corresponding effective duration is determined according to the first time range and the cached data is updated according to the effective duration. The corresponding effective duration is determined according to the second time range and the cached data is updated according to the effective duration.

[0070] The cache data update method, device, equipment, storage medium and program provided by the embodiments of the present invention can obtain the historical update time information of the first original data corresponding to the cache data, so that the time range of data change of the first original data corresponding to the cache data can be determined according to the historical update time information. When the cache data is updated, the effective time of the cache data is determined according to the time range of the data change, and the cache data is updated according to the effective time. At this time, the effective time of the cache data is not a fixed value. The time range of data change, that is, within the time range in which the original data may change, can be set to a shorter effective time of the cache data. For other time ranges, the effective time of the corresponding cache data can also be set according to actual conditions. Based on this, the effective time of the cache data corresponding to different time ranges can be flexibly adjusted, thereby avoiding multiple unnecessary updates to the cache data outside the time range of data change, and reducing the workload of cache data update.

[0071] In one embodiment, step 103 and step 104 may be implemented as follows:

[0072] Within the time range of the data change, determine the effective duration as the first effective duration, and update the cached data according to the first effective duration to obtain new cached data;

[0073] Outside the time range of data change, the effective duration is determined to be the second effective duration, and the cached data is updated according to the second effective duration to obtain new cached data; the first effective duration is less than the second effective duration.

[0074] Specifically, the first effective duration corresponding to the time range of data changes can be set according to the frequency of data changes within the time range. When data changes frequently, the first effective duration can be reduced, and when the number of data changes is small, the first effective duration can be increased.

[0075] The first effective time period is shorter than the second effective time period, so that the cache data can be updated at a relatively high frequency within the time range of data changes, and the cache data can be updated at a relatively low frequency outside the time range of data changes.

[0076] For example, for a website of a certain institution, the time range of data changes is 9:00-18:00. When updating cached data, the cached data can be updated with a first effective duration of 10 minutes within the time range of 9:00-18:00. In the time range from 18:00 to 9:00 the next day, the cached data is updated with a second effective duration of 15 hours. In other words, cached data is not updated outside the time range of data changes.

[0077] For another example, for a shopping website, the time range of data changes is 20:00-21:00. When updating cached data, the cached data can be updated with a first effective time of 5 minutes within the time range of 20:00-21:00. The cached data can be updated with a second effective time of 23 hours within the time range of 21:00 to 20:00 the next day.

[0078] In the above implementation, the current time point can be determined first. If the current time point is within the time range of data changes, the cached data can be updated according to the first effective duration corresponding to the time range. If the current time point is outside the time range of data changes, the cached data can be updated according to the second effective duration corresponding to the time range. Based on this, the cached data can be updated with different effective durations in different time periods, which can avoid unnecessary updates to the cached data. Moreover, the first effective duration is less than the second effective duration, which can ensure that the update frequency of the cached data within the time range of data changes is greater than the update frequency outside the time range of data changes, thereby ensuring that unnecessary updates are reduced outside the time range of data changes.

[0079] Optionally, the second effective duration is equal to the first preset duration minus the duration of the time range of the data change.

[0080] Specifically, the first original data is in a cycle of data change, data maintenance, data change, and data maintenance. The first preset duration is the duration of a single cycle of the first original data completing a change and a maintenance. For example, the first preset duration is 1 day, the time range for data change is 8:00-12:00, and the time range for data change is 4 hours, then the second effective duration is equal to 1 day minus 4 hours. The second effective duration is 20 hours. For another example, the first preset duration can be 20 hours, the time range for data change is 8:00-10:00, and the time range for data change is 2 hours, then the second effective duration is equal to 20 hours minus 2 hours. The second effective duration is 18 hours.

[0081] In the above implementation, the second effective duration can be conveniently calculated by subtracting the duration of the time range of data change from the first preset duration.

[0082] In one embodiment, updating the cache data according to the first effective duration may be achieved by the following operations:

[0083] After the cache duration of the cached data reaches the first effective duration, obtaining the i-th batch of second original data corresponding to the cached data; i is an integer greater than 0;

[0084] If the response time of the i-th batch of second original data is longer than the second preset time, then obtaining the (i+1)-th batch of second original data corresponding to the cached data after the third preset time;

[0085] If the response time of the i-th batch of second original data is less than or equal to the second preset time, the (i+1)-th batch of second original data corresponding to the cached data is obtained.

[0086] Specifically, for cache data with a large amount of data, when updating, the corresponding first original data can be divided into multiple batches to be acquired and updated. The multiple batches of second original data constitute the first original data. Of course, when the cache data is updated, the first original data can be acquired once, or the second original data can be acquired multiple times, and the first original data composed of the multiple batches of second original data can be obtained after multiple batches.

[0087] The second preset time is the preset response time of the i-th batch of second original data. When the response time of the i-th batch of second original data is longer than the second preset time, it means that the response time of this batch of second original data is long and the response speed is slow. The next batch of second original data can be obtained after a period of time. The third preset time is the time required to suspend and wait for the next batch of second original data when the response time of the current batch of second original data is too long.

[0088] For example, for a website of a certain public institution, after the cache duration of the cached data reaches 10 minutes (the first effective duration), 5 batches of second original data corresponding to the cached data are obtained. The second preset duration is 3 seconds, and the third preset duration is 10 seconds. If the response duration of the first batch of second original data is 2 seconds, the second batch of second original data is directly obtained. If the response duration of the second batch of second original data is 5 seconds, wait for 10 seconds before obtaining the third batch of second original data corresponding to the cached data. If the response duration of the third batch of second original data is 3 seconds, wait for 10 seconds before obtaining the fourth batch of second original data. If the response duration of the fourth batch of second original data is 1 second, the fifth batch of second original data can be directly obtained without waiting.

[0089] In the above implementation, the cached data can be updated in batches. After obtaining the second original data of each batch, the response time of the second original data of the batch can be determined, and then the service response speed and service pressure of providing the first original data can be determined. If the response time of the second original data of the current batch is long, it means that the service response speed of providing the second original data is slow and the service pressure is high. At this time, you can wait and suspend for the third preset time, and then obtain the second original data of the subsequent batches, which can reduce the pressure of the service providing the first original data. In addition, when the amount of cached data is relatively large, the problem of slow service response speed of the original data is prone to occur. Waiting for the third preset time and then continuing to update can avoid excessive pressure on the server of the original data and avoid affecting other services.

[0090] In one embodiment, the cache data updating method further includes:

[0091] If the update of cache data fails, the first effective time length is increased.

[0092] Specifically, when updating cached data, if all the first original data corresponding to the cached data are obtained at one time and the data acquisition fails, the update is abandoned and the cached data remains the old cached data. At the same time, the first effective duration of the current cached data increases. When the first original data corresponding to the cached data is obtained in multiple batches and the second original data of a batch fails to be obtained, the acquisition of the second original data of the subsequent batches is stopped and the cached data update is abandoned. The cached data remains the old cached data. In addition, the first effective duration of the current cached data increases.

[0093] Optionally, after the current cache data update fails, if the next cache data update fails again, the first valid time length continues to increase. And, as the number of failures increases, the increase in the first valid time length increases accordingly.

[0094] For example, for a corporate website, the first effective duration is 20 minutes. After the cache time of the cached data reaches 20 minutes, the original data is obtained in 6 batches to update the cached data. During the update process, if the acquisition of the third batch of second original data fails, the acquisition of the fourth, fifth and sixth batches of second original data will be stopped, and the cached data update will be abandoned. The cached data of this corporate website is the old cached data, and the first effective duration is increased to 21 minutes. After the cache time of the cached data reaches 21 minutes, the original data is obtained in 6 batches to update the cached data. During the update process, if the acquisition of the second batch of second original data fails, the update will be stopped. The cached data of this corporate website is the old cached data, and the first effective duration is increased to 23 minutes. By analogy, the increase in the first effective duration shall not exceed 1 / 2 of the original first effective duration.

[0095] In the above implementation, after the current update of cached data fails, it can be determined that the service providing the first original data is abnormal. In this case, the first effective time can be increased, thereby reducing invalid calls to the abnormal service. In addition, after the current update operation fails, the old cached data can be provided, thereby avoiding the failure of the client's request.

[0096] In one embodiment, after receiving the cache data read request, the cache data update method further includes:

[0097] Determine whether cached data is valid;

[0098] If the cached data is valid, read the corresponding data from the cached data;

[0099] If the cached data is invalid, determine whether to perform an update operation on the cached data according to the state of the cached data update flag;

[0100] If the cache data update operation is not performed, then execute step 103-step 104;

[0101] If the cache data is being updated, the corresponding data will continue to be read from the cache data.

[0102] Specifically, if the cache data update flag exists or is a preset value, such as 1, it means that the cache data is being updated, and the state of the cache data update flag can be the first state. If the cache data update flag does not exist or is not a preset value, it means that the cache data is invalid, but the update process is not started, that is, the update operation is not performed, and the state of the cache data update flag can be the second state.

[0103] In actual applications, after receiving a cache data read request, if the cache data is valid, the current cache data is sent. If the cache data is invalid, it is necessary to further determine whether to perform a cache data update operation based on the cache data update flag. If the cache data update flag does not exist or is not a preset value, indicating that the cache data update operation has not been performed, the update operation is performed. If the cache data update flag exists or is a preset value, indicating that the cache data update operation is being performed, there is no need to repeat the update operation.

[0104] For example, after an enterprise website receives a cache data read request, it first determines whether the cache data is valid. If valid, the current cache data is directly sent. If invalid, it further determines whether the cache data update operation is being performed based on the cache data update identifier. If the update operation is being performed, the current cache data is sent. If the update operation is not performed, the update operation is performed. The update operation is the step of updating the cache data according to the time range of the data change and the effective time of the cache data corresponding to the time range as described in the above embodiment.

[0105] In the above implementation, when the cache data is invalid, before updating the cache data, it can be determined whether the cache data is being updated. If the cache data update operation is not performed, the update operation is performed, thereby avoiding repeated updates of the cache data.

[0106] In one embodiment, after determining that the cache data update operation has not been performed, when the cache data update operation needs to be performed, the following operations may also be performed: updating the state of the cache data update flag to a first state; the first state is used to indicate that the cache data update operation is being performed;

[0107] Optionally, after updating the cache data, the method further includes: updating the state of the cache data update identifier to a second state; the second state is used to indicate that the cache data update operation has not been performed.

[0108] Specifically, the cache data update mark may have two states, which respectively represent that the update operation is being executed and that the update operation is not being executed. By detecting the state of the cache data update mark, it can be identified whether the update operation is being executed.

[0109] When it is determined that the cache data update operation is not performed, the state of the cache data update flag is updated to the first state before the update operation, such as marking the cache data update flag, or setting the value of the existing cache data update flag to a preset value. After the cache data is updated, the state of the cache data update flag can be updated to the second state, such as deleting the cache data update flag, or setting the value of the cache data update flag to a value different from the preset value.

[0110] For example, an enterprise website receives a cache data read request, determines that the cache data is invalid, and judges that the cache data update operation has not been performed based on the cache data update identifier, first marks the cache data update identifier and then performs the update operation. After the update operation is completed, the cache data update identifier is updated again and the cache data update identifier is deleted.

[0111] In the above implementation, the cache data update flag is updated before and after the update operation is performed, so that the next process can quickly identify whether the update operation is being performed, thereby preventing repeated multiple update operations.

[0112] For example, Figure 3 As shown, the cache data updating method of this embodiment includes the following steps:

[0113] Step 1: Receive the request and read the cache.

[0114] After receiving the cache data request sent by the user device, the service component attempts to obtain the cache data.

[0115] Step 2: The cache processing component checks whether the current cache is expired. If not, it proceeds to step 2.1; if it is expired, it proceeds to step 2.2.

[0116] Step 2.1: If the check result is no and the current cache is not expired, the cache processing component uses the current cache data.

[0117] Step 2.2: If the check result is yes, the current cache has expired, and the cache processing component checks whether the cache data is being updated.

[0118] Step 2.2.1: If the result of the check that the cache data is being updated is no, the cache processing component updates the "updating" flag to prevent multiple updates to the cache.

[0119] Step 2.2.2: If the check result of cache data being updated is yes, the cache processing component continues to use the current cache data, giving priority to ensuring normal business operation.

[0120] Step 3: After the cache processing component updates the "updating" flag, the cache processing component submits a request to update the cache data to the update processing component.

[0121] Step 3.1, update request queue. The cache processing component writes the request to update cache data into the GOChannel (pipeline) to be cached, and updates the request queue in the GO Channel. The GO Channel to be cached may contain requests to update cache data received from multiple electronic devices.

[0122] Step 3.2: After the cache processing component submits the update of cache data, it continues to use the current cache data.

[0123] Step 4: The cache processing component uses the current cache and sends it to the business component.

[0124] Step 5: Update cache data. The update processing component detects whether there is a request to update cache data in the GO pipeline. If it is found, it enters the cache data update process.

[0125] like Figure 4 As shown, the cache data update process includes the following steps:

[0126] Step 1: The update processing component creates a new cache task and requests the first original data in batches.

[0127] Step 2: Determine whether the requested batch is smaller than the total batch. The update processing component loops to obtain the second original data according to the number of batches. If the loop request is completed, go to step 3. If the request is not completed, go to step 2.1.

[0128] Step 2.1: If the result of judging that the number of requests is less than the total batch is yes, the update processing component continues to request the second original data.

[0129] Step 2.2: The update processing component checks whether the return result of the request is successful. If yes, it goes to step 2.3; if not, it goes to step 6.

[0130] Step 2.3: If the result of the judgment of request success is yes, the request for the second original data is successful, then part of the cached data is updated.

[0131] Step 2.4: The update processing component checks whether the response time of the request for the second original data is greater than 3 seconds.

[0132] Step 2.5: If the result of the judgment that the response time is greater than 3 seconds is yes, it means that the service providing the first original data responds slowly, and the pressure on the service may be relatively high, so the process of updating the cached data is suspended for 10 seconds.

[0133] Step 2.6, continue to cycle and acquire the first raw data in batches.

[0134] Step 3: If the number of requests is less than the total batch, the result of the judgment is no, and the process of cyclically obtaining the first original data has ended, the update processing component archives the change time of the first original data for calculating the effective time of the cached data.

[0135] Step 4: The update processing component calculates the effective duration of cached data, which mainly involves the following scenarios:

[0136] 1) For enterprises and institutions that only work from 9:00 to 18:00 on weekdays, the change record of the first original data should only contain data from this time period. Therefore, there are two options for the effective duration of the newly generated cache data:

[0137] a) If the cache update operation occurs within this time period, the validity period of the cached data can be set to 10 minutes, that is, it will take effect at the latest 10 minutes after the first original data is changed.

[0138] b) If the cache update operation occurs after 18:00, the effective period of the cache data can be set to 15 hours. That is, there is no need to update the cache at night because you don't work at night and won't modify the original data. Wait until the cache expires the next day and then update the cache. At this time, the cache time should be set to 10 minutes.

[0139] 2) Through the archived records of the first original data, it is found that the change time is between 20:00 and 21:00 in the evening. Then, according to the newly generated cache time, there are two options for the effective duration of the cache data:

[0140] a) If the newly generated cache data is between 20:00 and 21:00, the effective duration of the cache data can be set to 10 minutes;

[0141] b) If the newly generated cache data is after 21:00, the effective duration of the cache data can be set to 23 hours, that is, the cache will expire at 20:00 the next day.

[0142] Step 5: New cache data has been generated, and the expiration time of the cache data has been set. At this time, the current old cache data is switched to the new cache data.

[0143] Step 6: If the request is judged as not successful, the loop is exited and the cache data update is abandoned.

[0144] Step 7. Extend the validity period of the current cached data. Considering that the service providing the first original data may be abnormal, the current cached data continues to be used, and the cached data is updated after a delay. As the number of cached data update failures increases, the extension time becomes longer. For example, if the first update of cached data fails, the validity period of the cached data is extended by 1 minute. After the cached data expires, the cache is updated again. If it fails again, the validity period is extended by 2 minutes, and so on. The extension time shall not exceed 5 minutes. The purpose is to reduce invalid calls to abnormal services.

[0145] The cache data updating method provided by the embodiment of the present invention obtains the historical update time information of the first original data corresponding to the cache data, so that the time range of data change of the first original data corresponding to the cache data can be determined according to the historical update time information. When the cache data is updated, the effective time of the cache data is determined according to the time range of the data change, and the cache data is updated according to the effective time. At this time, the effective time of the cache data is not a fixed value. The time range of data change, that is, within the time range in which the original data may change, can be set to a shorter effective time of the cache data. For other time ranges, the effective time of the corresponding cache data can also be set according to actual conditions. Based on this, the effective time of the cache data corresponding to different time ranges can be flexibly adjusted, thereby avoiding multiple unnecessary updates to the cache data outside the time range of data change, and reducing the workload of cache data update.

[0146] The cache data updating device provided by the present invention is described below. The cache data updating device described below and the cache data updating method described above can be referred to each other.

[0147] Figure 5 1 is a schematic diagram of the structure of an embodiment of a cache data updating device provided by the present invention. Figure 5 As shown, the cache data updating device provided in this embodiment includes:

[0148] An acquisition module 210 is used to acquire historical update time information of the first original data corresponding to the cached data;

[0149] A processing module 220, configured to determine a time range of data changes according to the historical update time information;

[0150] The processing module 220 is further configured to determine a valid time period of the cached data according to a time range of the data change, and update the cached data according to the valid time period.

[0151] Optionally, the processing module 220 is specifically configured to:

[0152] Within the time range of the data change, determining the validity period as a first validity period, and updating the cached data according to the first validity period to obtain new cached data;

[0153] Outside the time range of the data change, the effective duration is determined to be a second effective duration, and the cached data is updated according to the second effective duration to obtain new cached data; the first effective duration is less than the second effective duration.

[0154] Optionally, the second effective duration is equal to the first preset duration minus the duration of the time range of the data change.

[0155] Optionally, the processing module 220 is further configured to:

[0156] After the cache duration of the cache data reaches the first effective duration, obtaining the i-th batch of second original data corresponding to the cache data; i is an integer greater than 0;

[0157] If the response time of the i-th batch of second original data is longer than the second preset time, obtaining the (i+1)-th batch of second original data corresponding to the cached data after a third preset time;

[0158] If the response time of the i-th batch of second original data is less than or equal to the second preset time, the i+1-th batch of second original data corresponding to the cached data is obtained.

[0159] Optionally, the processing module 220 is specifically configured to:

[0160] If updating the cache data fails, the first effective time length is increased.

[0161] Optionally, the processing module 220 is further configured to:

[0162] Determining whether the cached data is valid;

[0163] If the cache data is valid, reading corresponding data from the cache data;

[0164] If the cached data is invalid, determining whether to execute an update operation of the cached data according to a state of a cached data update identifier;

[0165] If the update operation of the cached data is not performed, then performing a step of determining the validity period of the cached data according to the time range of the data change;

[0166] If the update operation of the cache data is being executed, the corresponding data continues to be read from the cache data.

[0167] Optionally, the processing module 220 is further configured to:

[0168] After determining that the cache data update operation has not been performed, before performing the cache data update operation, updating the state of the cache data update identifier to a first state; the first state is used to indicate that the cache data update operation is being performed;

[0169] After the cache data is updated, the state of the cache data update flag is updated to a second state; the second state is used to indicate that the cache data update operation is not performed.

[0170] The device of the embodiment of the present invention is used to execute the method in any of the aforementioned method embodiments. Its implementation principle and technical effects are similar and will not be repeated here.

[0171] Here is an example:

[0172] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the following method: obtaining the historical update time information of the first original data corresponding to the cached data; determining the time range of the data change according to the historical update time information; determining the effective time of the cached data according to the time range of the data change, and updating the cached data according to the effective time.

[0173] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0174] On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the cache data update method provided in the above embodiments is implemented to execute the following steps: obtaining historical update time information of the first original data corresponding to the cache data; determining a time range for data changes based on the historical update time information; determining a valid period for the cache data based on the time range for data changes, and updating the cache data based on the valid period.

[0175] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0176] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0177] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A cache data updating method, characterized in that: include: Obtain historical update time information of first original data corresponding to the cached data; Determine the time range of data changes based on the historical update time information; Determine the validity period of the cached data according to the time range of the data change; Update the cached data according to the validity period; Determining the validity period of the cached data according to the time range of the data change, and updating the cached data according to the validity period, includes: Within the time range of the data change, determining the validity period as a first validity period, and updating the cached data according to the first validity period to obtain new cached data; The updating of the cache data according to the first effective time period includes: After the cache duration of the cache data reaches the first effective duration, obtaining the i-th batch of second original data corresponding to the cache data; i is an integer greater than 0; If the response time of the i-th batch of second original data is longer than the second preset time, obtaining the (i+1)-th batch of second original data corresponding to the cached data after a third preset time; If the response time of the i-th batch of second original data is less than or equal to the second preset time, the i+1-th batch of second original data corresponding to the cached data is obtained.

2. The cache data updating method according to claim 1, characterized in that: The determining the effective duration of the cached data according to the time range of the data change, and updating the cached data according to the effective duration, further includes: Outside the time range of the data change, the effective duration is determined to be a second effective duration, and the cached data is updated according to the second effective duration to obtain new cached data; the first effective duration is less than the second effective duration.

3. The cache data updating method according to claim 2, characterized in that: The second effective duration is equal to the first preset duration minus the duration of the time range of the data change.

4. The cache data updating method according to claim 2 or 3, characterized in that: The method further comprises: If updating the cache data fails, the first effective time length is increased.

5. The cache data updating method according to any one of claims 1 to 3, characterized in that: After receiving the cache data read request, the method further includes: Determining whether the cached data is valid; If the cache data is valid, reading corresponding data from the cache data; If the cached data is invalid, determining whether to execute an update operation of the cached data according to a state of a cached data update identifier; If the update operation of the cached data is not performed, then performing a step of determining the validity period of the cached data according to the time range of the data change; If the update operation of the cache data is being executed, the corresponding data continues to be read from the cache data.

6. The cache data updating method according to claim 5, characterized in that: After determining that the cache data update operation has not been performed, before performing the cache data update operation, the method further includes: updating the state of the cache data update identifier to a first state; the first state is used to indicate that the cache data update operation is being performed; After updating the cache data, the method further includes: updating the state of the cache data update flag to a second state; the second state is used to indicate that the cache data update operation has not been performed.

7. A cache data updating device, characterized in that: include: An acquisition module, used to acquire historical update time information of first original data corresponding to the cached data; A processing module, used to determine a time range of data changes according to the historical update time information; The processing module is further used to determine the effective duration of the cached data according to the time range of the data change, and update the cached data according to the effective duration; The processing module is specifically used for: Within the time range of the data change, determining the validity period as a first validity period, and updating the cached data according to the first validity period to obtain new cached data; The processing module is further specifically used for: After the cache duration of the cache data reaches the first effective duration, obtaining the i-th batch of second original data corresponding to the cache data; i is an integer greater than 0; If the response time of the i-th batch of second original data is longer than the second preset time, obtaining the (i+1)-th batch of second original data corresponding to the cached data after a third preset time; If the response time of the i-th batch of second original data is less than or equal to the second preset time, the i+1-th batch of second original data corresponding to the cached data is obtained.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the cache data updating method according to any one of claims 1 to 6 are implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the cache data updating method as claimed in any one of claims 1 to 6 are implemented.

10. A computer program product having executable instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor implements the steps of the cache data updating method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Log analysis-based business processing method and apparatus, and computer device

    CN108509323A

  • Method and device for updating buffer memory, buffering equipment and storage medium

    CN108897495A