Cache method for changing data, cache device and electronic device

By using the method of using version numbers to identify changed data, the version number interval of the changed data is determined and updated, which solves the problem of extended data synchronization when the data volume is huge and achieves the effect of fast synchronization to the cache.

CN116226191BActive Publication Date: 2025-09-23中国邮政储蓄银行股份有限公司
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211732152.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2025-09-23
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

When the amount of data is huge, synchronizing data to the cache in the existing technology will cause server pressure and network congestion, which will extend the synchronization time.

Method used

The version number is used to identify the changed data. By determining the version number interval of the changed data, the changed data is obtained and updated to the cache.

Benefits of technology

It achieves fast synchronization of changed data to the cache, solving the problem of prolonged data synchronization time caused by the huge amount of data when data is changed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116226191B_ABST
    Figure CN116226191B_ABST
Patent Text Reader

Abstract

The present application provides a method for caching changed data, a caching device, and an electronic device. The method includes: determining whether the data in the current table in the database has been updated; in the case that the data in the current table in the database has changed, obtaining the table version number of the current table, determining the version number interval of the changed data at least based on the change of the changed data and the table version number of the current table, and updating the table version number of the current table to obtain the version number of the updated table, the changed data is the data that has changed in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as the current table, adding data with different primary keys from the current table, deleting data in the current table; obtaining the changed data based on the version number interval of the changed data and the version number of the updated table; updating the changed data to the cached data. This method solves the technical problem of long data synchronization time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data, and in particular to a method for caching changing data, a caching device, a computer-readable storage medium, and an electronic device. Background Art

[0002] The cache is a buffer for data exchange. When reading data, the requested data is first searched in the cache. If the data is found, it is executed directly. If not, the data is searched in memory. Because the cache runs much faster than memory, its function is to help the hardware run faster. Therefore, data caching can improve access response speed and enhance the user experience. To ensure cached data consistency, every table data change must be updated synchronously in the cache.

[0003] However, when the amount of table data is huge, each full data synchronization will inevitably put a certain amount of pressure on the server, congest the network, and prolong the data synchronization time. Summary of the Invention

[0004] The main purpose of this application is to provide a method for caching changed data, a caching device, a computer-readable storage medium, and an electronic device, so as to at least solve the technical problem of prolonged data synchronization time caused by the huge amount of data when the data is changed.

[0005] In order to achieve the purpose, according to one aspect of the present application, a caching method for changed data is provided, including: determining whether the data in the current table in the database is updated; when the data in the current table in the database is changed, obtaining the table version number of the current table, determining the version number interval of the changed data at least based on the change situation of the changed data and the table version number of the current table, and updating the table version number of the current table to obtain the version number of the updated table, the changed data is the changed data in the updated table relative to the current table, and the change situation includes one of the following: adding data with the same primary key as the current table, adding data with a different primary key from the current table, deleting data in the current table; obtaining the changed data based on the version number interval of the changed data and the version number of the updated table; and updating the changed data to the cached data.

[0006] Optionally, determining whether the data in the current table in the database has been updated includes: obtaining the current major version number and the previous major version number of the current table, and determining that the data in the current table in the database has been updated if the current major version number is greater than the previous major version number.

[0007] Optionally, the version number interval of the changed data is determined based at least on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of data with a different primary key from the current table, determining [y+1, MAX) as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0008] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of new data with the same primary key as the current table, according to the same primary key in the current table, the version number interval of the first data is obtained, and the first data is the data with the same primary key in the current table; according to the version number interval of the first data, [x, y) is determined as the updated version number interval of the first data, wherein x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; according to the updated version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0009] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the deletion of data in the current table, obtaining the version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is the data deleted in the updated table relative to the current table, and the second data is the deleted data in the current table; according to the version number interval of the second data, determining [x, y) as the updated version number interval of the second data, wherein x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; according to the updated version number interval of the second data, determining [y+1, INIT-y-1) as the version number interval of the changed data, wherein y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is first updated.

[0010] Optionally, updating the table version number of the current table to obtain the version number of the updated table includes: calculating the sum of the table version number of the current table and 1 to obtain the version number of the updated table.

[0011] Optionally, the change data is obtained based on the version number interval of the change data and the version number of the update table, including: when the starting value of the version number interval is less than or equal to the version number of the update table and the ending value of the version number interval is greater than the version number of the update table, obtaining the data within the version number interval of the change data; when the ending value of the version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the update table, obtaining the data within the version number interval.

[0012] Optionally, updating the changed data to cached data includes: obtaining the primary key of the changed data; when the primary key of the changed data is different from the primary key in the cache, storing the changed data in the cache; when the primary key of the changed data is the same as the primary key in the cache, determining whether the end value of the version number interval of the changed data is a predetermined difference, the predetermined difference being the difference between the starting value of the version number interval before the first update and the version number of the update table; when the end value of the version number interval of the changed data is the predetermined difference, deleting the data in the cache whose primary key is the same as the primary key of the changed data; when the end value of the version number interval of the changed data is not the predetermined difference, updating the data in the cache to the changed data; after traversing all the data in the cache, updating the table version number in the cache to the version number of the update table.

[0013] In order to achieve the purpose, according to one aspect of the present application, a caching device for change data is provided, including: a first determination unit, used to determine whether the data in the current table in the database is updated; a second determination unit, used to obtain the table version number of the current table when the data in the current table in the database is changed, determine the version number interval of the change data at least based on the change situation of the change data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the change data is the changed data in the updated table relative to the current table, and the change situation includes one of the following: adding data with the same primary key as the current table, adding data with a different primary key from the current table, and deleting data in the current table; an acquisition unit, used to obtain the change data based on the version number interval of the change data and the version number of the update table; an update unit, used to update the change data to the cached data.

[0014] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the method of controlling any one of the devices where the computer-readable storage medium is located is described.

[0015] According to another aspect of the present application, a processor is provided, wherein the processor is configured to run a program, wherein the program executes any one of the methods described when the program is run.

[0016] According to another aspect of the present application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include a method for executing any one of the processing methods.

[0017] The technical solution of this application uses version numbers to identify changed data, determines the version number interval of the changed data, and then obtains the changed data and updates the changed data to the cached data. This achieves the purpose of synchronizing the changed data, thereby achieving the technical effect of quickly synchronizing the changed data to the cache, thereby solving the technical problem of prolonged data synchronization caused by the huge amount of data when the data is changed. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings that constitute part of this application are used to provide a further understanding of this application. The illustrative embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation on this application. In the drawings:

[0019] Figure 1 A hardware structure block diagram of a mobile terminal for executing cache of changed data provided in an embodiment of the present application is shown;

[0020] Figure 2 A schematic diagram of a process for caching change data provided according to an embodiment of the present application is shown;

[0021] Figure 3 A schematic diagram of the overall process of caching of change data provided according to an embodiment of the present application is shown;

[0022] Figure 4 A structural block diagram of a change data caching device provided according to an embodiment of the present application is shown;

