Cache data updating method and system, electronic equipment and storage medium
By obtaining time information in the business server, determining the update strategy and performing full or incremental updates, combined with high-frequency incremental and low-frequency full updates, the problem of low cache data update efficiency and poor accuracy in the existing technology is solved, and an efficient and accurate implementation is achieved. The cache data is updated.
Patent Information
- Application Number
- CN202311196823.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-15
- Publication Date
- 2024-10-18
AI Technical Summary
Existing cache data update methods are inefficient and inaccurate, especially in high-concurrency and large-traffic business request processing. Regular full updates result in low query efficiency and high costs, and it is difficult to set the incremental update frequency too high.
By obtaining the time when the business server starts and updates tasks, determine the full update or incremental update strategy, perform full or incremental updates based on the full update time interval threshold, and combine incremental updates and full updates to achieve high-frequency incremental updates and low-frequency full updates. combine.
It improves the efficiency and accuracy of cached data updates, reduces the database load, avoids the performance consumption caused by frequent full updates, and ensures data consistency and real-time performance.
Smart Images

Figure CN118796844A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a cache data updating method, system, electronic device and storage medium. Background Art
[0002] Local cache technology is designed to handle high-concurrency, high-traffic business request processing. The existing cache data update is generally done by querying the full amount of data each time through a scheduled task, and then updating the local cache as a whole; or by monitoring or message notification mechanisms to achieve incremental updates to the local cache. It can be seen that the above method will lead to low query efficiency and high cost of each full update through scheduled full updates. At the same time, since the database must be read in full each time, the update frequency cannot be set too high, resulting in low efficiency and low accuracy of cache data updates. Summary of the invention
[0003] Embodiments of the present invention provide a cache data updating method, system, electronic device and storage medium, which improve the efficiency and accuracy of cache data updating.
[0004] In a first aspect, an embodiment of the present invention provides a cache data updating method, comprising:
[0005] Get the first time when the business server is started;
[0006] Acquire a second time when the business server executes the update task;
[0007] If it is determined that the update strategy of the update task is a full update strategy, obtaining a full update time interval threshold;
[0008] A full update or an incremental update of the local database is performed according to the first time, the second time and the full update time interval threshold.
[0009] In one embodiment, the first time includes a full update time;
[0010] The performing a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold includes:
[0011] Determine a first time interval based on the full update time and the second time;
[0012] If it is determined that the first time interval is greater than the full update time interval threshold, performing a full update of the local database;
[0013] If it is determined that the first time interval is less than or equal to the full update time interval threshold, an incremental update of the local database is performed.
[0014] In one embodiment, the specific steps of performing the full update include:
[0015] Querying the first full amount of valid data in the business database, and converting the first full amount of valid data into a key value format to obtain the first target full amount of valid data;
[0016] The data in the local database is fully updated according to the first target full amount of valid data.
[0017] In one embodiment, the first time includes a query update time;
[0018] The specific steps of performing the incremental update include:
[0019] Determine a second time interval based on the query update time and the second time;
[0020] determining whether updated data is found in the service database according to the second time interval;
[0021] If it is determined that the updated data is found, each updated data is traversed and converted into a key value form to obtain the target data;
[0022] The data in the local database is incrementally updated according to the target data.
[0023] In one embodiment, the incrementally updating the data in the local database according to the target data includes:
[0024] Acquire the status field of the target data;
[0025] Determine an operation identifier of the target data based on the status field;
[0026] If it is determined that the operation identifier is an update operation, then incrementally updating the data in the local database according to the target data; or,
[0027] If it is determined that the operation identifier is a deletion operation, the data in the local database is deleted according to the target data.
[0028] In one embodiment, the specific steps of determining the full update time interval threshold include:
[0029] Get the preset full update time interval and the preset query update time interval;
[0030] Calculate the ratio of the preset full update time interval to the preset query update time interval to obtain a ratio calculation result;
[0031] If it is determined that the ratio calculation result is an integer, the preset full update time interval is determined as the full update time interval threshold;
[0032] If it is determined that the ratio calculation result is not an integer, the ratio calculation result is rounded up to obtain a rounded calculation result, the rounded calculation result and the preset query update time are multiplied, and the product calculation result is determined as the full update time interval threshold.
[0033] In one embodiment, before obtaining the first time when the service server is started, the method further includes:
[0034] Obtain the second full amount of valid data in the business database;
[0035] Convert the second full amount of valid data into a key value format to obtain the second target full amount of valid data;
[0036] The data in the local database is fully updated according to the second target full amount of valid data.
[0037] In a second aspect, an embodiment of the present invention provides a cache data update system, including:
[0038] A first time acquisition module, used to obtain the first time when the business server is started;
[0039] A second time acquisition module, used to acquire a second time when the business server executes the update task;
[0040] A third time acquisition module, configured to acquire a full update time interval threshold if it is determined that the update strategy of the update task is a full update strategy;
[0041] The cache data update module is used to perform a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold.
[0042] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the cache data update method described in the first aspect when executing the computer program.
[0043] In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium comprising a computer program, and when the computer program is executed by a processor, the cache data update method described in the first aspect is implemented.
[0044] The cache data update method, system, electronic device and storage medium provided by the embodiments of the present invention obtain the first time when the business server is started; obtain the second time when the business server executes the update task; if it is determined that the update strategy of the update task is a full update strategy, then obtain the full update time interval threshold; according to the first time, the second time and the full update time interval threshold, perform a full update or incremental update of the local database. In the process of updating cache data, high-frequency incremental updates are achieved by setting a smaller first time, and low-frequency full update data calibration is achieved by setting a larger first time, and the local cache data is accurately updated through the combination of incremental updates and full updates, thereby achieving high efficiency and accuracy of cache data updates. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the present invention or 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.
[0046] Figure 1 is a flow chart of a cache data updating method provided by an embodiment of the present invention;
[0047] Figure 2 is a schematic diagram of the architecture of the initialization module provided in an embodiment of the present invention;
[0048] Figure 3 is a schematic diagram of the architecture of an update task module provided in an embodiment of the present invention;
[0049] Figure 4 It is a schematic diagram of the architecture of the database table design fields provided by an embodiment of the present invention;
[0050] Figure 5 It is a flow chart of the overall solution of the cache data updating method provided by an embodiment of the present invention;
[0051] Figure 6 is a schematic diagram of a process flow for cache data request processing provided by an embodiment of the present invention;
[0052] Figure 7 is a schematic diagram of the structure of a cache data update system provided by an embodiment of the present invention;
[0053] Figure 8 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution 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.
[0055] Reference Figure 1 , Figure 1 1 is a flow chart of a cache data updating method provided by an embodiment of the present invention. An embodiment of the present invention provides a cache data updating method, comprising:
[0056] Step 101, obtaining the first time when the business server is started;
[0057] Step 102, obtaining a second time when the business server executes the update task;
[0058] Step 103: if it is determined that the update strategy of the update task is a full update strategy, a full update time interval threshold is obtained;
[0059] Step 104: perform a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold.
[0060] It should be noted that the embodiment of the present invention describes the cache data update method by taking the cache data update system as the execution subject, but the execution subject is not limited to the cache data update system. The cache data update system provided by the embodiment of the present invention is implemented through the memory of its own business server, queries the table data that needs to be cached in the business database, and caches the data in the local database, so that when receiving the user's processing request, it can be directly read and used through the cache data in the local database, wherein the cache data in the business database and the local database are usually stored in the form of table data, therefore, each type of cache data in the local database corresponds to a table, and a table can be transformed according to business needs through specific business rules to correspond to cache data in multiple local databases. The cache data update system includes an initialization module and an update task module, the cache data update system realizes the initialization of the business server through the initialization module, and realizes the update task of the business server through the update task module to perform a full update or incremental update of the local database.
[0061] It should be further explained that when the business server is started, the cache data update system will execute the initialization module, which includes the initialization time unit, the initialization update strategy unit, the initialization full cache unit and the initialization task unit. Figure 2, Figure 2 It is a schematic diagram of the architecture of the initialization module provided by an embodiment of the present invention. The cache data update system determines the startup time of the business server by initializing the time unit and sets the global time variable, and the global time variable includes the query update time and the full update time. The cache data update system sets the global variable parameters by initializing the update strategy unit. Through the global variable parameter setting, it can be determined that the executed update strategy is only the incremental update strategy, or the executed update strategy is a combination of the incremental update strategy and the full update strategy. The global variable parameters include a forced full update parameter (forceRefreshAll parameter), a full update time interval parameter (refreshAllInterval parameter) and a query update time interval parameter (refreshInterval parameter). Further, if forceRefreshAll=true is set, the cache data update system determines that the executed update strategy is the full update strategy, that is, when the update strategy is the full update strategy, the full update and incremental update processes coexist, and the refreshAllInterval parameter and the refreshInterval parameter are set. If forceRefreshAll=false is set, the cache data update system determines that the executed update strategy is the incremental update strategy and sets the refreshInterval parameter. The cache data update system initializes the full cache unit. When the business server starts, it queries all valid data in the business database table at one time, converts all valid data into key-value form according to the business calculation rules, and caches it to the local database to ensure that the business server can process business requests normally after startup. The cache data update system initializes the update task of the business server by initializing the task unit. According to the set global variable parameters, global time variables and update strategies, it regularly queries the updated data in the business database and updates it to the local database, thereby achieving high efficiency and accuracy of cache data updates and ensuring the consistency of table data and local cache data.
[0062] It should be further explained that when the business server executes the update task, the cache data update system will execute the update task module, which includes an update strategy judgment unit, a query unit, a calculation unit and an update unit. Figure 3 , Figure 3It is a schematic diagram of the architecture of the update task module provided by an embodiment of the present invention. The cache data update system determines which update strategy the data to be cached in the local database supports according to the global variable parameters set by the initialization module through the update strategy judgment unit. Further, if the cache data supports the full update strategy and this query meets the full update conditions, the cache data update system will query all valid data in the business database table at one time. If the cache data does not support the full update strategy and this query does not meet the full update conditions, the cache data update system will query the updated data in the business database table. The cache data update system determines the output of the update strategy judgment unit through the query unit, and determines whether this query is a full query or an incremental update query based on the output result. The cache data update system obtains the data queried by the query unit through the calculation unit, and converts it into a key value form according to the business calculation rules. Further, the cache data update system calculates whether each piece of data belongs to a normal update or a logical deletion through the calculation unit according to the status field (status) of each piece of data. The cache data update system determines the output of the update strategy judgment unit through the update unit, and determines the update plan based on the output result. If the update plan is a full update, the cache data update system will update the data in the local database to the key-value data output by the calculation unit. If the update plan is an incremental update, the cache data update system will determine the operation identifier of the update data according to the calculation result output by the calculation unit and the key, and perform incremental updates or deletions on the update data according to the operation identifier.
[0063] Specifically, the cache data update system obtains the first time when the business server is started. The first time includes the full update time and the query update time. Therefore, it can be understood that when the business server is started, the cache data update system obtains the start time of the business server, and records the full update time as the obtained start time of the business server, and records the query update time as the obtained start time of the business server.
[0064] Further, the cache data update system initializes the update task and executes the update task through the business server. Further, when the business server executes the update task, the cache data update system obtains the second time when the business server executes the update task, and obtains the timestamp between the query update time when the business server is started and the second time when the business server executes the update task based on the query update time when the business server is started and the second time when the business server executes the update task, and determines the obtained timestamp as the query time range of this update task, wherein the second time is the execution time when the business server executes the update task.
[0065] Furthermore, the cache data update system obtains a preset forceRefreshAll parameter, and determines an update strategy for the update task according to the preset forceRefreshAll parameter. The update strategy for the update task includes a full update strategy and an incremental update strategy.
[0066] Further, if the preset forceRefreshAll parameter determines that the update strategy of the update task is a full update strategy, the cache data update system obtains the full update time interval threshold. Further, the cache data update system performs a full update or incremental update of the local database according to the first time, the second time and the full update time interval threshold.
[0067] Furthermore, if the preset forceRefreshAll parameter determines that the update strategy of the update task is an incremental update strategy, the cache data update system performs an incremental update of the local database.
[0068] The cache data update method provided by the embodiment of the present invention includes: obtaining a first time when the business server is started; obtaining a second time when the business server executes an update task; if it is determined that the update strategy of the update task is a full update strategy, obtaining a full update time interval threshold; and executing a full update or incremental update of the local database according to the first time, the second time and the full update time interval threshold. In the process of updating cache data, high-frequency incremental updates are achieved by setting a smaller first time, and low-frequency full update data calibration is achieved by setting a larger first time. By combining incremental updates and full updates, local cache data is accurately updated, thereby achieving high efficiency and accuracy in updating cache data.
[0069] Furthermore, before obtaining the first time when the service server is started, it also includes:
[0070] Obtain the second full amount of valid data in the business database;
[0071] Convert the second full amount of valid data into a key value format to obtain the second target full amount of valid data;
[0072] The data in the local database is fully updated according to the second target full amount of valid data.
[0073] Specifically, when the business server is started, the cache data update system obtains the second full amount of valid data in the business database, that is, the cache data update system pulls the second full amount of valid data of the table data in the business database.
[0074] It should be noted that the business data table includes but is not limited to the update time field (update_time), the data status field (status) and the field that uniquely represents the data (unique_key). The update time field, the data status field and the field that uniquely represents the data can be named according to business needs. update_time is used to identify the update time when any field of a row of data changes. During the process of updating cached data, update_time can be used to query data updated within a period of time; Status is used to identify the current data status. The data status includes whether it is a logical deletion state and other business states. It can be enumerated and designed according to business needs, and the entire life cycle of a table data from writing to deletion can be determined by whether the table data is in a logical deletion state; unique_key is used to uniquely identify table data during cached data updates. It can be the primary key, unique key, or a value calculated from certain fields in the table and guaranteed to be unique. Reference Figure 4 , Figure 4 It is a schematic diagram of the architecture of the database table design fields provided in an embodiment of the present invention.
[0075] Furthermore, the cache data update system calculates the unique_key of each second full effective data according to the business calculation rules based on the second full effective data in the acquired business database, and converts the second full effective data into a key value form to obtain the second target full effective data. It should be noted that in the process of updating cache data, the cache data update system will convert the data into a key value form and store it in the local database. Therefore, the cache data update system can perform partial data updates when there is data update through unique_key, without the need to perform a full update every time.
[0076] Furthermore, the cache data update system fully updates the data in the local database according to the second target full amount of valid data.
[0077] The embodiment of the present invention obtains the second full valid data in the business database and converts the second full valid data into a key value form to obtain the second target full valid data, and fully updates the data in the local database according to the second target full valid data. By caching the full valid data in the business database in advance, the load pressure on the database during the cache data update process is reduced. At the same time, the delay of network transmission is avoided for each query, thereby ensuring the real-time and consistency of the query update.
[0078] Furthermore, the specific steps of determining the full update time interval threshold include:
[0079] Get the preset full update time interval and the preset query update time interval;
[0080] Calculate the ratio of the preset full update time interval to the preset query update time interval to obtain a ratio calculation result;
[0081] If it is determined that the ratio calculation result is an integer, the preset full update time interval is determined as the full update time interval threshold;
[0082] If it is determined that the ratio calculation result is not an integer, the ratio calculation result is rounded up to obtain a rounded calculation result, the rounded calculation result and the preset query update time are multiplied, and the product calculation result is determined as the full update time interval threshold.
[0083] Specifically, the cache data update system obtains a preset full update time interval according to a preset refreshAllInterval parameter, and obtains a preset query update time interval according to a preset refreshInterval parameter.
[0084] Furthermore, the cache data update system calculates the ratio of the preset full update time interval and the preset query update time interval according to the preset full update time interval and the preset query update time interval to obtain a ratio calculation result.
[0085] Further, if it is determined that the ratio calculation result is an integer, the cache data update system determines that the full update time interval threshold is a preset full update time interval.
[0086] Further, if it is determined that the ratio calculation result is not an integer, the cache data update system will round up the ratio calculation result to obtain a rounded calculation result. Further, the cache data update system will multiply the rounded calculation result and the preset query update time by the product calculation, and determine the product calculation result as the preset full update time interval. Therefore, it can be understood that if it is determined that the ratio calculation result is not an integer, the cache data update system determines the full update time interval threshold as:
[0087] t=(t1 / t2+1)*t2
[0088] Among them, t is the full update time interval threshold, t1 is the preset full update time interval, and t2 is the preset query update time interval.
[0089] In one embodiment, the preset full update time interval is 10 minutes, the preset query update time interval is 3 minutes, and the cache data update system calculates the ratio of the preset full update time interval and the preset query update time interval to obtain the ratio calculation result: Furthermore, the cache data update system determines that the ratio calculation result is not an integer, and rounds up to obtain a rounded calculation result of 4, and multiplies the rounded calculation result and the preset query update time to obtain a product calculation result of 12. Therefore, the cache data update system determines that the full update time interval threshold is 12 minutes, that is, the full update will be triggered when the cache data update system executes the fourth update task (12 minutes).
[0090] Therefore, it can be understood that the maximum full update time interval threshold = preset full update time interval + preset query update time interval, and the maximum query update time interval threshold = 2*preset query update time interval, wherein the maximum query update time interval threshold takes into account the situation where a full update occurs between two incremental updates, and the time intervals of all incremental updates that occur between every two full updates are the preset query update time intervals.
[0091] The embodiment of the present invention obtains a preset full update time interval and a preset query update time interval by presetting the refreshAllInterval parameter and the preset refreshInterval parameter, and calculates the ratio of the preset full update time interval and the preset query update time interval, and determines the full update time interval threshold according to the ratio calculation result, so as to ensure that each query update time interval is within a very small range, and can achieve high-frequency incremental update by setting a smaller query update time, and achieve low-frequency full update data calibration by setting a larger full update time, and at the same time, through the combination of incremental update and full update, the local cached data is accurately updated, thereby achieving high efficiency and accuracy of cached data update.
[0092] Further, based on the first time, the second time and the full update time interval threshold in step 103, performing a full update or an incremental update of the local database includes:
[0093] Determine a first time interval based on the full update time and the second time;
[0094] If it is determined that the first time interval is greater than the full update time interval threshold, performing a full update of the local database;
[0095] If it is determined that the first time interval is less than or equal to the full update time interval threshold, an incremental update of the local database is performed.
[0096] Specifically, the cache data update system determines a first time interval based on a first time when the server is started and a second time when the server performs an update task, wherein the first time includes a full update time, that is, the cache data update system calculates the difference between the second time and the full update time based on the full update time and the second time, and obtains the first time interval between the full update time and the second time.
[0097] Further, the cache data update system compares the numerical values of the first time interval and the full update time interval threshold according to the first time interval and the full update time interval threshold.
[0098] Further, if it is determined that the first time interval is greater than the full update time interval threshold, the cache data update system performs a full update of the local database. Further, if it is determined that the first time interval is less than or equal to the full update time interval threshold, the cache data update system performs an incremental update of the local database.
[0099] The embodiment of the present invention determines a first time interval according to a full update time and a second time, and executes a full update or incremental update of a local database according to the first time interval and a full update time interval threshold, and then implements an update strategy in which both incremental update and full update mechanisms coexist by updating a time field, a data status field, and a field representing unique data without introducing other middleware, thereby implementing short-cycle, high-frequency incremental updates and long-cycle, low-frequency full updates, thereby achieving high efficiency and accuracy in updating cached data, while avoiding dependence on other technologies, reducing implementation costs, and ensuring cached data consistency and real-time performance.
[0100] Furthermore, the specific steps of performing the full update include:
[0101] Querying the first full amount of valid data in the business database, and converting the first full amount of valid data into a key value format to obtain the first target full amount of valid data;
[0102] The data in the local database is fully updated according to the first target full amount of valid data.
[0103] Specifically, the cache data update system updates the full update time to the second time based on the second time when the server executes the update task. It should be noted that the full update time will be updated to the current update task execution time each time the update task is executed. Therefore, each time the full update is performed, the full update time interval is the difference between the current update task execution time and the last update task execution time, so as to ensure that each full update of the table data in the business database can be controlled within a larger time range, thereby achieving high efficiency and accuracy of cache data updates.
[0104] Furthermore, the cache data update system queries the first full amount of valid data in the business database. Furthermore, the cache data update system calculates the unique_key of each first full amount of valid data according to the first full amount of valid data and business calculation rules, and converts the first full amount of valid data into key value form to obtain the first target full amount of valid data.
[0105] Further, the cache data update system performs a full update of the data in the local database according to the first target full effective data. Further, the cache data update system ends the update task executed by the current business server and waits for the next update task.
[0106] The embodiment of the present invention obtains the first target full valid data by querying the first full valid data in the business database and converting the first full valid data into a key value form, and fully updates the data in the local database according to the first target full valid data, thereby avoiding inaccurate full update time caused by a business server clock problem, realizing full data calibration, and thus achieving high efficiency and accuracy of cache data updates.
[0107] Furthermore, the specific steps of performing the incremental update include:
[0108] Determine a second time interval based on the query update time and the second time;
[0109] determining whether updated data is found in the service database according to the second time interval;
[0110] If it is determined that the updated data is found, each updated data is traversed and converted into a key value form to obtain the target data;
[0111] The data in the local database is incrementally updated according to the target data.
[0112] Specifically, the cache data update system determines the second time interval based on a first time when the server is started and a second time when the server performs an update task, wherein the first time includes a query update time. That is, the cache data update system calculates the difference between the second time and the query update time based on the query update time and the second time to obtain the second time interval between the query update time and the second time.
[0113] Furthermore, the cache data update system updates the query update time to the second time based on the second time when the server executes the update task. It should be noted that the query update time will be updated to the current update task execution time each time the update task is executed. Therefore, each time the query is updated, the query update time interval is the difference between the current query update time and the last query update time, so as to ensure that each query update of the table data in the business database can be controlled within a smaller time range, thereby achieving the efficiency and accuracy of the cache data update, and if there is no problem with the business server clock, the incremental update can meet the real-time and accuracy of the local cache data.
[0114] Furthermore, the cache data update system determines in the service database whether update data is found within the second time interval according to the second time interval.
[0115] Further, if it is determined that the updated data is queried within the second time interval, the cache data update system traverses each updated data. Further, the cache data update system calculates the unique_key of each updated data according to the updated data and the business calculation rules, and converts the updated data into a key value form to obtain the target data.
[0116] Furthermore, the cache data update system incrementally updates the data in the local database according to the target data.
[0117] Furthermore, if it is determined that no update data is found within the second time interval, the cache data update system ends the update task currently executed by the service server and waits for the next update task.
[0118] The embodiment of the present invention determines the second time interval according to the query update time and the second time, determines that the updated data is queried according to the second time interval, traverses each update data, converts the update data into a key value form, obtains the target data, and incrementally updates the data in the local database according to the target data, and then accurately queries the updated data in the table within a period of time through the update time field, the data status field and the field that uniquely represents the data and the query update time, and realizes the incremental update of the cached data, which greatly reduces the implementation complexity of the incremental update of the cached data. At the same time, by updating the query update time each time, the time range of each scheduled query is reduced to a smaller range, and by initializing the custom query time interval size, the efficiency and accuracy of the query update are realized.
[0119] Further, the incrementally updating the data in the local database according to the target data includes:
[0120] Acquire the status field of the target data;
[0121] Determine an operation identifier of the target data based on the status field;
[0122] If it is determined that the operation identifier is an update operation, then incrementally updating the data in the local database according to the target data; or,
[0123] If it is determined that the operation identifier is a deletion operation, the data in the local database is deleted according to the target data.
[0124] It should be noted that, since the entire life cycle of each piece of data from writing to deletion needs to be recorded during the cache data update process, each query needs to determine each write operation of each piece of data in the business data table. Therefore, the business data table includes update_time and status. Each time the data is written, the update_time needs to be updated, and physical deletion cannot be used. The status needs to be used to identify logical deletion. Therefore, in each query update process, all updated data can be queried through update_time first, and then the status can be used to determine whether the updated data has been logically deleted.
[0125] Specifically, the cache data update system obtains the status field status of the target data, and determines the operation identifier of the target data based on the status.
[0126] Furthermore, if the operation is identified as an update operation, the cache data update system incrementally updates the target data to the data in the local database according to the unique_key of each updated data in a key manner. Furthermore, the cache data update system ends the update task executed by the current business server and waits for the next update task.
[0127] Furthermore, if the operation is identified as a delete operation, the cache data update system deletes the target data increment in the local database according to the unique_key of each updated data and the key. Furthermore, the cache data update system ends the update task executed by the current business server and waits for the next update task.
[0128] The embodiment of the present invention obtains the status field of the target data and determines the operation identifier of the target data based on the status field. According to the operation identifier, the target data is incrementally updated to the data in the local database or the target data is deleted in the local database. The operation identifier is used to determine whether the data is logically deleted, thereby realizing the perception of the entire life cycle of the data from writing to deletion. At the same time, the implementation complexity of the incremental update of the cached data is greatly reduced, the efficiency and accuracy of the cached data update are achieved, and the consistency and real-time performance of the cached data are guaranteed.
[0129] Further, refer to Figure 5 , Figure 5 : is a flow chart of the overall solution of the cache data update method provided by an embodiment of the present invention. Therefore, the overall process of the cache data update method provided by the present invention can be understood as follows:
[0130] When the business server is started, the cache data update system obtains the second full amount of valid data in the business database.
[0131] Furthermore, the cache data update system calculates the unique_key of each second full valid data according to the second full valid data in the acquired business database and the business calculation rules, and converts the second full valid data into a key value format to obtain the second target full valid data.
[0132] Furthermore, the cache data update system fully updates the data in the local database according to the second target full amount of valid data.
[0133] Furthermore, when the business server starts, the cache data update system obtains the start time of the business server, and records the full update time as the obtained start time of the business server, and records the query update time as the obtained start time of the business server.
[0134] Further, the cache data update system initializes the update task and executes the update task through the business server. Further, when the business server executes the update task, the cache data update system obtains the second time when the business server executes the update task, and obtains the timestamp between the query update time when the business server is started and the second time when the business server executes the update task according to the query update time when the business server is started, and determines the obtained timestamp as the query time range of this update task.
[0135] Furthermore, the cache data update system obtains a preset forceRefreshAll parameter, and determines an update strategy for the update task according to the preset forceRefreshAll parameter.
[0136] Further, if the preset forceRefreshAll parameter determines that the update strategy of the update task is a full update strategy, the cache data update system obtains the full update time interval threshold. Further, if the preset forceRefreshAll parameter determines that the update strategy of the update task is an incremental update strategy, the cache data update system performs an incremental update of the local database.
[0137] Further, after the cache data update system determines that the update strategy of the update task is the full update strategy, the cache data update system performs a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold.
[0138] Furthermore, the cache data update system calculates the difference between the second time and the full update time according to the full update time and the second time, so as to obtain a first time interval between the full update time and the second time.
[0139] Further, the cache data update system compares the numerical values of the first time interval and the full update time interval threshold according to the first time interval and the full update time interval threshold.
[0140] Further, if it is determined that the first time interval is greater than the full update time interval threshold, the cache data update system performs a full update of the local database.
[0141] Further, when the cache data update system executes a full update of the local database, the cache data update system updates the full update time to the second time based on the second time when the server executes the update task.
[0142] Furthermore, the cache data update system queries the first full amount of valid data in the business database. Furthermore, the cache data update system calculates the unique_key of each first full amount of valid data according to the first full amount of valid data and business calculation rules, and converts the first full amount of valid data into key value form to obtain the first target full amount of valid data.
[0143] Further, the cache data update system performs a full update of the data in the local database according to the first target full effective data. Further, the cache data update system ends the update task executed by the current business server and waits for the next update task.
[0144] Further, if it is determined that the first time interval is less than or equal to the full update time interval threshold, the cache data update system performs an incremental update of the local database.
[0145] Furthermore, when the cache data update system performs incremental update of the local database, the cache data update system calculates the difference between the second time and the query update time according to the query update time and the second time to obtain a second time interval between the query update time and the second time.
[0146] Furthermore, the cache data update system updates the query update time to the second time based on the second time when the server executes the update task.
[0147] Furthermore, the cache data update system determines in the service database whether update data is found within the second time interval according to the second time interval.
[0148] Further, if it is determined that the updated data is queried within the second time interval, the cache data update system traverses each updated data. Further, the cache data update system calculates the unique_key of each updated data according to the updated data and the business calculation rules, and converts the updated data into a key value form to obtain the target data.
[0149] Furthermore, the cache data update system incrementally updates the data in the local database according to the target data.
[0150] Furthermore, if it is determined that no update data is found within the second time interval, the cache data update system ends the update task currently executed by the service server and waits for the next update task.
[0151] Further, after the cache data update system determines that the update strategy of the update task is the incremental update strategy, the cache data update system calculates the difference between the second time and the query update time according to the query update time and the second time to obtain a second time interval between the query update time and the second time.
[0152] Furthermore, the cache data update system updates the query update time to the second time based on the second time when the server executes the update task.
[0153] Furthermore, the cache data update system determines in the service database whether update data is found within the second time interval according to the second time interval.
[0154] Further, if it is determined that the updated data is queried within the second time interval, the cache data update system traverses each updated data. Further, the cache data update system calculates the unique_key of each updated data according to the updated data and the business calculation rules, and converts the updated data into a key value form to obtain the target data.
[0155] Furthermore, the cache data update system incrementally updates the data in the local database according to the target data.
[0156] Furthermore, if it is determined that no update data is found within the second time interval, the cache data update system ends the update task currently executed by the service server and waits for the next update task.
[0157] Further, refer to Figure 6 , Figure 6is a flow chart of cache data request processing provided by an embodiment of the present invention. Therefore, the specific process of cache data request processing provided by the present invention can be understood as follows:
[0158] When the business server is started, the business server accesses the business database and queries the full amount of valid data in the business database. Further, the business database returns the full amount of valid data to the business server, and further, the business server converts the returned full amount of valid data into a key value format and caches it in the local database.
[0159] Further, the user sends a cache data update processing request to the business server through the cache data update system. Further, the business server receives the cache data processing request and queries the cache data in the local database according to the cache data processing request. Further, the local database returns the queried cache data to the business server.
[0160] Furthermore, the business server performs logical processing on the queried cache data to obtain target cache data, and returns the target cache data to the user through the cache data update system to respond to the user's cache data update processing request.
[0161] It should be noted that in high-traffic and high-concurrency services, a local database is generally set up on the business server to cache data in the local database to improve the efficiency of querying data, avoid the performance consumption of accessing the database for each access request, and improve the interface response speed. During the entire cache data request processing process, the business server does not directly interact with the business database when processing the request. It only interacts with the business database during the business server startup process and the execution of update tasks to update the local cache data and maintain data consistency.
[0162] The cache data updating system provided by the embodiment of the present invention is described below. The cache data updating system described below and the cache data updating method described above can be referred to each other. Figure 7 , Figure 7 is a structural diagram of a cache data update system provided in an embodiment of the present invention. The cache data update system provided in an embodiment of the present invention includes a first time acquisition module 701, a second time acquisition module 702, a third time acquisition module 703 and a cache data update module 704.
[0163] The first time acquisition module 701 is used to acquire the first time when the service server is started;
[0164] A second time acquisition module 702, used to acquire a second time when the business server executes the update task;
[0165] The third time acquisition module 703 is used to acquire a full update time interval threshold if it is determined that the update strategy of the update task is a full update strategy;
[0166] The cache data update module 704 is used to perform a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold.
[0167] The cache data update system provided by the embodiment of the present invention obtains the first time when the business server is started; obtains the second time when the business server executes the update task; if it is determined that the update strategy of the update task is a full update strategy, then obtains the full update time interval threshold; according to the first time, the second time and the full update time interval threshold, performs a full update or incremental update of the local database. In the process of updating cache data, high-frequency incremental updates are achieved by setting a smaller first time, and low-frequency full update data calibration is achieved by setting a larger first time, and the local cache data is accurately updated through the combination of incremental updates and full updates, thereby achieving high efficiency and accuracy of cache data updates.
[0168] In one embodiment, the cache data update system is further used to:
[0169] Obtain the second full amount of valid data in the business database;
[0170] Convert the second full amount of valid data into a key value format to obtain the second target full amount of valid data;
[0171] The data in the local database is fully updated according to the second target full amount of valid data.
[0172] In one embodiment, the third time acquisition module 703 is further used to:
[0173] Get the preset full update time interval and the preset query update time interval;
[0174] Calculate the ratio of the preset full update time interval to the preset query update time interval to obtain a ratio calculation result;
[0175] If it is determined that the ratio calculation result is an integer, the preset full update time interval is determined as the full update time interval threshold;
[0176] If it is determined that the ratio calculation result is not an integer, the ratio calculation result is rounded up to obtain a rounded calculation result, the rounded calculation result and the preset query update time are multiplied, and the product calculation result is determined as the full update time interval threshold.
[0177] In one embodiment, the cache data update module 704 is further configured to:
[0178] Determine a first time interval based on the full update time and the second time;
[0179] If it is determined that the first time interval is greater than the full update time interval threshold, performing a full update of the local database;
[0180] If it is determined that the first time interval is less than or equal to the full update time interval threshold, an incremental update of the local database is performed.
[0181] In one embodiment, the cache data update module 704 is further configured to:
[0182] Querying the first full amount of valid data in the business database, and converting the first full amount of valid data into a key value format to obtain the first target full amount of valid data;
[0183] The data in the local database is fully updated according to the first target full amount of valid data.
[0184] In one embodiment, the cache data update module 704 is further configured to:
[0185] Determine a second time interval based on the query update time and the second time;
[0186] determining whether updated data is found in the service database according to the second time interval;
[0187] If it is determined that the updated data is found, each updated data is traversed and converted into a key value form to obtain the target data;
[0188] The data in the local database is incrementally updated according to the target data.
[0189] In one embodiment, the cache data update module 704 is further configured to:
[0190] Acquire the status field of the target data;
[0191] Determine an operation identifier of the target data based on the status field;
[0192] If it is determined that the operation identifier is an update operation, then incrementally updating the data in the local database according to the target data; or,
[0193] If it is determined that the operation identifier is a deletion operation, the data in the local database is deleted according to the target data.
[0194] The specific embodiments of the cache data updating system provided by the present invention are substantially the same as the embodiments of the cache data updating method, and are not described in detail herein.
[0195] Figure 8 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 8 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 a computer program in the memory 830 to execute the steps of the cache data update method, for example including:
[0196] Get the first time when the business server is started;
[0197] Acquire a second time when the business server executes the update task;
[0198] If it is determined that the update strategy of the update task is a full update strategy, obtaining a full update time interval threshold;
[0199] A full update or an incremental update of the local database is performed according to the first time, the second time and the full update time interval threshold.
[0200] 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.
[0201] On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium includes a computer program, and the computer program can be stored on the non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the steps of the cache data update method provided in the above embodiments, for example, including:
[0202] Get the first time when the business server is started;
[0203] Acquire a second time when the business server executes the update task;
[0204] If it is determined that the update strategy of the update task is a full update strategy, obtaining a full update time interval threshold;
[0205] A full update or an incremental update of the local database is performed according to the first time, the second time and the full update time interval threshold.
[0206] 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.
[0207] 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.
[0208] 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: Get the first time when the business server is started; Acquire a second time when the business server executes the update task; If it is determined that the update strategy of the update task is a full update strategy, obtaining a full update time interval threshold; A full update or an incremental update of the local database is performed according to the first time, the second time and the full update time interval threshold.
2. The cache data updating method according to claim 1, characterized in that: The first time includes the full update time; The performing a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold includes: Determine a first time interval based on the full update time and the second time; If it is determined that the first time interval is greater than the full update time interval threshold, performing a full update of the local database; If it is determined that the first time interval is less than or equal to the full update time interval threshold, an incremental update of the local database is performed.
3. The cache data updating method according to claim 2, characterized in that: The specific steps of performing the full update include: Querying the first full amount of valid data in the business database, and converting the first full amount of valid data into a key value format to obtain the first target full amount of valid data; The data in the local database is fully updated according to the first target full amount of valid data.
4. The cache data updating method according to claim 2, characterized in that: The first time includes a query update time; The specific steps of performing the incremental update include: Determine a second time interval based on the query update time and the second time; determining whether updated data is found in the service database according to the second time interval; If it is determined that the updated data is found, each updated data is traversed and converted into a key value form to obtain the target data; The data in the local database is incrementally updated according to the target data.
5. The cache data updating method according to claim 4, characterized in that: The incrementally updating the data in the local database according to the target data includes: Acquire the status field of the target data; Determine an operation identifier of the target data based on the status field; If it is determined that the operation identifier is an update operation, then incrementally updating the data in the local database according to the target data; or, If it is determined that the operation identifier is a deletion operation, the data in the local database is deleted according to the target data.
6. The cache data updating method according to claim 1, characterized in that: The specific steps of determining the full update time interval threshold include: Get the preset full update time interval and the preset query update time interval; Calculate the ratio of the preset full update time interval to the preset query update time interval to obtain a ratio calculation result; If it is determined that the ratio calculation result is an integer, determining the full update time interval threshold to be the preset full update time interval; If it is determined that the ratio calculation result is not an integer, the ratio calculation result is rounded up to obtain a rounded calculation result, the rounded calculation result and the preset query update time are multiplied, and the product calculation result is determined as the preset full update time interval.
7. The cache data updating method according to any one of claims 1 to 6, characterized in that: Before obtaining the first time when the service server is started, the method further includes: Obtain the second full amount of valid data in the business database; Convert the second full amount of valid data into a key value format to obtain the second target full amount of valid data; The data in the local database is fully updated according to the second target full amount of valid data.
8. A cache data update system, characterized in that: include: A first time acquisition module, used to obtain the first time when the business server is started; A second time acquisition module, used to acquire a second time when the business server executes the update task; A third time acquisition module, configured to acquire a full update time interval threshold if it is determined that the update strategy of the update task is a full update strategy; The cache data update module is used to perform a full update or an incremental update of the local database according to the first time, the second time and the full update time interval threshold.
9. 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 computer program, the cache data updating method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium comprising a computer program, characterized in that: When the computer program is executed by a processor, the cache data updating method according to any one of claims 1 to 7 is implemented.