[0023] The above drawings include the following reference numerals:

[0024] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. DETAILED DESCRIPTION

[0025] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0026] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] For ease of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0029] Mybatis: A data access layer framework that provides extensible interceptors.

[0030] SQL: Structured Query Language, the language used to operate relational databases.

[0031] Interceptor: A programming pattern used to intercept method parameters before the method is called to perform operations such as verification and assignment.

[0032] Major version number: This number indicates changes to table data in the database. All tables have the same major version number, starting from 9001. The major version number increases with each table data change.

[0033] Table version number: used to indicate the data update history of the table. Each table has a corresponding table version number, starting from 1001. The table version number increases every time the table data is changed.

[0034] Version relationship: The relationship between the major version number and the table version number when a table data change is associated. One major version number can correspond to multiple table version numbers. The major version number represents the history of database and table data updates, and the table version number represents the specific table data change history in this change.

[0035] AOP: Aspect-oriented programming ensures that certain common functions are added to system components without modifying the source code.

[0036] Jointpoint: represents a well-defined point in the program, typically including method calls, access to class members, and execution of exception handling program blocks, etc. It can also nest other joint points.

[0037] Pointcut: represents a set of joint points, which are either combined by logical relationships or gathered together by wildcards, regular expressions, etc. It defines where the corresponding advice will occur.

[0038] Advice: Advice defines the specific operations to be performed at the program points defined in Pointcut. It uses before, after, and around to distinguish whether the code is executed before, after, or instead of each joint point.

[0039] As introduced in the background technology, the prior art has a technical problem of extending the data synchronization time due to the huge amount of data when the data is changed. To solve this problem, the embodiments of the present application provide a caching method for changing data, a caching device, a computer-readable storage medium and an electronic device.

[0040] The technical solutions in the embodiments of the present invention will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present invention.

[0041] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG is a hardware structure block diagram of a mobile terminal of a method for caching change data according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0042] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the device information display method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0043] In this embodiment, a method for caching changing data running on a mobile terminal, a computer terminal or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0044] Figure 2 Flowchart of the method for caching change data according to an embodiment of the present application. Figure 2 As shown, the method includes the following steps:

[0045] Step S101, determining whether the data in the current table in the database is updated;

[0046] Specifically, you can identify whether data in the current database has been updated by adding a timestamp field to the table, analyzing the database's own logs, and establishing update triggers on business tables. Adding a timestamp field to the table means that when table data is updated, the timestamp field is modified simultaneously. During data synchronization, incremental data can be identified based on the system time and the timestamp field in the table. This method is relatively simple, but it cannot retrieve records deleted or updated before the timestamp. Analyzing the database's own logs involves introducing a log analysis mechanism. First, check the log configuration information, enable logging, and specify the log file path. This will reveal the time, operation type, ID, and detailed information. This requires developers to be familiar with database logging. Establishing an update trigger means that when data changes, the trigger writes the changed data to a temporary table. During synchronization, the data is extracted from the temporary table, and the data in the temporary table is marked or deleted after synchronization is complete. This solution offers high performance, but requires creating a new trigger on the business table, which has some impact on the business system. The above method can quickly determine whether data in the database has been updated.

[0047] Step S102, when data in the current table in the database changes, obtain the table version number of the current table, determine the version number interval of the changed data based at least on the change of the changed data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the changed data is the changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0048] Specifically, the table version number range used to identify the effective range of each data record update is used to identify the table version number. This range starts with the value INIT_VERSION_NO of 1001 and reaches a maximum value MAX_VERSION_NO of 999999999. The range is represented as a left-closed, right-open interval [x, y], indicating that the table version number for this record is valid from x to y-1. This method can accurately determine the version number range of the changed data.

[0049] Step S103, obtaining the above-mentioned change data according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table;

[0050] Specifically, different types of change data can be obtained based on the boundary values ​​of the version number range, such as newly added data with the same primary key as the current table, newly added data with different primary keys from the current table, and deleted data from the current table. The above method can quickly obtain change data.

[0051] Step S104: Update the above-mentioned changed data into the cached data.

[0052] Specifically, all the changed data are updated to the cache. The primary keys of the changed data are traversed in sequence. If the primary key is not in the cache, it means that the changed data is updated relative to the data in the cache, and the changed data is stored in the cache. If the primary key is in the cache, it can be determined again whether the changed data is data deleted from the database. If so, the data in the cache should be deleted as well. The above method can achieve the rapid update of the changed data to the cached data.

[0053] This embodiment uses version numbers to identify changed data, determines the version number interval for the changed data, and then obtains the changed data and updates the cached data. This achieves the goal of synchronizing the changed data, thereby achieving the technical effect of quickly synchronizing the changed data to the cache and resolving the technical issue of extended data synchronization time due to the large amount of data being modified.

[0054] In a specific implementation, step S101 can be implemented by the following steps: Step S1011, obtaining the current major version number and the previous major version number of the current table; Step S1012, if the current major version number is greater than the previous major version number, determining that the data in the current table in the database has been updated. In this method, the major version number is used to indicate that table data in the database has changed. All tables have the same major version number, starting from 9001, and the major version number is incremented each time a table data change occurs. This method can quickly determine whether the data in the current table in the database has been updated.

[0055] In order to further determine the version number interval of the changed data under different change situations, the above-mentioned step S102 of the present application can be implemented through the following steps: step S1021, when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, determine [y+1, MAX) as the version number interval of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data. In this method, when data with a different primary key from the above-mentioned current table is added, it means that the changed data is different from the primary key of the data in the current table, so it is a new data, therefore, the minimum value of the version number interval can be added by 1. As shown in Table 1, the primary key of the newly added data is KEY-1002, which is different from the primary key KEY-1001 of the original data in the table, so a new version number interval of [1002, 9999999999) is added.

[0056] Table 1 adds data with different primary keys from the current table above

[0057] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 999999999 Original data KEY-1002 50 1002 999999999 Change data

[0058] The above step S102 can also be implemented in other ways, for example: Step S1022, when the change situation represents the addition of data with the same primary key as the above current table, obtain the version number interval of the first data based on the same primary key in the above current table, and the above first data is the data with the same primary key in the above current table; Step S1023, based on the version number interval of the above first data, determine [x, y) as the updated version number interval of the above first data, wherein x is the starting value of the version number interval of the same data in the above current table, and y is the table version number of the above current table; Step S1024, based on the updated version number interval of the above first data, determine [y+1, MAX) as the version number interval of the above changed data, wherein y is the table version number of the above current table, and MAX is the maximum value of the table version number of the above changed data. In this method, when data with the same primary key as the above current table is added, it means that the changed data has the same primary key as the data in the current table, and therefore the existing data is updated. As shown in Table 2, based on the primary key, a record with a version number interval ending in 999999999 is found. Assuming the version number interval for this record is [1001, 999999999), the interval for this record is modified to [1001, 1002]. At the same time, a new updated record is added, and the table version number interval is [1002, 9999999999). This method can quickly determine the table version number interval when a new record with the same primary key as the current table is added.

[0059] Table 2 adds data with the same primary key as the current table above

[0060] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 1002 Original data KEY-1001 50 1002 999999999 Change data

[0061] The above-mentioned step S102 can also be implemented in other ways. In step S1025, when the change situation represents the deletion of data in the current table, the version number interval of the second data is obtained according to the primary key of the deleted data, wherein the above-mentioned deleted data is the data deleted in the updated table relative to the current table, and the above-mentioned second data is the deleted data in the above-mentioned current table; step S1026, according to the version number interval of the above-mentioned second data, determine [x, y) as the updated version number interval of the above-mentioned second data, wherein x is the starting value of the version number interval of the deleted data in the above-mentioned current table, and y is the table version number of the above-mentioned current table; step S1027, according to the updated version number interval of the above-mentioned second data, determine [y+1, INIT-y-1) as the version number interval of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and INIT is the starting value of the version number interval before the data in the above-mentioned current table is updated for the first time. In this method, as shown in Table 3, a record with a version number interval ending in 999999999 is found based on the primary key. Assuming the version number interval for this record is [1001, 999999999), the interval for this record is modified to [1001, 1002]. A new updated record is added, with a table version number interval in the range [1002, -2]. This makes it impossible to find this record when querying data, thus achieving the purpose of deleting the data. This method can quickly determine the table version number interval when the change indicates the deletion of data in the current table.

[0062] Table 3 deletes the data in the current table

[0063] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 1002 Original data KEY-1001 50 1002 -2 Change data

[0064] The above step S102 can also be implemented in other ways. In step S1028, the sum of the table version number of the above current table and 1 is calculated to obtain the version number of the above updated table. The table version number is used to represent the data update history of the table. Each table has a corresponding table version number. Starting from 1001, the table version number is incremented by 1 each time the table data is changed. When maintaining data, the data maintenance application can set the udpateByPk, insert, deleteByPk, and batchInsert methods in MyBatis's DaoSupport to map the interface aspect, and configure the pointcut to @Pointcut("execution(public*xx.DaoSupportImpl.xxx(..))&&args(obj)"). The table version number is written in the aspect method according to the data operation type.

[0065] In some embodiments, step S103 can be implemented as follows: Step S1031: When the starting value of the version number interval is less than or equal to the version number of the update table and the ending value of the version number interval is greater than the version number of the update table, data within the version number interval of the changed data is obtained; Step S1032: When the ending value of the version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the update table, data within the version number interval is obtained. In practical applications, the application cache can monitor changes in the configuration center's master version number. When table data changes, a scheduled task scans the master version number table for the latest master version number record and, if so, pushes it to the configuration center's configuration file. When the application cache obtains the changed master version number, it compares it with the locally cached master version number. If it is less than the latest master version number in Apollo, data synchronization is performed. Based on the master version number, the corresponding record in the version relationship table is queried to obtain the table name and table version number information. If the table version number obtained is Tp, newly added records can be retrieved based on the condition (table_version_no_bgn <= Tp AND table_version_no_end > MAX_VERSION_NO) OR table_version_no_end = INIT_VERSION_NO - Tp. Here, table_version_no_bgn is the starting field for the table version number of the changed data, table_version_no_end is the field for the table version number of the changed data to expire, MAX_VERSION_NO is the maximum value of the table version number, i.e., 999999999, and INIT_VERSION_NO is the initial value of the table version number, i.e., 1001. To obtain changed data based on the above conditions, the application cache needs to fully load the cached data at startup. After startup, if a change in the main version number is detected, incremental data needs to be pulled for full data merging.

[0066] In some embodiments, the above step S104 can be specifically implemented by the following steps: Step S1041, obtaining the primary key of the above-mentioned changed data; Step S1042, when the primary key of the above-mentioned changed data is different from the primary key in the above-mentioned cache, storing the above-mentioned changed data in the cache; Step S1043, when the primary key of the above-mentioned changed data is the same as the primary key in the above-mentioned cache, determining whether the end value of the version number interval of the above-mentioned changed data is a predetermined difference, the above-mentioned predetermined difference is the difference between the starting value of the version number interval before the first update and the version number of the above-mentioned update table, when the end value of the version number interval of the above-mentioned changed data is the above-mentioned predetermined difference, deleting the data in the above-mentioned cache whose primary key is the same as the primary key of the above-mentioned changed data, when the end value of the version number interval of the above-mentioned changed data is not the above-mentioned predetermined difference, updating the data in the above-mentioned cache to the above-mentioned changed data; Step S1044, after traversing all the data in the above-mentioned cache, updating the table version number in the above-mentioned cache to the version number of the above-mentioned update table. The full data merge is based on the original cache data, and merges the acquired change data into the final valid full data. The primary keys of the incremental data records are sequentially traversed, and the merging rule is as follows: If the primary key is not found in the cache, the data is directly stored in the cache. If the primary key is present in the cache, the end value of the version number interval of the changed data is determined to be a predetermined difference. If it is, the original record in the cache is deleted; otherwise, the original cached record is replaced with the changed data. After the incremental data traversal is completed, the table version number in the cache is updated. This method can further achieve data merging. Figure 3 FIG. 1 shows a schematic diagram of an overall process of caching a change data according to an embodiment of the present application, as shown in FIG. Figure 3 As shown in the figure, the caching process for changed data is as follows: First, when data in the parameter table is updated, the incremental data identifier (i.e., the version number range) is stored in the database; then, the version information is synchronized to the database. A scheduled task scans for pending version numbers and, if any, pushes this information to the configuration center. Finally, the application cache monitors data updates in the configuration center. Upon data changes, it retrieves the latest major version number. Based on the major version number, it obtains the table name and corresponding table version number for the changed data, pulls the table's incremental data, and merges it to generate the full, valid cache data.

[0067] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0068] The embodiments of the present application also provide a caching device for changing data. It should be noted that the caching device for changing data in the embodiments of the present application can be used to execute the caching method for changing data provided in the embodiments of the present application. The device is used to implement the above-mentioned embodiments and preferred implementation modes, and the details that have been described will not be repeated here. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.

[0069] The following introduces the cache device for changing data provided in the embodiment of the present application.

[0070] Figure 4 Schematic diagram of a caching device for changing data according to an embodiment of the present application. Figure 4 As shown, the device includes:

[0071] A first determining unit 10 is used to determine whether the data in the current table in the database is updated;

[0072] Specifically, it is possible to identify whether data in the current database has been updated by adding a timestamp field to the table, analyzing the database's own logs, and establishing update triggers on the business table. Adding a timestamp field to the table means that when table data is updated, the timestamp field is modified synchronously. During data synchronization, incremental data can be identified based on the system time and the timestamp field in the table. This method is relatively simple, but it cannot retrieve records deleted or updated before the timestamp. Analyzing the database's own logs involves introducing a log analysis mechanism. First, check the log configuration information, then enable logging and specify the log file path. This provides information about the time, operation type, ID, and detailed information. This requires developers to be familiar with database logging methods. Establishing an update trigger means that when data changes, the trigger writes the changed data to a temporary table. During synchronization, data is extracted from the temporary table, and the data in the temporary table is marked or deleted after synchronization is complete. This solution offers high performance, but requires creating a new trigger in the business table, which has a certain impact on the business system. The above device can quickly determine whether data in the database has been updated.

[0073] The second determining unit 20 is configured to obtain a table version number of the current table when data in the current table in the database changes, determine a version number interval of the changed data based at least on a change in the changed data and the table version number of the current table, and update the table version number of the current table to obtain a version number of the updated table, wherein the changed data is data that has changed in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0074] Specifically, the change data identifier uses a table version number range to identify the effective range of the table version number for each data record update, namely the version number range mentioned above. The starting value INIT_VERSION_NO of this range is 1001, and the maximum value MAX_VERSION_NO is 999999999. The range is represented as a left-closed and right-open interval [x, y), indicating that the table version number of this record is valid from x to y-1. The above device can accurately determine the version number range of the change data.

[0075] an acquiring unit 30, configured to acquire the change data according to the version number interval of the change data and the version number of the update table;

[0076] Specifically, different types of change data can be obtained based on the boundary values ​​of the version number interval, such as newly added data with the same primary key as the current table, newly added data with different primary keys from the current table, and deleted data from the current table. The above device can quickly obtain change data.

[0077] The updating unit 40 is configured to update the above-mentioned changed data into the cached data.

[0078] Specifically, all the changed data are updated to the cache. The primary keys of the changed data are traversed in sequence. If the primary key is not in the cache, it means that the changed data is updated relative to the data in the cache, and the changed data is stored in the cache. If the primary key is in the cache, it can be determined again whether the changed data is data deleted from the database. If so, the data in the cache should be deleted as well. The above method can achieve the rapid update of the changed data to the cached data.

[0079] This embodiment uses version numbers to identify changed data, determines the version number interval for the changed data, and then obtains the changed data and updates the cached data. This achieves the goal of synchronizing the changed data, thereby achieving the technical effect of quickly synchronizing the changed data to the cache and resolving the technical issue of extended data synchronization time due to the large amount of data being modified.

[0080] During the specific implementation process, the above-mentioned first determination unit can be implemented through the following steps: a first acquisition module is used to obtain the current major version number and the previous major version number of the above-mentioned current table; a first determination module is used to determine that the data in the above-mentioned current table in the above-mentioned database has been updated when the above-mentioned current major version number is greater than the above-mentioned previous major version number. The major version number in this device is used to indicate that there is a change in table data in the library. All tables correspond to the same major version number, starting from 9001, and the major version number increases each time there is a change in table data. The above-mentioned device can quickly determine that the data in the above-mentioned current table in the above-mentioned database has been updated.

[0081] In order to further determine the version number interval of the changed data under different change situations, the above-mentioned second determination unit of the present application can be implemented through the following steps. The second determination module is used to determine [y+1, MAX) as the version number interval of the above-mentioned changed data when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data. In this device, when data with a different primary key from the above-mentioned current table is added, it means that the changed data is different from the primary key of the data in the current table, and therefore it is a new data. Therefore, the minimum value of the version number interval can be increased by 1. As shown in Table 1, the primary key of the newly added data is KEY-1002, which is different from the primary key KEY-1001 of the original data in the table, so a new version number interval of [1002, 9999999999) is added.

[0082] Table 1 adds data with different primary keys from the current table above

[0083] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 999999999 Original data KEY-1002 50 1002 999999999 Change data

[0084] The above-mentioned second determination unit can also be implemented in other ways, for example: a second acquisition module is used to obtain the version number interval of the first data according to the same primary key in the above-mentioned current table when the change situation represents the addition of new data with the same primary key as the above-mentioned current table, and the above-mentioned first data is the data with the same primary key in the above-mentioned current table; a third determination module is used to determine [x, y) as the updated version number interval of the above-mentioned first data according to the version number interval of the above-mentioned first data, wherein x is the starting value of the version number interval of the same data in the above-mentioned current table, and y is the table version number of the above-mentioned current table; a fourth determination module is used to determine [y+1, MAX) as the version number interval of the above-mentioned changed data according to the updated version number interval of the above-mentioned first data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data. In this device, when new data with the same primary key as the above-mentioned current table is added, it means that the changed data has the same primary key as the data in the current table, and therefore the existing data is updated. As shown in Table 2, based on the primary key, a record with a version number interval ending in 999999999 is found. Assuming the version number interval for the record found is [1001, 999999999), the interval range of the record is modified to [1001, 1002), and a new updated record is added, with the table version number interval range being [1002, 9999999999). The above device can quickly determine the table version number interval when a change indicates the addition of data with the same primary key as that in the current table.

[0085] Table 2 adds data with the same primary key as the current table above

[0086] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 1002 Original data KEY-1001 50 1002 999999999 Change data

[0087] The above-mentioned second determination unit can also be implemented in other ways. The third acquisition module is used to obtain the version number interval of the second data according to the primary key of the deleted data when the change situation represents the deletion of data in the current table, wherein the above-mentioned deleted data is the data deleted in the updated table relative to the current table, and the above-mentioned second data is the deleted data in the above-mentioned current table; the fifth determination module is used to determine [x, y) as the updated version number interval of the above-mentioned second data according to the version number interval of the above-mentioned second data, wherein x is the starting value of the version number interval of the deleted data in the above-mentioned current table, and y is the table version number of the above-mentioned current table; the sixth determination module is used to determine [y+1, INIT-y-1) as the version number interval of the above-mentioned change data according to the updated version number interval of the above-mentioned second data, wherein y is the table version number of the above-mentioned current table, and INIT is the starting value of the version number interval before the data in the above-mentioned current table is updated for the first time. In this device, as shown in Table 3, a record with a version number interval ending in 999999999 is found based on the primary key. Assuming the version number interval for the record found is [1001, 999999999), the interval range of the record is modified to [1001, 1002), and a new updated record is added with a table version number interval range of [1002, -2]. This way, when querying data, the record cannot be found, thus achieving the purpose of deleting the data. The above device can quickly determine the table version number interval when the change indicates the deletion of data in the current table.

[0088] Table 3 deletes the data in the current table

[0089] Primary Key Field Starting version number End version number Notes KEY-1001 100 1001 1002 Original data KEY-1001 50 1002 -2 Change data

[0090] The above-mentioned second determination unit can also be implemented in other ways. The calculation module is used to calculate the sum of the above-mentioned table version number and 1 to obtain the version number of the above-mentioned updated table. The table version number is used to represent the data update history of the table. Each table has a corresponding table version number, starting from 1001. The table version number is incremented by 1 each time the table data is changed. When maintaining data, the data maintenance application can set the udpateByPk, insert, deleteByPk, and batchInsert methods in MyBatis's DaoSupport to map the interface aspect, and configure the pointcut to @Pointcut("execution(public*xx.DaoSupportImpl.xxx(..))&&args(obj)"). The table version number is written in the aspect method according to the data operation type.

[0091] In some embodiments, the acquisition unit can be implemented specifically through the following steps: a fourth acquisition module, configured to acquire data within the version number interval of the changed data when the starting value of the version number interval is less than or equal to the version number of the update table and the ending value of the version number interval is greater than the version number of the update table; and a fifth acquisition module, configured to acquire data within the version number interval when the ending value of the version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the update table. In practical applications, the application cache can monitor changes in the configuration center's master version number. When table data changes, a scheduled task scans the master version number table for the latest master version number record and, if so, pushes it to the configuration center's configuration file. When the application cache acquires the changed master version number, it compares it with the locally cached master version number. If it is less than the latest master version number in Apollo, data synchronization is performed. Based on the master version number, the corresponding record in the version relationship table is queried to obtain the table name and table version number information. If the table version number obtained is Tp, newly added records can be retrieved based on the condition (table_version_no_bgn <= Tp AND table_version_no_end > MAX_VERSION_NO) OR table_version_no_end = INIT_VERSION_NO - Tp. Here, table_version_no_bgn is the starting field for the table version number of the changed data, table_version_no_end is the field for the table version number of the changed data to expire, MAX_VERSION_NO is the maximum value of the table version number, 999999999, and INIT_VERSION_NO is the initial value of the table version number, 1001. To obtain changed data based on these conditions, the application cache needs to fully load the cached data at startup. After startup, if a change in the main version number is detected, incremental data needs to be pulled for full data merging.

[0092] In some embodiments, the update unit can be specifically implemented through the following steps: a sixth acquisition module for acquiring the primary key of the change data; a processing module for storing the change data in the cache when the primary key of the change data is different from the primary key in the cache; a seventh determination module for determining whether the end value of the version number interval of the change data is a predetermined difference when the primary key of the change data is the same as the primary key in the cache, the predetermined difference being the difference between the starting value of the version number interval before the first update and the version number of the update table; if the end value of the version number interval of the change data is the predetermined difference, the data in the cache with the same primary key as the primary key of the change data is deleted; if the end value of the version number interval of the change data is not the predetermined difference, the data in the cache is updated to the change data; an update module for updating the table version number in the cache to the version number of the update table after traversing all the data in the cache. The full data merge is based on the original cache data and merges the acquired change data into the final valid full data. The primary keys of the incremental data records are sequentially traversed, and the merging rule is as follows: if the primary key is not found in the cache, the data is directly stored in the cache; if the primary key exists in the cache, the end value of the version number interval of the changed data is determined to be a predetermined difference. If it is, the original record in the cache is deleted; otherwise, the original cache record is replaced with the changed data; after the incremental data traversal is completed, the table version number in the cache is updated. The above device can further realize data merging.

[0093] The change data caching device includes a processor and a memory. The first determination unit, the second determination unit, the acquisition unit, and the update unit are all stored as program units in the memory. The processor executes the program units stored in the memory to implement the corresponding functions. The modules are all located in the same processor; alternatively, the modules can be located in different processors in any combination.

[0094] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set up, and the kernel parameters can be adjusted to cache changing data.

[0095] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0096] An embodiment of the present invention provides a computer-readable storage medium, which includes a stored program. When the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method for caching changed data.

[0097] Specifically, the caching method for changed data includes:

[0098] Step S101, determining whether the data in the current table in the database is updated;

[0099] Specifically, you can identify whether data in the current database has been updated by adding a timestamp field to the table, analyzing the database's own logs, and establishing update triggers on business tables. Adding a timestamp field to the table means that when table data is updated, the timestamp field is modified simultaneously. During data synchronization, incremental data can be identified based on the system time and the timestamp field in the table. This method is relatively simple, but it cannot retrieve records deleted or updated before the timestamp. Analyzing the database's own logs involves introducing a log analysis mechanism. First, check the log configuration information, enable logging, and specify the log file path. This will reveal the time, operation type, ID, and detailed information. This requires developers to be familiar with database logging. Establishing an update trigger means that when data changes, the trigger writes the changed data to a temporary table. During synchronization, the data is extracted from the temporary table, and the data in the temporary table is marked or deleted after synchronization is complete. This solution offers high performance, but requires creating a new trigger on the business table, which has some impact on the business system. The above method can quickly determine whether data in the database has been updated.

[0100] Step S102, when data in the current table in the database changes, obtain the table version number of the current table, determine the version number interval of the changed data based at least on the change of the changed data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the changed data is the changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0101] Specifically, the table version number range used to identify the effective range of each data record update is used to identify the table version number. This range starts with the value INIT_VERSION_NO of 1001 and reaches a maximum value MAX_VERSION_NO of 999999999. The range is represented as a left-closed, right-open interval [x, y], indicating that the table version number for this record is valid from x to y-1. This method can accurately determine the version number range of the changed data.

[0102] Step S103, obtaining the above-mentioned change data according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table;

[0103] Specifically, different types of change data can be obtained based on the boundary values ​​of the version number range, such as newly added data with the same primary key as the current table, newly added data with different primary keys from the current table, and deleted data from the current table. The above method can quickly obtain change data.

[0104] Step S104: Update the above-mentioned changed data into the cached data.

[0105] Specifically, all the changed data are updated to the cache. The primary keys of the changed data are traversed in sequence. If the primary key is not in the cache, it means that the changed data is updated relative to the data in the cache, and the changed data is stored in the cache. If the primary key is in the cache, it can be determined again whether the changed data is data deleted from the database. If so, the data in the cache should be deleted as well. The above method can achieve the rapid update of the changed data to the cached data.

[0106] Optionally, determining whether the data in the current table in the database has been updated includes: obtaining the current major version number and the previous major version number of the above-mentioned current table, and if the above-mentioned current major version number is greater than the above-mentioned previous major version number, determining that the data in the above-mentioned current table in the above-mentioned database has been updated.

[0107] Optionally, the version number range of the above-mentioned changed data is determined at least based on the change situation of the changed data and the table version number of the above-mentioned current table, including: when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, determining [y+1, MAX) as the version number range of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data.

[0108] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of new data with the same primary key as the current table, according to the same primary key in the current table, the version number interval of the first data is obtained, and the first data is the data with the same primary key in the current table; according to the version number interval of the first data, [x, y) is determined as the updated version number interval of the first data, wherein x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; according to the updated version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0109] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the deletion of data in the current table, obtaining the version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is the data deleted in the updated table relative to the current table, and the second data is the deleted data in the current table; according to the version number interval of the second data, determining [x, y) as the updated version number interval of the second data, wherein x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; according to the updated version number interval of the second data, determining [y+1, INIT-y-1) as the version number interval of the changed data, wherein y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is first updated.

[0110] Optionally, updating the table version number to determine the version number of the updated table includes: calculating the sum of the table version number and 1 to obtain the version number of the updated table.

[0111] Optionally, the above-mentioned change data is obtained based on the version number interval of the above-mentioned change data and the version number of the above-mentioned update table, including: when the starting value of the above-mentioned version number interval is less than or equal to the version number of the above-mentioned update table and the ending value of the above-mentioned version number interval is greater than the version number of the above-mentioned update table, the data within the above-mentioned version number interval of the above-mentioned change data is obtained; when the ending value of the above-mentioned version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the above-mentioned update table, the data within the above-mentioned version number interval is obtained.

[0112] Optionally, updating the above-mentioned change data to the cached data includes: obtaining the primary key of the above-mentioned change data; when the primary key of the above-mentioned change data is different from the primary key in the above-mentioned cache, storing the above-mentioned change data in the cache; when the primary key of the above-mentioned change data is the same as the primary key in the above-mentioned cache, determining whether the end value of the version number interval of the above-mentioned change data is a predetermined difference, the above-mentioned predetermined difference is the difference between the starting value of the version number interval before the first update occurs and the version number of the above-mentioned update table, when the end value of the version number interval of the above-mentioned change data is the above-mentioned predetermined difference, deleting the data in the above-mentioned cache whose primary key is the same as the primary key of the above-mentioned change data, when the end value of the version number interval of the above-mentioned change data is not the above-mentioned predetermined difference, updating the data in the above-mentioned cache to the above-mentioned change data; after traversing all the data in the above-mentioned cache, updating the table version number in the above-mentioned cache to the version number of the above-mentioned update table.

[0113] An embodiment of the present invention provides a processor, which is used to run a program, wherein the method for caching changed data is executed when the program is running.

[0114] Specifically, the caching method for changed data includes:

[0115] Step S101, determining whether the data in the current table in the database is updated;

[0116] Specifically, you can identify whether data in the current database has been updated by adding a timestamp field to the table, analyzing the database's own logs, and establishing update triggers on business tables. Adding a timestamp field to the table means that when table data is updated, the timestamp field is modified simultaneously. During data synchronization, incremental data can be identified based on the system time and the timestamp field in the table. This method is relatively simple, but it cannot retrieve records deleted or updated before the timestamp. Analyzing the database's own logs involves introducing a log analysis mechanism. First, check the log configuration information, enable logging, and specify the log file path. This will reveal the time, operation type, ID, and detailed information. This requires developers to be familiar with database logging. Establishing an update trigger means that when data changes, the trigger writes the changed data to a temporary table. During synchronization, the data is extracted from the temporary table, and the data in the temporary table is marked or deleted after synchronization is complete. This solution offers high performance, but requires creating a new trigger on the business table, which has some impact on the business system. The above method can quickly determine whether data in the database has been updated.

[0117] Step S102, when data in the current table in the database changes, obtain the table version number of the current table, determine the version number interval of the changed data based at least on the change of the changed data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the changed data is the changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0118] Specifically, the table version number range used to identify the effective range of each data record update is used to identify the table version number. This range starts with the value INIT_VERSION_NO of 1001 and reaches a maximum value MAX_VERSION_NO of 999999999. The range is represented as a left-closed, right-open interval [x, y], indicating that the table version number for this record is valid from x to y-1. This method can accurately determine the version number range of the changed data.

[0119] Step S103, obtaining the above-mentioned change data according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table;

[0120] Specifically, different types of change data can be obtained based on the boundary values ​​of the version number range, such as newly added data with the same primary key as the current table, newly added data with different primary keys from the current table, and deleted data from the current table. The above method can quickly obtain change data.

[0121] Step S104: Update the above-mentioned changed data into the cached data.

[0122] Specifically, all the changed data are updated to the cache. The primary keys of the changed data are traversed in sequence. If the primary key is not in the cache, it means that the changed data is updated relative to the data in the cache, and the changed data is stored in the cache. If the primary key is in the cache, it can be determined again whether the changed data is data deleted from the database. If so, the data in the cache should be deleted as well. The above method can achieve the rapid update of the changed data to the cached data.

[0123] Optionally, determining whether the data in the current table in the database has been updated includes: obtaining the current major version number and the previous major version number of the above-mentioned current table, and when the above-mentioned current major version number is greater than the above-mentioned previous major version number, determining that the data in the above-mentioned current table in the above-mentioned database has been updated.

[0124] Optionally, the version number range of the above-mentioned changed data is determined at least based on the change situation of the changed data and the table version number of the above-mentioned current table, including: when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, determining [y+1, MAX) as the version number range of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data.

[0125] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of new data with the same primary key as the current table, according to the same primary key in the current table, the version number interval of the first data is obtained, and the first data is the data with the same primary key in the current table; according to the version number interval of the first data, [x, y) is determined as the updated version number interval of the first data, wherein x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; according to the updated version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0126] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the deletion of data in the current table, obtaining the version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is the data deleted in the updated table relative to the current table, and the second data is the deleted data in the current table; according to the version number interval of the second data, determining [x, y) as the updated version number interval of the second data, wherein x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; according to the updated version number interval of the second data, determining [y+1, INIT-y-1) as the version number interval of the changed data, wherein y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is first updated.

[0127] Optionally, updating the table version number to determine the version number of the updated table includes: calculating the sum of the table version number and 1 to obtain the version number of the updated table.

[0128] Optionally, the above-mentioned change data is obtained based on the version number interval of the above-mentioned change data and the version number of the above-mentioned update table, including: when the starting value of the above-mentioned version number interval is less than or equal to the version number of the above-mentioned update table and the ending value of the above-mentioned version number interval is greater than the version number of the above-mentioned update table, the data within the above-mentioned version number interval of the above-mentioned change data is obtained; when the ending value of the above-mentioned version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the above-mentioned update table, the data within the above-mentioned version number interval is obtained.

[0129] Optionally, updating the above-mentioned change data to the cached data includes: obtaining the primary key of the above-mentioned change data; when the primary key of the above-mentioned change data is different from the primary key in the above-mentioned cache, storing the above-mentioned change data in the cache; when the primary key of the above-mentioned change data is the same as the primary key in the above-mentioned cache, determining whether the end value of the version number interval of the above-mentioned change data is a predetermined difference, the above-mentioned predetermined difference is the difference between the starting value of the version number interval before the first update occurs and the version number of the above-mentioned update table, when the end value of the version number interval of the above-mentioned change data is the above-mentioned predetermined difference, deleting the data in the above-mentioned cache whose primary key is the same as the primary key of the above-mentioned change data, when the end value of the version number interval of the above-mentioned change data is not the above-mentioned predetermined difference, updating the data in the above-mentioned cache to the above-mentioned change data; after traversing all the data in the above-mentioned cache, updating the table version number in the above-mentioned cache to the version number of the above-mentioned update table.

[0130] An embodiment of the present invention provides a device, comprising a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, at least the following steps are performed:

[0131] Step S101, determining whether the data in the current table in the database is updated;

[0132] Step S102, when data in the current table in the database changes, obtain the table version number of the current table, determine the version number interval of the changed data based at least on the change of the changed data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the changed data is the changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0133] Step S103, obtaining the above-mentioned change data according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table;

[0134] Step S104: Update the above-mentioned changed data into the cached data.

[0135] The devices in this article can be servers, PCs, PADs, mobile phones, etc.

[0136] Optionally, determining whether the data in the current table in the database has been updated includes: obtaining the current major version number and the previous major version number of the above-mentioned current table, and when the above-mentioned current major version number is greater than the above-mentioned previous major version number, determining that the data in the above-mentioned current table in the above-mentioned database has been updated.

[0137] Optionally, the version number range of the above-mentioned changed data is determined at least based on the change situation of the changed data and the table version number of the above-mentioned current table, including: when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, determining [y+1, MAX) as the version number range of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data.

[0138] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of new data with the same primary key as the current table, according to the same primary key in the current table, the version number interval of the first data is obtained, and the first data is the data with the same primary key in the current table; according to the version number interval of the first data, [x, y) is determined as the updated version number interval of the first data, wherein x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; according to the updated version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0139] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the deletion of data in the current table, obtaining the version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is the data deleted in the updated table relative to the current table, and the second data is the deleted data in the current table; according to the version number interval of the second data, determining [x, y) as the updated version number interval of the second data, wherein x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; according to the updated version number interval of the second data, determining [y+1, INIT-y-1) as the version number interval of the changed data, wherein y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is first updated.

[0140] Optionally, updating the table version number to determine the version number of the updated table includes: calculating the sum of the table version number and 1 to obtain the version number of the updated table.

[0141] Optionally, the above-mentioned change data is obtained based on the version number interval of the above-mentioned change data and the version number of the above-mentioned update table, including: when the starting value of the above-mentioned version number interval is less than or equal to the version number of the above-mentioned update table and the ending value of the above-mentioned version number interval is greater than the version number of the above-mentioned update table, the data within the above-mentioned version number interval of the above-mentioned change data is obtained; when the ending value of the above-mentioned version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the above-mentioned update table, the data within the above-mentioned version number interval is obtained.

[0142] Optionally, updating the above-mentioned change data to the cached data includes: obtaining the primary key of the above-mentioned change data; when the primary key of the above-mentioned change data is different from the primary key in the above-mentioned cache, storing the above-mentioned change data in the cache; when the primary key of the above-mentioned change data is the same as the primary key in the above-mentioned cache, determining whether the end value of the version number interval of the above-mentioned change data is a predetermined difference, the above-mentioned predetermined difference is the difference between the starting value of the version number interval before the first update occurs and the version number of the above-mentioned update table, when the end value of the version number interval of the above-mentioned change data is the above-mentioned predetermined difference, deleting the data in the above-mentioned cache whose primary key is the same as the primary key of the above-mentioned change data, when the end value of the version number interval of the above-mentioned change data is not the above-mentioned predetermined difference, updating the data in the above-mentioned cache to the above-mentioned change data; after traversing all the data in the above-mentioned cache, updating the table version number in the above-mentioned cache to the version number of the above-mentioned update table.

[0143] The present application also provides a computer program product, which, when executed on a data processing device, is adapted to execute a program for initializing at least the following method steps:

[0144] Step S101, determining whether the data in the current table in the database is updated;

[0145] Step S102, when data in the current table in the database changes, obtain the table version number of the current table, determine the version number interval of the changed data based at least on the change of the changed data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table, wherein the changed data is the changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data from the current table;

[0146] Step S103, obtaining the above-mentioned change data according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table;

[0147] Step S104: Update the above-mentioned changed data into the cached data.

[0148] Optionally, determining whether the data in the current table in the database has been updated includes: obtaining the current major version number and the previous major version number of the above-mentioned current table, and if the above-mentioned current major version number is greater than the above-mentioned previous major version number, determining that the data in the above-mentioned current table in the above-mentioned database has been updated.

[0149] Optionally, the version number range of the above-mentioned changed data is determined at least based on the change situation of the changed data and the table version number of the above-mentioned current table, including: when the above-mentioned change situation represents the addition of data with a different primary key from the above-mentioned current table, determining [y+1, MAX) as the version number range of the above-mentioned changed data, wherein y is the table version number of the above-mentioned current table, and MAX is the maximum value of the table version number of the above-mentioned changed data.

[0150] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of new data with the same primary key as the current table, according to the same primary key in the current table, the version number interval of the first data is obtained, and the first data is the data with the same primary key in the current table; according to the version number interval of the first data, [x, y) is determined as the updated version number interval of the first data, wherein x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; according to the updated version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, wherein y is the table version number of the current table, and MAX is the maximum value of the table version number of the changed data.

[0151] Optionally, the version number interval of the changed data is determined at least based on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the deletion of data in the current table, obtaining the version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is the data deleted in the updated table relative to the current table, and the second data is the deleted data in the current table; according to the version number interval of the second data, determining [x, y) as the updated version number interval of the second data, wherein x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; according to the updated version number interval of the second data, determining [y+1, INIT-y-1) as the version number interval of the changed data, wherein y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is first updated.

[0152] Optionally, updating the table version number to determine the version number of the updated table includes: calculating the sum of the table version number and 1 to obtain the version number of the updated table.

[0153] Optionally, the above-mentioned change data is obtained based on the version number interval of the above-mentioned change data and the version number of the above-mentioned update table, including: when the starting value of the above-mentioned version number interval is less than or equal to the version number of the above-mentioned update table and the ending value of the above-mentioned version number interval is greater than the version number of the above-mentioned update table, the data within the above-mentioned version number interval of the above-mentioned change data is obtained; when the ending value of the above-mentioned version number interval is equal to the difference between the starting value of the version number interval before the first update and the version number of the above-mentioned update table, the data within the above-mentioned version number interval is obtained.

[0154] Optionally, updating the above-mentioned change data to the cached data includes: obtaining the primary key of the above-mentioned change data; when the primary key of the above-mentioned change data is different from the primary key in the above-mentioned cache, storing the above-mentioned change data in the cache; when the primary key of the above-mentioned change data is the same as the primary key in the above-mentioned cache, determining whether the end value of the version number interval of the above-mentioned change data is a predetermined difference, the above-mentioned predetermined difference is the difference between the starting value of the version number interval before the first update occurs and the version number of the above-mentioned update table, when the end value of the version number interval of the above-mentioned change data is the above-mentioned predetermined difference, deleting the data in the above-mentioned cache whose primary key is the same as the primary key of the above-mentioned change data, when the end value of the version number interval of the above-mentioned change data is not the above-mentioned predetermined difference, updating the data in the above-mentioned cache to the above-mentioned change data; after traversing all the data in the above-mentioned cache, updating the table version number in the above-mentioned cache to the version number of the above-mentioned update table.

[0155] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0156] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0157] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0158] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0159] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0160] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0161] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0162] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0163] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0164] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:

[0165] 1) In the caching method of the change data of the present application, first, it is determined whether the data in the current table in the database has been updated; then, in the case that the data in the above-mentioned current table in the above-mentioned database has changed, the table version number of the current table is obtained, and the version number interval of the above-mentioned change data is determined at least according to the change of the change data and the table version number of the above-mentioned current table, and the table version number of the above-mentioned current table is updated to obtain the version number of the updated table, and then, according to the version number interval of the above-mentioned change data and the version number of the above-mentioned update table, the above-mentioned change data is obtained; finally, the above-mentioned change data is updated to the cached data. The method of using the version number to identify the change data is used to determine the version number interval of the change data, and then obtain the change data, and update the change data to the cached data. The purpose of synchronizing the change data is achieved, thereby realizing the technical effect of quickly synchronizing the change data to the cache, and thus solving the technical problem of extending the data synchronization time due to the huge amount of data when the data is changed.

[0166] 2) In the cache device for change data of the present application, the first determination unit is used to determine whether the data in the current table in the database has been updated; the second determination unit is used to obtain the table version number of the current table when the data in the current table in the database has changed, determine the version number interval of the change data at least according to the change of the change data and the table version number of the current table, and update the table version number of the current table to obtain the version number of the updated table. The acquisition unit is used to obtain the change data according to the version number interval of the change data and the version number of the updated table; the update unit is used to update the change data to the cached data. By using the version number to identify the change data, the change data is obtained by determining the version number interval of the change data, and the change data is updated to the cached data. The purpose of synchronizing the change data is achieved, thereby realizing the technical effect of quickly synchronizing the change data to the cache, thereby solving the technical problem of extending the data synchronization time due to the huge amount of data when the data is changed.

[0167] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Persons skilled in the art will readily appreciate that various modifications and variations are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.

Claims

1. A method for caching changing data, characterized in that: include: Determine whether the data in the current table in the database is updated; In the case where the data in the current table in the database changes, obtaining a table version number of the current table, determining a version number interval of the changed data based at least on a change in the changed data and the table version number of the current table, and updating the table version number of the current table to obtain a version number of an updated table, wherein the changed data is changed data in the updated table relative to the current table, and the change includes one of the following: adding data having the same primary key as that in the current table, adding data having a different primary key from that in the current table, or deleting data in the current table; Acquire the changed data according to the version number interval of the changed data and the version number of the update table; Update the changed data to the cached data, Determine the version number interval of the changed data based at least on the change situation of the changed data and the table version number of the current table, including: when the change situation represents the addition of data with a different primary key from the current table, determine [y+1, MAX) as the version number interval of the changed data, where y is the table version number of the current table and MAX is the maximum value of the table version number of the changed data.

2. The method according to claim 1, characterized in that Determine whether the data in the current table in the database has been updated, including: Get the current major version number and the previous major version number of the current table, In a case where the current major version number is greater than the previous major version number, it is determined that data in the current table in the database is updated.

3. The method according to claim 1, characterized in that Determining the version number interval of the changed data based at least on a change in the changed data and a table version number of the current table includes: If the change indicates that data with the same primary key as that in the current table is newly added, obtaining a version number interval of first data according to the same primary key in the current table, the first data being the data with the same primary key in the current table; According to the version number interval of the first data, determine [x, y) as the updated version number interval of the first data, where x is the starting value of the version number interval of the same data in the current table, and y is the table version number of the current table; According to the update version number interval of the first data, [y+1, MAX) is determined as the version number interval of the changed data, where y is the table version number of the current table and MAX is the maximum value of the table version number of the changed data.

4. The method according to claim 1, wherein Determining the version number interval of the changed data based at least on a change in the changed data and a table version number of the current table includes: When the change indicates deletion of data in the current table, obtaining a version number interval of the second data based on the primary key of the deleted data, wherein the deleted data is data deleted from the updated table relative to the current table, and the second data is the deleted data in the current table; According to the version number interval of the second data, determine [x, y) as the update version number interval of the second data, where x is the starting value of the version number interval of the deleted data in the current table, and y is the table version number of the current table; According to the updated version number interval of the second data, determine [y+1, INIT-y-1) as the version number interval of the changed data, where y is the table version number of the current table, and INIT is the starting value of the version number interval before the data in the current table is updated for the first time.

5. The method according to claim 1, wherein Updating the table version number of the current table to obtain the version number of the updated table includes: The sum of the table version number of the current table and 1 is calculated to obtain the version number of the updated table.

6. The method according to claim 1, characterized in that Acquiring the change data according to the version number interval of the change data and the version number of the update table includes: When the starting value of the version number interval is less than or equal to the version number of the update table and the ending value of the version number interval is greater than the version number of the update table, acquiring data within the version number interval of the changed data; When the end value of the version number interval is equal to the difference between the start value of the version number interval before the first update and the version number of the update table, data within the version number interval is acquired.

7. The method according to claim 1, characterized in that Updating the changed data to the cached data includes: Obtaining the primary key of the changed data; When the primary key of the changed data is different from the primary key in the cache, storing the changed data in the cache; When the primary key of the changed data is identical to the primary key in the cache, determining whether an end value of a version number interval of the changed data is a predetermined difference value, the predetermined difference value being a difference between a start value of the version number interval before the first update occurs and the version number of the update table; if the end value of the version number interval of the changed data is the predetermined difference value, deleting data in the cache whose primary key is identical to the primary key of the changed data; and if the end value of the version number interval of the changed data is not the predetermined difference value, updating the data in the cache to the changed data; After traversing all the data in the cache, the table version number in the cache is updated to the version number of the update table.

8. A caching device for changing data, characterized in that: include: A first determining unit, configured to determine whether data in a current table in a database is updated; a second determining unit, configured to obtain, when the data in the current table in the database changes, a table version number of the current table, determine a version number interval of the changed data based at least on a change in the changed data and the table version number of the current table, and update the table version number of the current table to obtain a version number of an updated table, wherein the changed data is changed data in the updated table relative to the current table, and the change includes one of the following: adding data with the same primary key as that in the current table, adding data with a different primary key from that in the current table, or deleting data in the current table; an acquiring unit, configured to acquire the changed data according to the version number interval of the changed data and the version number of the update table; An updating unit, configured to update the changed data into the cached data, The second determination unit includes a second determination module, which is used to determine [y+1, MAX) as the version number interval of the changed data when the change situation represents the addition of data with a different primary key from the current table, where y is the table version number of the current table and MAX is the maximum value of the table version number of the changed data.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 7.

10. A processor, characterized in that: The processor is configured to run a program, wherein the program executes the method according to any one of claims 1 to 7 when running.

11. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for executing the method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Apparatus and method for processing data and program

    JP2011215984A