Automatic cache updating method and device, electronic equipment and storage medium

By monitoring database operations and automatically obtaining cache key-value parsing rules, the system enables automatic updates of cached data, solving the problems of low cache update efficiency and consistency, and improving the accuracy and consistency of cached data.

CN122045245APending Publication Date: 2026-05-15HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HONOR DEVICE CO LTD
Filing Date
2024-11-15
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

In existing technologies, cached data updates are inefficient and prone to errors, leading to inconsistencies between cached and database data, and resulting in accidental or missed deletions.

Method used

By monitoring database operations, the system automatically obtains the parsing rules for cached key-value pairs. Using these rules, it searches for and deletes the corresponding cached data in the cache area, thus achieving automatic updates to the cached data.

Benefits of technology

It improves the efficiency and accuracy of cache updates, ensures consistency between cached data and database data, and reduces the risk of accidental deletion and missed deletion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122045245A_ABST
    Figure CN122045245A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data updating, in particular to an automatic cache updating method and device, electronic equipment and a storage medium. The automatic cache updating method comprises the steps that target operation on first data in a first database is monitored, target information corresponding to the first data is obtained, the target operation comprises updating operation and deleting operation, and the target information comprises an analysis rule corresponding to a cache key value of the first data; obtaining a cache key value of the first data based on an analysis rule; and searching and deleting target cache data corresponding to the cache key value in the cache region. According to the automatic cache updating method and device, the electronic equipment and the storage medium provided by the embodiment of the invention, the data in the cache can be automatically updated when the data in the database is updated, so that the cache updating efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data update technology, and in particular to a method, apparatus, electronic device and storage medium for automatic cache update. Background Technology

[0002] Users need to access data stored in databases when using various applications. When access volume is high or access is frequent, data access speed can be affected. To optimize data access performance, a caching system can be used to pre-store frequently accessed data in the cache. This way, when accessing data, it can be retrieved from the cache first. Caching can utilize high-speed storage media (such as memory) for data storage, and retrieving data from the cache is faster than retrieving data from the database, thereby improving the response speed of data access.

[0003] To manage cached data, the data in the cache needs to be consistent with the data in the database. When data in the database is updated or deleted, the data in the cache needs to be manually deleted simultaneously, resulting in low cache update efficiency. Furthermore, manually deleting data in the cache is prone to errors, such as accidental deletion or omissions. Summary of the Invention

[0004] To address the aforementioned issues, embodiments of this application provide a method, apparatus, electronic device, and storage medium for automatic cache updates, which can automatically update data in the cache when data in the database is updated, thereby improving cache update efficiency and accuracy.

[0005] To achieve the above objectives, in a first aspect, embodiments of this application provide an automatic cache update method, comprising: detecting a target operation on first data in a first database, obtaining target information corresponding to the first data, wherein the target operation includes an update operation and a delete operation, and the target information includes a parsing rule corresponding to the cache key value of the first data; obtaining the cache key value of the first data based on the parsing rule; and searching for and deleting target cache data corresponding to the cache key value in the cache area.

[0006] In the embodiments provided in this application, the first database can be monitored. Upon detecting a target operation on the first data in the first database, i.e., detecting a deletion or update operation on the first data, the target information corresponding to the first data can be obtained first. The target information includes the parsing rules for the cache key-value pairs corresponding to the first data. Thus, the cache key-value pairs of the first data can be obtained using the parsing rules, enabling the search and deletion of target cache data in the cache area based on the cache key-value pairs. This allows for the synchronous updating of cache data in the cache area when the first database is updated or deleted, maintaining data consistency between the first database and the cache area, and ensuring the accuracy of the found target cache data. Furthermore, in the automatic cache update method provided in this embodiment, the server can automatically obtain the cache key-value pairs according to the key-value parsing rules, and then automatically search for target cache data using the cache key-value pairs, eliminating the need for manual programming for searching and deleting, effectively improving the update efficiency of the cache area.

[0007] In one optional implementation, the parsing rules include a rule type and a key-value rule. The cache key-value of the first data is obtained based on the parsing rules, including: when the rule type is a fixed value type, the key-value rule includes a fixed string; and the string is determined as the cache key-value. Thus, when the first data is immutable or read-only data, the string corresponding to the key-value rule can be directly determined as the cache key-value of the first data based on the fixed value type, improving parsing efficiency.

[0008] In one optional implementation, obtaining the cached key-value pair of the first data based on the parsing rules further includes: if the rule type is a function type, the key-value rule includes a custom function; calling the custom function to query the second database to obtain the cached key-value pair. Thus, when the first data is data provided by a second database in a third-party system or application, the cached key-value pair of the first data may be stored in the second database, and the cached key-value pair of the first data can be obtained by calling the custom function.

[0009] In one optional implementation, obtaining the cache key value of the first data based on the parsing rules further includes: if the rule type is a concatenation value type, the key value rule includes concatenation rules for at least two target parameters; querying the values ​​corresponding to at least two target parameters; and concatenating the values ​​corresponding to at least two target parameters according to the concatenation rules to obtain the cache key value. Thus, when the first data is user data or session data, or other data that needs to be associated with the application, the cache key value of the first data needs to be combined with user information. In this case, the cache key value of the first data can be obtained using the concatenation value rules.

[0010] In one optional implementation, the target information further includes table data of the first data, wherein the table data is the data corresponding to the first data in the data table, and the first database uses the data table to store the first data; querying the values ​​corresponding to at least two target parameters includes: querying the values ​​corresponding to at least two target parameters in the table data provided by the target information. In this way, the values ​​corresponding to the target parameters can be directly queried from the target information.

[0011] In one optional implementation, the target information further includes table data of the first data, wherein the table data is the data corresponding to the first data in the data table, and the first database uses the data table to store the first data; the parsing rules also include calling methods for at least one target parameter; querying the values ​​corresponding to at least two target parameters includes: using the calling methods of at least one target parameter to query the value corresponding to at least one target parameter; and querying the values ​​corresponding to the remaining target parameters in the table data provided by the target information. Thus, the value corresponding to at least one target parameter can be queried by calling the method, and the values ​​corresponding to the remaining target parameters can be queried from the target information.

[0012] In one optional implementation, finding and deleting the target cached data corresponding to the cache key-value pair in the cache region includes: finding and deleting the target cached data in the cache region after obtaining the cache key-value pair for a first preset duration; wherein the first preset duration is longer than the operation duration of the first database performing the target operation on the first data. Thus, when the first preset duration is longer than the operation duration of the target operation on the first data in the first database, the target cached data in the cache region can be deleted after the target operation on the first database is completed, achieving data consistency between the first database and the cache region.

[0013] In one optional implementation, detecting a first operation on first data in a first database and obtaining the target information corresponding to the first data includes: monitoring and parsing the log file of the first database; if the operation type in the parsed log file includes a target operation, determining that the target operation is performed on the first data in the first database; and obtaining the target information corresponding to the first data. In this way, when monitoring the first database, the log file of the first database can be directly monitored, thereby enabling timely understanding of data changes in the first database. Simultaneously, parsing the log file also provides detailed information about the operated data, facilitating the acquisition of target information.

[0014] In one optional implementation, after detecting the first operation on the first data in the first database and obtaining the target information corresponding to the first data, the method further includes: transmitting the target information through a first message queue; and within a second preset time period after the first message queue transmits the target information, if the first message queue does not receive feedback that the cached key-value parsing is complete, the first message queue retransmits the target information. Since message queues provide a reliable message transmission mechanism, using message queues to transmit target information ensures that the target information is transmitted in order and with integrity, avoiding loss, duplication, or out-of-order transmission. If the first message queue does not receive feedback that the cached key-value parsing is complete within the second preset time period after transmitting the target information, it indicates that the cached key-value parsing has failed. The first message queue can retransmit the target information, thereby enabling the parsing rules in the target information to be parsed again until the cached key-value can be obtained, thus avoiding the possibility of missing cached data due to parsing failure.

[0015] In one optional implementation, before searching for and deleting the target cached data corresponding to the cache key-value pair in the cache region, the method further includes: transmitting the cache key-value pair via a second message queue; and within a third preset time period after the second message queue transmits the cache key-value pair, if the second message queue does not receive feedback indicating that the deletion of the target cached data is complete, the second message queue retransmits the cache key-value pair. Since message queues provide a reliable message transmission mechanism, using message queues to transmit cache key-value pairs ensures that the cache key-value pairs are transmitted in order and with integrity, avoiding loss, duplication, or out-of-order transmission. If no feedback indicating that deletion is complete is received within the third preset time period, the deletion can be directly considered a failure. At this point, the second message queue can retransmit the cache key-value pair, thereby achieving a second deletion of the target cached data to ensure data consistency between the cache region and the first database.

[0016] To achieve the above objectives, in a second aspect, embodiments of this application provide an automatic cache update device, comprising: a monitoring module configured to: detect a target operation on first data in a first database and obtain target information corresponding to the first data, wherein the target operation includes an update operation and a deletion operation, and the target information includes a parsing rule corresponding to the cache key value of the first data; a preprocessing module configured to: obtain the cache key value of the first data based on the parsing rule; and a deletion module configured to: search for and delete target cache data corresponding to the cache key value in a cache area, wherein the cache data in the cache area corresponds to the data in the first database, and the target cache data corresponds to the first data.

[0017] To achieve the above objectives, in a third aspect, embodiments of this application provide an electronic device, including: a memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs the automatic cache update method as provided in the first aspect above.

[0018] To achieve the above objectives, in a fourth aspect, embodiments of this application provide a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the automatic cache update method provided in the first aspect above.

[0019] To achieve the above objectives, in a fifth aspect, embodiments of this application provide a computer program product, characterized in that, when the computer program product is run on a computer, it causes the computer to execute the automatic cache update method provided in the first aspect above.

[0020] Understandably, the beneficial effects that the technical solutions provided in the second to fifth aspects described above can be achieved by referring to the beneficial effects of any of the optional implementation methods in the first aspect, which will not be repeated here. Attached Figure Description

[0021] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a schematic diagram illustrating the interaction between an electronic device and a server, provided in an embodiment of this application.

[0023] Figure 2 This is a schematic diagram of the interface of the smart space application provided in the embodiments of this application;

[0024] Figure 3 This is a schematic diagram of a data acquisition process for an application provided in an embodiment of this application;

[0025] Figure 4 This is a schematic diagram of another application data acquisition process provided in an embodiment of this application;

[0026] Figure 5 This is a schematic diagram of a database update process provided in an embodiment of this application;

[0027] Figure 6 This is a first flowchart illustrating an automatic cache update method provided in an embodiment of this application;

[0028] Figure 7 This is a schematic diagram of the target operation provided in the embodiments of this application;

[0029] Figure 8 This is a second flowchart illustrating the automatic cache update method provided in this application embodiment;

[0030] Figure 9 This is a schematic diagram illustrating the process of performing a target operation on first data in a first database, provided in an embodiment of this application.

[0031] Figure 10 This is a schematic diagram of the structure of an automatic cache update device provided in an embodiment of this application;

[0032] Figure 11 This is a schematic diagram of another cache automatic update device provided in an embodiment of this application;

[0033] Figure 12 This is a flowchart of the automatic cache update process of the automatic cache update device provided in the embodiments of this application;

[0034] Figure 13 This is a structural block diagram of a chip system provided in an embodiment of this application.

[0035] Illustration markings:

[0036] 100 - Electronic device, 101 - Main interface, 102 - Smart space icon, 103 - First click operation, 104 - Homepage interface, 105 - Second click operation, 106 - Discovery interface, 200 - Cloud server, 300 - Cache automatic update device, 310 - Monitoring module, 320 - Preprocessing module, 330 - Deletion module. Detailed Implementation

[0037] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are all within the protection scope of this application.

[0038] In the following description, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0039] Furthermore, in this application, directional terms such as "upper," "lower," "inner," and "outer" are defined relative to the indicated placement of the components in the accompanying drawings. It should be understood that these directional terms are relative concepts, used for relative description and clarification, and can change accordingly depending on the placement of the components in the accompanying drawings.

[0040] To facilitate understanding of the plan, the relevant terminology will be introduced below.

[0041] Application: A software program that runs on an electronic device. Applications perform specific functions or tasks, such as production, management, entertainment, and education. Applications typically consist of code and related resources and interact with the user through a user interface.

[0042] Servers: Servers provide various services and resources within a network environment to meet client needs. Servers include, but are not limited to, file servers, web servers, database servers, and game servers. Database servers, in particular, can store and manage large amounts of structured data, allowing clients to connect and perform database operations such as querying, inserting, updating, and deleting.

[0043] A database is a single file or collection of files used to store data. It also provides a structured way to organize and access the stored data. A database can include multiple tables, each consisting of a series of rows and columns used to store specific data records.

[0044] A Database Management System (DBMS) is a software tool or system. It runs on a database server and is used to manage and operate databases. DBMSs enable database operations related to data definition, querying, updating, management, and security. They typically provide a query language (such as Structured Query Language, SQL) for writing and executing queries to meet user needs. Common DBMSs include MySQL, Oracle, SQL Server, and PostgreSQL. MySQL (My Structured Query Language) is an open-source relational database management system known for its ease of use, high performance, high reliability, and excellent scalability. Oracle (Oracle Database) is a commercial-grade relational database management system characterized by scalability, high performance, high availability, and advanced analytics and data mining capabilities. SQL Server (Microsoft SQL Server) is a relational database management system known for its ease of use, tight integration with Windows operating systems, and comprehensive database solutions. PostgreSQL (PostgreSQL Database) is an open-source relational database management system known for its high reliability, scalability, and support for complex queries and transaction processing.

[0045] Caching is a storage technology used to temporarily store frequently accessed data. Caching typically consists of high-speed storage media (such as memory), offering faster access speeds compared to slower main memory or disk, thus improving data access speed and system performance. Common caching technologies and tools include Redis, Memcached, EHCache, and Hazelcast. Redis (Remote Dictionary Server) is an open-source, memory-based caching database system, belonging to the high-performance key-value store category. Memcached is an open-source, high-performance distributed memory object caching system that uses key-value pairs to store data and accelerates read and write operations by caching data in memory. EHCache is an open-source Java memory caching library that can be integrated with various Java applications, providing multiple caching strategies and expiration mechanisms, supporting distributed and persistent caching. Hazelcast is an open-source distributed memory cache that enables distributed data storage and access, providing high availability and data consistency guarantees.

[0046] Key-value pairs are a data storage model used to represent a data item or object. They organize and access data based on the relationship between a key and its corresponding value. Each data item has a unique key, associated with a value. The key acts as an index for quick data lookup and access, while the value is the actual data stored within the key-value pair.

[0047] Message queues (MQ) are a communication pattern for passing messages between applications. MQ allows applications to communicate asynchronously by sending messages to queues, without needing to perform direct point-to-point communication.

[0048] Figure 1 This is a schematic diagram illustrating the interaction between an electronic device and a server, provided in an embodiment of this application.

[0049] like Figure 1 As shown, in order to provide more functions for users of electronic device 100, multiple applications can be set up in electronic device 100, and the icons of each application can be displayed on the main interface 101 of electronic device 100 for user convenience.

[0050] It is worth noting that the electronic device 100 can be a mobile phone, tablet computer, handheld computer, personal computer (PC), ultra-mobile personal computer (UMPC), netbook, as well as cellular phone, personal digital assistant (PDA), augmented reality (AR) device, virtual reality (VR) device, artificial intelligence (AI) device, wearable device, vehicle device, etc. The embodiments of this application do not impose special restrictions on the specific type of electronic device 100.

[0051] For example, the main interface 101 of the electronic device 100 can display icons such as clock, calendar, gallery, memo, file manager, email, music, calculator, video, fitness tracker, weather, browser, smart space, settings, voice recorder, and app store. The main interface 101 can also display battery level, time, and network signal strength.

[0052] When applications on electronic device 100 are running, each application can obtain data from its corresponding cloud server 200, upload data, or interact with other backend services. This data can include user personal information, application configuration files, media files, and user-generated content. Applications can communicate with cloud server 200 through its Application Programming Interface (API) to send requests to and receive responses, thereby enabling communication between applications on electronic device 100 and cloud server 200.

[0053] The cloud server 200 can serve as a database server to store application-related data. Upon receiving a data request from the application, the cloud server 200 can query the relevant data in the database. After retrieving the data, the cloud server 200 can return the retrieved data to the application, thus responding to the application's data request. In addition to storing data, the cloud server 200 can also process, calculate, and analyze the data to meet the needs of the application.

[0054] For example, the interaction between the smart space application in electronic device 100 and the server will be used as an example for illustration.

[0055] Figure 2 This is a schematic diagram of the interface of the smart space application provided in the embodiments of this application.

[0056] Combination Figure 1 and Figure 2 As shown, in response to the user's first click operation 103, the electronic device 100 will launch the Smart Space application and change the screen displayed on the electronic device 100. Figure 1 The main interface 101 switches to the one in the middle. Figure 2 The homepage interface 104 of the smart space application is shown in (a). The first click operation 103 is the operation of clicking the smart space icon 102 displayed on the main interface 101 of the electronic device 100.

[0057] The homepage of the Smart Space (104) displays "My Home," "Frequently Used," and "Family Space" controls. The "Frequently Used" screen displays frequently used devices. Figure 2 In section (a), frequently used devices are not yet added. Users can click "Add Device" to add frequently used devices. Additionally, the homepage 104 displays "Hot Recommendations," which recommends articles containing images and text for users to browse. Furthermore, the bottom of the Smart Space homepage 104 displays controls for "Home," "Scenes," "Discover," "Shop," and "My Account." Users can switch between displayed interfaces by clicking these bottom controls.

[0058] In response to the user's second click operation 105, the interface displayed on the electronic device 100 will change. Figure 2 (a) shows the homepage of the Smart Space. 104 Switches to... Figure 2 The discovery interface 106 of the smart space is shown in (b). The second click operation 105 is the operation of clicking the "Discover" control in the homepage interface 104 of the smart space.

[0059] The discovery interface 106 in the Smart Space displays a search box, below which are tweet icons (such as version upgrade tweet icons). These tweet icons can be further categorized by content. For example, tweets can be divided into practical tips and convenient lifestyle features. If a user is interested in a tweet, they can directly click its icon to open and read it.

[0060] For example, if a user is interested in a "Bedtime Charging Reminder" tweet in the Convenience Life section, they can directly click the "Bedtime Charging Reminder" icon to view the tweet.

[0061] Alternatively, if users are not interested in the tweets displayed on the discovery screen 106, they can click the "More" control to browse more tweets.

[0062] It is understood that the process of the electronic device 100 displaying the smart space discovery interface 106 described above is only one example. In other embodiments, it can also be achieved through other means (such as using the settings icon in the main interface 101 to enter the smart space discovery interface 106), which is not limited in this embodiment. In addition, the application and the application interface provided in this application embodiment are only one example, and this application embodiment is not limited.

[0063] For example, tweets on the Smart Space discovery interface 106 are typically image and text data configured by the Smart Space application's operators and stored on the cloud server 200. When a user clicks the tweet icon, the Smart Space application requests the corresponding image and text data from the cloud server 200. The cloud server 200 searches its database for the corresponding image and text data and returns it to the Smart Space application, enabling the electronic device 100 to display the tweet's content.

[0064] For example, data stored in a database is typically persistent data. A cloud server's database can utilize data tables to store data with the same data structure, which can include identical fields or attributes. Each data table consists of a series of rows and columns. Each row in the data table corresponds to a data record, and each column has a unique name and can correspond to a specific data type such as integer, string, or date. For example, table columns can include identifier (id), category, Uniform Resource Locator (url), category ID (category_id), card ID (card_id), and content ID (content_id), etc.

[0065] Table 1t_content

[0066] id content_id pic_url category_id 1 10000 http: / / magichome / a.jpg RFY2

[0067] In one example, as shown in Table 1, the table name is t_content, and the columns of the table include id, content_id, pic_url, and category_id. It can be seen that the data stored in Table 1 consists of data with id, content_id, pic_url, and category_id fields.

[0068] Specifically, in the data table shown in Table 1, the first row of data has the following values: id = 1, content_id = 10000, pic_url = http: / / magichome / a.jpg, and category_id = RFY2. In the data table shown in Table 1, the second row of data has the following values: id = 2, content_id = 10002, pic_url = http: / / magichome / b.jpg, and category_id = RFY1.

[0069] Table 2 t_content_card

[0070] id content_id card_id 3 10004 1595668965764431873 4 10006 1595668965764431874

[0071] In another example, as shown in Table 2, the table name is t_content_card, and the columns include id, content_id, and card_id. It can be seen that the data stored in Table 2 consists of id, content_id, and card_id fields.

[0072] Specifically, in the data table shown in Table 2, the first row of data has an id value of 3, a content_id value of 10004, and a card_id value of 1595668965764431873. The second row of data in the same table has an id value of 4, a content_id value of 10006, and a card_id value of 1595668965764431874.

[0073] For example, a database may include multiple data tables, which may have different table names and store data with different data structures (such as the data tables shown in Table 1 and Table 2). Each row in each data table may correspond to one piece of data.

[0074] When a cloud server needs to retrieve corresponding data from a database, it can use the database's provided language (such as SQL) to query the data in the data table.

[0075] Since databases are typically stored on hard drives, hard drive read / write speeds are relatively slow. When a cloud server performs a database query, it needs to read data from the hard drive, which introduces latency. Furthermore, if the database query lacks appropriate indexes or query optimization, it may require traversing the entire table or performing complex operations, increasing query time. Additionally, if the query involves multiple databases located on different physical servers or remote locations, data transmission over the network is necessary, and network latency further increases query time.

[0076] Therefore, it takes time for the cloud server to retrieve relevant image and text data from the database, and users cannot receive data responses promptly. This is especially true when the application sends a large number of data requests to the server in a short period, which can significantly extend the waiting time and severely impact the user experience.

[0077] To improve data response speed, frequently accessed data can be pre-stored in a caching system. A caching system utilizes high-speed storage media (such as memory) for temporary data storage. Retrieving data from the cache is faster than retrieving it from the database, thus improving data access response speed. A caching system can store frequently accessed data or calculation results in a fast-access location. When the same data is needed again, it can be retrieved directly from the cache, reducing user waiting time and providing instant data display, thereby accelerating the response speed and performance of cloud servers. Simultaneously, a caching system can also reduce server load, decrease network traffic, and improve server system reliability, ultimately providing better service to users.

[0078] For example, caching systems typically use key-value pairs to store data. Each cached data item has a unique key to identify and retrieve the data. The corresponding value is the actual stored data content. The key is usually a string or number, while the value can be various types of data, such as strings, objects, and arrays. The caching system stores data in memory based on the key-value pair mapping. This key-value pair data structure makes data retrieval in the cache efficient, effectively improving the speed and efficiency of data access.

[0079] Figure 3 This is a schematic diagram of the data acquisition process of an application provided in an embodiment of this application.

[0080] like Figure 3As illustrated, when the smart space application sends a data query request to the cloud server, the cloud server can first query the caching system. If the requested data is cached in the caching system, it can be directly returned to the smart space application, thereby improving the response speed of the cloud server.

[0081] Figure 4 This is a schematic diagram of the data acquisition process of another application provided in this application embodiment.

[0082] like Figure 4 As shown, when the smart space application sends a data query request to the cloud server, the cloud server can first query the cache system. If the requested data is not cached in the cache system, the query request is then sent to the database. After the corresponding data is found in the database, the retrieved data is returned to the smart space application. Simultaneously, the database can also synchronize the retrieved data to the cache system. This way, the next time the data is queried, it can be directly retrieved from the cache system, improving response speed.

[0083] To manage the data cached in the caching system, the data in the caching system needs to be consistent with the data in the database. In other words, the data cached in the caching system should be the data stored in the database. If the data in the database is updated or deleted, the corresponding data in the caching system should also be updated or deleted.

[0084] Figure 5 This is a schematic diagram of a database update process provided in an embodiment of this application.

[0085] like Figure 5 As illustrated, when the back-end operations staff of the smart space need to update old images in the database with new ones, they can call the cloud API to upload the new images to the database, thus updating the old images. After the database update is complete, the old images no longer exist in the database. If the old images are stored in the cache system, the back-end operations staff need to manually write a deletion program to find the old images in the cache system and delete them manually.

[0086] When the smart space application needs to retrieve a new image, the server can first query the cache system. If the new image is not yet stored in the cache system, the server will then query the database and return the new image to the application. At this point, the cache system can store the new image. This way, the next time the smart space application needs to retrieve the new image, it can directly query the cache system, improving response speed.

[0087] However, manually deleting data from the cache system by writing a program is not only inefficient when updating data in the database, but it is also prone to missing deletions when there are batch updates or deletions in the database, leading to inconsistencies between the data in the cache system and the data in the database. Furthermore, manually deleting data from the cache system may result in accidental deletion (e.g., due to program errors), resulting in a high error rate and making it difficult to manage cached data effectively.

[0088] To address the aforementioned issues, this application provides an automatic cache update method that automatically updates the cached data when the data in the database is updated, thereby improving cache update efficiency and accuracy.

[0089] Figure 6 This is a first flowchart illustrating an automatic cache update method provided in an embodiment of this application.

[0090] like Figure 6 As shown, the automatic cache update method provided in this application includes:

[0091] Step S110: Detect the target operation on the first data in the first database and obtain the target information corresponding to the first data.

[0092] Table 3t_pic

[0093] id name URL type keyrule 11111 22221 www.honor.1111.jpg 1 10000 11112 22222 www.honor.1112.jpg 2 id+name 11113 22223 www.honor.1113.jpg 2 id+com.honor.PicSever.getid 11114 22224 www.honor.1114.jpg 3 com.honor.PicSever.getid

[0094] For example, as shown in Table 3, the first database can utilize data tables for data storage. In other words, the first data can be stored in a data table. The table name in Table 3 is t_pic, and the columns include id, name, URL, type, and keyrule. When the first row of the data table stores the first data, then the information in each column of the first row can be the target information corresponding to the first data.

[0095] Specifically, the information in the first row of the data table shown in Table 3 is as follows: the value of id is 11111, the value of name is 22221, the value of URL is www.honor.1111.jpg, the value of type is 1, and the value of keyrule is 10000.

[0096] The information in the second row of the data table shown in Table 3 is as follows: the value of id is 11112, the value of name is 22222, the value of URL is www.honor.1112.jpg, the value of type is 2, and the value of keyrule is id+name.

[0097] The information in the third row of the data table shown in Table 3 is as follows: the value of id is 11113, the value of name is 22223, the value of URL is www.honor.1113.jpg, the value of type is 2, and the value of keyrule is id+com.honor.PicSever.getid.

[0098] The information in the fourth row of the data table shown in Table 3 is as follows: the value of id is 11114, the value of name is 22224, the value of URL is www.honor.1114.jpg, the value of type is 3, and the value of keyrule is com.honor.PicSever.getid.

[0099] In this data table, the fields in each column can be different parameters of the data. For example, the parameters in the first row of data in Table 3 can include id, name, URL, type, and keyrule. The value corresponding to each parameter is the value of that parameter, such as the value of 11111 for the parameter id.

[0100] For example, in the data table shown in Table 3, `type` and `keyrule` can be the parsing rules for the cached key-value pairs of the data. Here, `type` represents the rule type, and `keyrule` represents the key-value rule.

[0101] It is worth noting that in other embodiments, the data table may not include the type value. In this embodiment, the specific content of the data table is not limited.

[0102] For example, the rule types for each piece of data in the data table can be the same or different (as shown in Table 3), and the key-value rules can also be the same or different.

[0103] Table 4t_pic

[0104] id name URL type keyrule 11111 22221 www.honor.1111.jpg 1 10000 11112 22222 www.honor.1112.jpg 1 20000 11113 22223 www.honor.1113.jpg 1 30000 11114 22224 www.honor.1114.jpg 1 40000

[0105] For example, as shown in Table 4, the data in Table 4 have the same rule type but different key-value rules.

[0106] As can be seen, when multiple data sets have the same data structure, they can be stored in the same data table. If data sets with the same data structure have different rule types, then they can also be stored in different data tables according to the rule types. In this embodiment, there are no restrictions on whether the rule types and key-value rules of the data in a data table are the same.

[0107] For example, the target operations include an update operation and a delete operation. The update operation updates the first data in the first database with the second data, and the delete operation deletes the first data in the first database. After the target operation is performed on the first data in the first database, the first data will no longer exist in the first database. To maintain data consistency between the cache area and the first database, the corresponding first data in the cache area needs to be deleted.

[0108] Figure 7 This is a schematic diagram of the target operation provided in the embodiments of this application.

[0109] Specifically, the following explanation uses the data stored in the first row of the data table as an example to illustrate the target operation.

[0110] like Figure 7 As shown in (a), the update operation for the first data is to update the data information corresponding to the first data to the data information corresponding to the second data. After the update operation is completed, the first data is no longer stored in the data table.

[0111] like Figure 7 As shown in (b), the deletion operation for the first data is as follows: delete the data information corresponding to the first data. After the deletion operation is completed, the data table no longer stores the first data. Furthermore, the row originally used to store the first data can be empty to allow for the insertion of other data. Alternatively, the row originally used to store the first data can also be deleted; in this embodiment, the data table after deleting the first data is not limited.

[0112] It is worth noting that the first data in the first database can be any data corresponding to any row in the data table, and the first data is not limited in this embodiment.

[0113] Optionally, the first database can be a MySQL database, or it can be an Oracle database, etc. In this embodiment, the specific type of the first database is not limited.

[0114] For example, the cache region can cache data from the first database. After the target operation on the first data is completed, the first data will no longer exist in the first database. To maintain consistency between the cache region and the first database, the corresponding cached data in the cache region should be deleted. Cached data in the cache region is typically stored in key-value pairs. When searching for or deleting data in the cache region, the cache key-value pair corresponding to the cached data needs to be known.

[0115] Specifically, the cached data in the cache area can be stored in a distributed cache system like Redis. Alternatively, the cached data in the cache area can be stored in a distributed cache system like Memcached. It is understood that this application does not limit the specific type of cache system.

[0116] Since the key value of the first data in the first database is usually different from the cached key value of the first data in the cache area, when retrieving target information of the first data in the first database, the cached key value of the first data may not be directly stored in the first database. After detecting a target operation on the first data in the first database, the parsing rules corresponding to the cached key value of the first data stored in the data table can be obtained. In this way, the cached key value corresponding to the first data can be obtained according to the parsing rules corresponding to the cached key value, so as to facilitate the lookup of the target cached data corresponding to the first data in the cache area.

[0117] In one example, the target information may only include the information corresponding to the type and keyrule in the data table. For example, the target information corresponding to the first piece of data could be:

[0118]

[0119] In another example, the target information may include information corresponding to the type and keyrule in the data table, and may also include other parameter information. For example, the target information corresponding to the first data may be:

[0120]

[0121] Alternatively, the target information corresponding to the first data can also be:

[0122]

[0123]

[0124] As can be seen, target information can be represented in the form of logs or in other forms. In this embodiment, the specific form of target information is not limited.

[0125] Step S120: Obtain the cache key-value pair of the first data based on the parsing rules.

[0126] Optionally, the target information corresponding to the first data includes the parsing rules for cache key values. After obtaining the target information, the cache key value of the first data can be obtained based on the parsing rules for cache key values ​​in the target information, which facilitates the subsequent retrieval of the cache data corresponding to the first data in the cache area.

[0127] For example, in the data table shown in Table 4, if the data stored in the first row is the first data, then the parsing rule for the first data is that the value of type is 1 and the value of keyrule is 10000. In other words, the rule type in the cached key-value parsing rule for the first data is 1, and the key-value rule is 10000.

[0128] In one example, the parsing rule for the first data has a type value of 1 and a key rule value of 10000. In this case, a rule type of 1 indicates that the cache key value of the first data is a fixed value, and the cache key value is equal to the key value rule of 10000. Therefore, based on the rule type and key value rule in the parsing rule, it can be determined that the cache key value of the first data is 10000.

[0129] In another example, the parsing rule for the first data is that the key rule value is 10000, and the cache key value can be directly equal to the key value rule of 10000. In this case, the cache key value for the first data is obtained based on the key value rule.

[0130] It is understandable that rule type 1 can also represent other types, and cached key-value pairs can also be other values ​​obtained based on key-value rules. The above method of obtaining cached key-value pairs based on parsing rules is only one example.

[0131] Step S130: Locate and delete the target cache data corresponding to the cache key value in the cache area.

[0132] The target cached data corresponds to the first data. In other words, the target cached data is the first data cached in the cache area. All data cached in the cache area are data stored in the first database. The cache area can cache all the data stored in the first database, or it can cache a portion of the data stored in the first database.

[0133] However, when the first data no longer exists in the first database, the target cache data corresponding to the first data in the cache area needs to be deleted synchronously to maintain data consistency between the first database and the cache area.

[0134] In the embodiments provided in this application, the first database can be monitored. Upon detecting a target operation on the first data in the first database, i.e., detecting a deletion or update operation on the first data, the target information corresponding to the first data can be obtained first. The target information includes the parsing rules for the cache key-value pairs corresponding to the first data. Thus, the cache key-value pairs of the first data can be obtained using the parsing rules, enabling the search and deletion of target cache data in the cache area based on the cache key-value pairs. This allows for the synchronous updating of cache data in the cache area when the first database is updated or deleted, maintaining data consistency between the first database and the cache area, and ensuring the accuracy of the found target cache data. Furthermore, in the automatic cache update method provided in this embodiment, the server can automatically obtain the cache key-value pairs according to the key-value parsing rules, and then automatically search for target cache data using the cache key-value pairs, eliminating the need for manual programming for searching and deleting, effectively improving the update efficiency of the cache area.

[0135] Figure 8 This is a second flowchart illustrating the automatic cache update method provided in this application embodiment.

[0136] like Figure 8 As shown, the automatic cache update method provided in this application also includes:

[0137] Step S211: Monitor and parse the log files of the first database.

[0138] For example, the log file of the first database may include a transaction log. The transaction log can record detailed information about all transaction operations performed in the first database, including data insertion, update, and deletion operations. When monitoring the first database, the log file can be directly monitored, thus facilitating timely understanding of data changes in the first database.

[0139] Furthermore, while monitoring the log files of the first database, the log files can also be parsed. During parsing, detailed information about the first data within the log files can be obtained. For example, database information, table information, operation types, and table data can be retrieved by parsing the log files. The database information includes the name of the database storing the first data; the table information includes the names of the tables storing the first data; and the operation types include insert, delete, and update operations. Delete and update operations will change the first data in the first database. The table data consists of information about the first data recorded in the tables that store the first data.

[0140] In some embodiments, taking a MySQL database as an example, when monitoring the log files of the MySQL database, the binary log (binlog) can be monitored directly. The binlog records all change operations in the MySQL database, including insert, update, and delete operations. Monitoring the binlog allows for timely understanding of the detailed operations of each transaction in the MySQL database, including which tables in the MySQL database were operated on, what operations were performed, the specific data content of each operation, and the time of the operation.

[0141] For example, when monitoring the binlog logs of a MySQL database, you can use the Canal tool, the MySQL Binlog Monitor tool, and the MySQL Binlog Explorer tool to monitor the binlog logs of the MySQL database.

[0142] Specifically, the Canal tool can monitor MySQL database binlog logs in real time, parse binlog events, and convert them into easily understandable data formats such as JSON and Avro for subsequent data processing and analysis. Canal supports various methods of data subscription and consumption, and can transmit parsed data to target systems such as message queues, databases, and files.

[0143] The MySQL Binlog Monitor tool can monitor, parse, and analyze the binlog logs of MySQL databases in real time to enable functions such as data backup and recovery, data synchronization and replication, data auditing and tracing, and real-time data analysis and monitoring.

[0144] The MySQL Binlog Explorer tool can browse, parse, and analyze MySQL binary logs to enable data recovery and repair, data migration and synchronization, data auditing and troubleshooting, as well as data analysis and reporting.

[0145] For example, we will use the Canal tool to monitor the binlog of a MySQL database.

[0146] Data in a MySQL database is typically stored in the persistence layer, while the log files generated by the MySQL database reside in the DAO (Data Access Object) layer. In some application architectures, the persistence layer permanently stores data in the MySQL database, while the DAO layer is responsible for interacting with the MySQL database. In the DAO layer, when the server performs database operations, it first writes to the log before executing the specific database operation. Therefore, log recording and processing usually occur in the DAO layer, not the persistence layer. The DAO layer is responsible for translating operations into specific database operations while simultaneously logging these operations to ensure data integrity and consistency.

[0147] Specifically, when using the Canal tool to monitor the binlog of a MySQL database, interception is typically performed at the DAO layer. The Canal tool can intercept and parse binlog logs by configuring the MySQL database connection information on the server and using the corresponding MySQL database driver. Once configured, the Canal tool intercepts MySQL database insert, delete, and update operations at the DAO layer and converts them into corresponding events (such as insert, delete, and update events) for subsequent processing. By intercepting the DAO layer, the Canal tool can provide real-time monitoring and processing of MySQL database change operations, capturing detailed information for each operation.

[0148] It is understood that when monitoring and parsing the log files of the first database, the corresponding open-source tools can be used to monitor and parse the database log files for the database management system. This application embodiment does not limit the type of database or the specific type of open-source tool.

[0149] Step S212: If the operation type parsed from the log file includes a target operation, determine that the target operation will be performed on the first data in the first database.

[0150] For example, when deletion and update operations occur in the first database, the cache area also needs to be updated synchronously. When monitoring the log files of the first database, if update and deletion logs are parsed, it can be determined that update and deletion operations have occurred in the first database, allowing for timely updates to the cached data in the cache area.

[0151] Step S213: Obtain the target information corresponding to the first data.

[0152] The target information includes the parsing rules corresponding to the cached key-value pairs of the first data.

[0153] For example, when parsing a log file, detailed data information can be obtained. Then, the target information corresponding to the first piece of data can be obtained by parsing the log file. As shown in Table 3, the target information corresponding to the first piece of data may include information such as the table, id, name, URL, type, and keyrule of the first piece of data. Among these, type and keyrule are information related to the parsing rules for cached key-value pairs.

[0154] Optionally, when obtaining the target information corresponding to the first data, only information related to the cache key-value parsing rules can be obtained, such as only obtaining the type and keyrule information of the first data. Alternatively, all information about the first data recorded in the data table can be obtained, such as obtaining the table, id, name, URL, type, and keyrule information of the first data, for subsequent use. It is understood that the specific content of the obtained target information can be adjusted according to the actual situation, and is not limited in this embodiment.

[0155] It is worth noting that the above steps S211-S213 can be used to implement the above step S110 in order to monitor the target operation on the first database.

[0156] In some embodiments, the automatic cache update method provided in this application further includes: transmitting target information through a first message queue. Since a message queue provides a reliable message transmission mechanism, using a message queue to transmit target information ensures that the target information is transmitted in order and with integrity, thereby avoiding loss, duplication, or out-of-order transmission.

[0157] Please refer to it again. Figure 8 Transmitting target information through the first message queue may include:

[0158] Step S221: Transmit the target information to the first message queue.

[0159] Step S222: The first message queue transmits target information.

[0160] For example, when a message queue transmits target information, the target information can be transmitted in the form of a change log, so that relevant information can be found when parsing cached key-value pairs according to the parsing rules in the target information.

[0161] In this embodiment, using a first message queue to transmit target information can prevent the loss of target information. When a batch deletion or update operation occurs in the first database, multiple target information will be obtained. At this time, the monitoring tool can transmit multiple target information to the first message queue in sequence. The first message queue then transmits the target information to the receiver sequentially according to the order of the multiple target information, thereby avoiding the omission of target information and preventing the missed deletion of target cache data in the cache area.

[0162] It is worth noting that steps S221-S222 above can be executed after step S110. In this way, the target information can be transmitted through the first message queue, thereby improving the reliability of the target information transmission.

[0163] In some embodiments, since the data types stored in the first database may differ, and the cache key-value parsing rules corresponding to different data types may also differ, the data table can not only record multiple data items, but also record the rule type and specific key-value rule corresponding to each data item.

[0164] For example, the type column of a data table can record at least one rule type, and the keyrule column of a data table can record at least one key-value rule.

[0165] like Figure 8 As shown, specifically, when the parsing rule includes rule type and key-value rule, the automatic cache update method also includes:

[0166] Step S2311: When the rule type is a fixed value, the key-value rule includes a fixed string.

[0167] For example, when the first data is immutable or read-only, it will not change after being accessed by the application. In this case, the cache key-value pair corresponding to the first data can be a fixed value that will not change due to the application's access, reading, or use.

[0168] Specifically, the first data could be icons within the application (such as...). Figure 2 The specific form of the first data (such as the homepage icon shown) or configuration file, etc., is not limited in this embodiment.

[0169] In this embodiment, when the cache key value of the first data does not change, the first database can directly store the rule type (type) in the parsing rule of the cache key value as a fixed value, and store the string corresponding to the key rule (keyrule) in the parsing rule.

[0170] Referring to Table 3, for example, if the first row of data in the data table shown in Table 3 is the first data, the rule type corresponding to the first data is 1, and the key rule is 10000, where 10000 is the string corresponding to the key rule.

[0171] A rule type of 1 can be used to indicate that the rule type of the parsing rule is a fixed value. In other embodiments, a rule type of A can also be used to indicate that the rule type of the parsing rule is a fixed value. Alternatively, a rule type of gudingzhi can also be used to indicate that the rule type of the parsing rule is a fixed value.

[0172] It is understood that the specific representation method of the rule type used to represent fixed values ​​in the parsing rules can be determined according to the actual situation, and is not specifically limited in this embodiment.

[0173] Step S2312: Determine the string as the cache key-value pair.

[0174] For example, when the rule type of the parsing rule is a fixed value, the string corresponding to the keyrule can be directly determined as the cache key value, so as to use the cache key value to find the target cached data in the cache area.

[0175] Specifically, the first row of data in the data table shown in Table 3 is the first data, and the string corresponding to the key rule is 10000. Therefore, the cache key value of the first data is 10000.

[0176] Alternatively, if the rule type corresponding to each data item in the data table shown in Table 4 is a fixed value, then the cache key value for each data item in Table 4 is the value of keyrule. Specifically, in the data table shown in Table 4, the cache key value for the first row is 10000, the cache key value for the second row is 20000, the cache key value for the third row is 30000, and the cache key value for the fourth row is 40000.

[0177] Step S2321: When the rule type is a function type, the key-value rule includes a user-defined function.

[0178] For example, when the first data is provided by a second database in a third-party system or application, the cached key-value pair of the first data may be stored in the second database. In this case, the cached key-value pair corresponding to the first data needs to be retrieved by calling a function to query the second database.

[0179] Specifically, if the first data cached in the cloud server cache area of ​​the smart space is map data, and this map data is obtained by the cloud server from a request to the second database of the map application, then the detailed information of the map data is still stored in the second database. When deleting or updating map data in the first database, the first database may not have recorded the cached key-value pair corresponding to the map data. In this case, the rule type corresponding to the first data can be a function type, and the key-value pair rule can be a user-defined function.

[0180] Referring to Table 3, for example, if the second row of data in the data table of the first database is the first data, the rule type corresponding to the first data is 3, and the key rule is com.honor.picSever.getid.

[0181] A rule type of 3 can be used to indicate that the rule type of the parsing rule is a function type. In other embodiments, a rule type of C can also be used to indicate that the rule type of the parsing rule is a function type. Alternatively, a rule type of hanshu can also be used to indicate that the rule type of the parsing rule is a function type.

[0182] It is understood that the specific representation method of the rule type used to represent the function type in the parsing rules can be determined according to the actual situation, and is not specifically limited in this embodiment.

[0183] The key-value rule is `com.honor.picSever.getid`. Here, `com.honor.picSever.getid` is a user-defined function (UDF). The system can use the methods provided by this function to retrieve the cached key-value corresponding to the first piece of data. In `com.honor.picSever.getid`, "com.honor.picSever" can represent a path, and "getid" can represent the ID of the object being retrieved. In other words, the UDF can set the query path and query parameters. The query path can be the path where the cached key-value of the first piece of data is stored, and the query parameters can be the cached key-value of the first piece of data, thus allowing the cached key-value of the first piece of data to be obtained by calling the UDF.

[0184] It is understood that UDFs can be different functions for different data. UDFs can be adjusted according to the storage location and retrieval method of the data. In this embodiment, no limitation is made on the UDF.

[0185] Step S2322: Call a custom function to query the second database to obtain the cached key-value pairs.

[0186] For example, when the rule type of the parsing rule is a function type, the function in the key-value rule can be directly called to query the second database to obtain the cached key-value. The second database can be the database of the application or system specified by the function, but this is not limited in this embodiment.

[0187] Specifically, if the com.honor.picSever.getid method is called and returns a value of 20000, then the cache key value of the first data is 20000.

[0188] Optionally, for multiple data entries in the same data table, the corresponding UDFs for each data entry can be different. In other words, the cached key values ​​for each data entry can be stored in different paths. Alternatively, for multiple data entries in the same data table, the corresponding UDFs for each data entry can be the same. In other words, the cached key values ​​for each data entry can be stored in the same path. In this embodiment, the specific storage location of the cached key values ​​for each data entry is not limited.

[0189] Step S2331: When the rule type is concatenated value type, the key-value rule includes a concatenation rule with at least two target parameters.

[0190] For example, when the first data is user data or session data that needs to be associated with an application, the first data can be associated with the user's identity or usage records in the application for personalized operations and authorization management. In this case, the first data will be associated with user information, and the first data stored in the first database will generate information associated with the user. Simultaneously, when the first data associated with user information is cached in the cache area, the target cached data in the cache area will also be associated with user information, and the target cached data will change relative to the original first data. For such data, its cache key-value pair needs to be combined with user information. In this case, the rule type for the cache key-value pair of the first data can be a concatenation rule.

[0191] The following explanation uses image data as the first data point.

[0192] The first data cached in the cloud server cache of the smart space can be profile picture background image data. When the first user uses the profile picture background image data, the profile picture background image data cached in the cache area needs to include the first user's identifier. The original profile picture background image data is cached with the first user's identifier added. If a second user uses the profile picture background image data, the profile picture background image data cached in the cache area needs to include the second user's identifier. Compared to the original profile picture background image data, the cached data in the cache area includes the second user's identifier. In this way, when different users use the same image data, the data in the cache area can be distinguished by associating it with the user identifier.

[0193] As can be seen from the above association process, when the same image data is used by different users, it will generate image data associated with different user information. The rule type corresponding to such data can be a concatenated value type, so as to use the concatenation rule to determine the information associated with the user of the first data as the cache key value.

[0194] In this embodiment, when the rule type is a concatenated value type, the key-value rule can include a concatenation rule of at least two target parameters. For example, the key-value rule can be target parameter A + target parameter B; or, the key-value rule can be target parameter A + target parameter B + target parameter C; or, the key-value rule can be target parameter B + target parameter A.

[0195] Referring to Table 3, for example, if the second row of data in the first database's data table is the first data, the rule type corresponding to this first data is 2, and the key rule is id+name. If the third row of data in the first database's data table is the first data, the rule type corresponding to this first data is 2, and the key rule is id+com.honor.PicSever.getid.

[0196] In this context, a rule type of 2 can be used to indicate that the rule type of the parsing rule is a concatenated value type. In other embodiments, a rule type of B can also be used to indicate that the rule type of the parsing rule is a concatenated value type. Alternatively, a rule type of pinjiezhi can also be used to indicate that the rule type of the parsing rule is a concatenated value type.

[0197] It is understood that the specific representation method of the rule type used to represent the concatenated value type in the parsing rules can be determined according to the actual situation, and is not specifically limited in this embodiment.

[0198] When the key-value rule is `id+name`, `id` and `name` can be two target parameters, and `id+name` can be a concatenation rule for these two target parameters. Similarly, when the key-value rule is `id+com.honor.PicSever.getid`, `id` and `com.honor.PicSever.getid` can be two target parameters, and `id+com.honor.PicSever.getid` is a concatenation rule for these two target parameters.

[0199] It is understood that the target parameters and splicing rules may be different for different data, and no limitation is made in this embodiment.

[0200] Step S2332: Query the values ​​corresponding to at least two target parameters.

[0201] For example, when the key-value rule keyrule is a concatenation rule of at least two target parameters, the value corresponding to the target parameter in keyrule can be searched first in order to obtain the cache key-value of the first data.

[0202] In one example, if the second row of data in a data table of the first database is the first data, the target information corresponding to the first data includes:

[0203]

[0204] The target information mentioned above specifically includes the rule type (type 2) of the first data cache key-value parsing rule, the key rule (keyrule) for storing the first data as id+name, the value of the first data id as 11112, the value of the first data name as 22222, and the value of the first data URL as www.honor.1112.jpg. The target information may include table data for the first data, which is the data corresponding to the first data in the data table. In this case, the target information may include not only the parsing rules but also the table data for the first data. The table data refers to the information data in the data table storing the first data.

[0205] In this embodiment, the values ​​corresponding to at least two target parameters can be retrieved from the table data provided by the target information.

[0206] For example, if the key-value rule is id+name, and the table data provided by the target information includes the values ​​corresponding to id and name, then the value of id for the two target parameters is 11112, and the value of name is 22222.

[0207] In another example, if the third row of data in the data table of the first database is the first data, the target information corresponding to the first data includes:

[0208]

[0209] The aforementioned target information specifically includes a rule type of 2 for the first data cache key-value parsing rule, a key rule for storing the first data with the key rule id+com.honor.PicSever.getid, a first data id value of 11113, a first data name value of 22223, and a first data URL value of www.honor.1113.jpg. The target information may include table data for the first data, which is the data corresponding to the first data in the data table. In this case, the target information includes not only table data but also the calling method for at least one target parameter in the parsing rule.

[0210] In this embodiment, querying the values ​​corresponding to at least two target parameters can be achieved by using the calling method of at least one target parameter to obtain the value corresponding to at least one target parameter, and querying the values ​​corresponding to the remaining target parameters in the table data provided by the target information.

[0211] For example, when the key-value rule is `id + com.honor.PicSever.getid`, one target parameter is the value of `id`, which can be directly obtained from the table data provided by the target information; the value of `id` is 11113. The other target parameter is the value obtained by calling a function method. If calling the `com.honor.PicSever.getid` function method returns a value of 20000, then the corresponding value for the other target parameter is 20000.

[0212] Alternatively, when the key-value rule is `id+name+com.honor.PicSever.getcard_id`, the key-value rule includes three target parameters. Two of these are the values ​​of `id` and `name`, which can be directly obtained from the table data provided by the target information. For example, the value of `id` is 11113, and the value of `name` is 22223. The third target parameter is the value obtained by calling a function method. If the function `com.honor.PicSever.getcard_id` returns 20000, then the corresponding value for the other target parameter is 20000.

[0213] Alternatively, when the key-value rule is `id+name+com.honor.PicSever.getcard_id+com.honor.PicSever.getid`, the key-value rule includes four target parameters. Two of these target parameters are the values ​​of `id` and `name`, which can be directly obtained from the table data provided by the target information. The value of `id` is 11113, and the value of `name` is 22223. The remaining two target parameters are values ​​obtained by calling function methods. If calling the `com.honor.PicSever.getcard_id` function returns a value of 20000, and calling the `com.honor.PicSever.getid` function returns a value of 30000, then the values ​​of the remaining two target parameters are 20000 and 30000, respectively.

[0214] It is worth noting that the number of target parameters to be concatenated in the key-value rules can be set according to the actual situation. Similarly, the number of parameters that need to be obtained by calling the UDF method among multiple target parameters can also be set according to the actual situation. The key-value rules provided in this application are merely examples and should not be considered as limitations.

[0215] It is understandable that if a UDF function exists in the key-value rule, the value corresponding to the target parameter can be stored in a different data table in the same database as the first data, or it can be stored in a different database than the first data.

[0216] Step S2333: Concatenate the values ​​corresponding to at least two target parameters according to the concatenation rules to obtain the cache key value.

[0217] For example, when the key-value rule is id+name, and the query finds that the value of id is 11113 and the value of name is 22223, then the cache key value of the first data is 1111322223.

[0218] When the key-value rule is id+com.honor.PicSever.getid, the value of id is found to be 11113. Calling the function method retrieves the value corresponding to another target parameter as 20000. Therefore, the cache key value of the first data is 1111320000.

[0219] When the key-value rule is id+name+com.honor.PicSever.getcard_id, the query returns id as 11113 and name as 22223. Calling the function method returns another target parameter with a value of 20000. Therefore, the cache key for the first data is 111132222320000.

[0220] When the key-value rule is id+name+com.honor.PicSever.getcard_id+com.honor.PicSever.getid, the query returns id as 11113 and name as 22223. Calling the function method returns the values ​​for the other two target parameters as 20000 and 30000 respectively. Therefore, the cache key for the first data is 11113222232000030000.

[0221] It should be noted that when the data stored in the first database is of different types, the rule type for caching key values ​​can include more than one, such as two, three, five, or six types. In this embodiment, the number of rule types for caching key values ​​is not limited.

[0222] For the same rule type (type), the key-value rules (keyrule) can be the same or different. As shown in Table 3, the rule types (type) of the second and third rows of data are both concatenated values, but their key-value rules (keyrule) are different. In other embodiments, the rule types (type) of the second and third rows of data can both be concatenated values, but their key-value rules (keyrule) can also be the same.

[0223] However, as shown in Table 4, when the rule type is a fixed value, the key-value rules are all different to ensure the uniqueness of the cached key-value corresponding to each data.

[0224] Furthermore, when parsing cached key-value pairs using target information, multiple channels can be used to parse multiple sets of target information simultaneously to improve the parsing efficiency of cached key-value pairs.

[0225] It is worth noting that the above steps S2311-S2333 can be used to implement the above step S120.

[0226] Please refer to it again. Figure 8 The automatic cache update method provided in this application embodiment further includes:

[0227] Step S223: After parsing the cached key-value of the first data, transmit the key-value parsing completion feedback to the first message queue.

[0228] In this embodiment, after transmitting target information using the first message queue, when obtaining the cached key value based on the parsing rules in the target information, a parsing completion feedback can be transmitted to the first message queue so that the first message queue can transmit the next set of target information in a timely manner.

[0229] Furthermore, within a second preset time period after the first message queue transmits the target information, if the first message queue does not receive feedback indicating that the cached key-value parsing is complete, the first message queue will retransmit the target information. The starting point of the second preset time period is the moment when the first message queue transmits the target information.

[0230] For example, message queues typically have a persistence mechanism, so that even if the receiver is not currently able to receive the message, the message will be persisted in the queue until the receiver is ready to receive it.

[0231] In this embodiment, the target information transmitted by the first message queue is typically used for parsing cached key-value pairs. After receiving and parsing the target information, the receiver of the first message queue can send feedback indicating successful parsing back to the first message queue. If the first message queue does not receive feedback indicating successful parsing of the cached key-value pairs within a second preset time period after transmitting the target information, it indicates that the cached key-value pair parsing has failed. This failure may be due to network instability or other reasons, which are not limited in this embodiment. In this case, the first message queue can retransmit the target information, thereby enabling the parsing rules in the target information to be parsed again until the cached key-value pairs can be obtained, thus avoiding the possibility of missed cached data deletion due to parsing failure.

[0232] For example, the second preset duration should be greater than the duration for parsing the cached key value based on the parsing rules. In this embodiment, the specific value of the second preset duration is not limited.

[0233] In some embodiments, the cache automatic update method provided in this application further includes: transmitting cache key values ​​through a second message queue. Since message queues provide a reliable message transmission mechanism, using a message queue to transmit cache key values ​​ensures that cache key values ​​are transmitted in order and with integrity, thereby avoiding loss, duplication, or out-of-order transmission.

[0234] Please refer to it again. Figure 8 Transmitting cached key-value pairs via the second message queue can include:

[0235] Step S241: Transfer the cached key-value pair to the second message queue.

[0236] Step S242: The second message queue transmits the cached key-value pairs.

[0237] Furthermore, automatic cache update methods also include:

[0238] Step S251: After parsing the first preset duration of the cache key value, find and delete the target cache data in the cache area.

[0239] The first preset duration is longer than the operation duration for performing the target operation on the first data in the first database. The starting point for the first preset duration is the moment when the cached key-value pair is obtained based on the parsing rules.

[0240] For example, when performing a target operation on the first data in the first database, the performance limitations of the first database will result in a relatively long execution time for the target operation. In other words, the operation time required to delete or update the first data in the first database will be relatively long, while the time required to delete the target cached data in the cache area will be relatively short.

[0241] Figure 9 This is a schematic diagram illustrating a process of performing a target operation on first data, as provided in an embodiment of this application.

[0242] like Figure 9 As shown, when performing a target operation on the first data in the first database, if the time taken to complete the target operation is t1, the time taken to obtain the target information, parse the cache key value based on the parsing rules in the target information, and use the cache key value to find and delete the target cache data is t2. Here, t2 is less than t1.

[0243] After time t2, the target cached data in the cache region has been deleted, and the target cached data in the cache region is empty. However, the first data in the first database has not yet been updated or deleted, meaning that the first data still exists in the first database.

[0244] If the application requests the first data within the time period t2-t1, the cloud server will first request it from the cache area, but at this time the cache area does not contain the target cached data. Afterwards, the cloud server will request the first data from the first database and synchronize the first data from the first database to the cache area.

[0245] In this scenario, after time t1, the target operation on the first data in the first database is completed, and the first data will no longer exist in the first database. However, the target cache data that was previously deleted in the cache area is loaded and re-cached, and the target cache data in the cache area cannot be deleted again, resulting in inconsistency between the data in the first database and the cache area. This can easily lead to errors during subsequent data access.

[0246] Based on this, after obtaining the cache key value for a first preset duration, the target cache data in the cache area is then searched and deleted, enabling delayed deletion of the target cache data in the cache area. When the first preset duration is longer than the operation duration for performing the target operation on the first data in the first database, the target cache data in the cache area can be deleted after the target operation on the first database is completed, thus ensuring data consistency between the first database and the cache area.

[0247] Specifically, after parsing the cache key value for the first preset duration, the target cached data in the cache area can be deleted by calling the Redis cache.

[0248] It is worth noting that step S251 can be used to implement step S130 above.

[0249] Please refer to it again. Figure 8 The automatic cache update method provided in this application embodiment includes:

[0250] Step S243: After deleting the target cached data in the cache area, transmit the deletion completion feedback to the second message queue.

[0251] For example, after deleting the target cached data, a deletion completion notification can be sent to the second message queue. This allows the second message queue to continue sending the next cached key-value pair to update the data in the cached area.

[0252] Furthermore, within a third preset time period after the second message queue transmits the cached key-value pair, if the second message queue does not receive feedback indicating that the target cached data deletion is complete, the second message queue will retransmit the cached key-value pair. The starting point of the third preset time period is the moment the second message queue transmits the cached key-value pair.

[0253] In this embodiment, the cache key value transmitted by the second message queue is used to locate and delete target cached data in the cache area. During the deletion process, if a network anomaly, server failure, or application malfunction occurs, causing problems with the cached data in the cache area, the target cached data cannot be deleted normally, and the cached data in the cache area cannot be updated. Through monitoring by the second message queue, if no feedback indicating deletion completion is received within a third preset time period, it can be directly considered that the deletion has failed. At this time, the second message queue can retransmit the cache key value, thereby realizing the deletion of the target cached data again, to ensure the data consistency between the cache area and the first database.

[0254] For example, the third preset duration should be longer than the duration of deleting the target cache data in the cache area. In this embodiment, the specific value of the third preset duration is not limited.

[0255] Figure 10 This is a schematic diagram of the structure of an automatic cache update device provided in an embodiment of this application.

[0256] like Figure 10 As shown in the illustration, this application embodiment also provides a cache automatic update device 300, including a monitoring module 310, a preprocessing module 320, and a deletion module 330. The monitoring module 310 is used to monitor target operations on first data in a first database and obtain target information corresponding to the first data. The target operations include update and deletion operations, and the target information includes parsing rules corresponding to the cache key-value pairs of the first data. The preprocessing module 320 is used to obtain the cache key-value pairs of the first data based on the parsing rules. The deletion module 330 is used to find and delete target cache data corresponding to the cache key-value pairs in the cache region.

[0257] The cache automatic update device 300 provided in this application embodiment can monitor the operations of a first database. When first data in the first database is deleted or updated, it can obtain the target information corresponding to the first data. The target information includes the parsing rules for the cache key value of the first data. In this way, the preprocessing module 320 can obtain the cache key value based on the parsing rules, and the deletion module 330 queries and deletes the target cache data in the cache area through the cache key value, so as to achieve data consistency between the cache area and the first database, thereby realizing automatic update of the cache and effectively improving the update efficiency and accuracy of the cache.

[0258] Figure 11 This is a schematic diagram of another automatic cache update device provided in an embodiment of this application.

[0259] Figure 12 This is a flowchart of the automatic cache update process of the automatic cache update device provided in the embodiments of this application.

[0260] Combination Figure 11 and Figure 12 As shown, the cache automatic update device 300 also includes a first message queue MQ1 and a second message queue MQ2. The first message queue MQ1 is located between the monitoring module 310 and the preprocessing module 320, and is used to transmit target messages from the monitoring module 310 to the preprocessing module 320. The second message queue MQ2 is located between the preprocessing module 320 and the deletion module 330, and is used to transmit cache key-value pairs from the preprocessing module 320 to the deletion module 330.

[0261] In some embodiments, the monitoring module 310 is further configured to monitor and parse the log file of the first database, and if the operation type parsed in the log file includes a target operation, determine to perform a target operation on the first data in the first database and obtain the target information corresponding to the first data.

[0262] For example, the monitoring module 310 can be a Canal tool.

[0263] In some embodiments, the monitoring module 310 is further configured to transmit target information to a first message queue. The first message queue MQ1 is configured to transmit the target information to the preprocessing module 320.

[0264] For example, when there are multiple sets of target information, the first message queue can transmit the target information to the preprocessing module 320 in sequence.

[0265] In some embodiments, the preprocessing module 320 is used to determine the string as a cached key-value when the key-value rule includes a fixed string and the rule type is a fixed value.

[0266] In some embodiments, the preprocessing module 320 is further configured to, when the rule type is a function type, include a custom function in the key-value rule, call the custom function, and query the second database to obtain the cached key-value.

[0267] In some embodiments, the preprocessing module 320 is further configured to, when the rule type is a concatenation value type, include concatenation rules for at least two target parameters, query the values ​​corresponding to at least two target parameters, and concatenate the values ​​corresponding to at least two target parameters according to the concatenation rules to obtain cached key values.

[0268] In one example, the target information may include not only parsing rules but also table data of the first data. The table data refers to the information data in the data table storing the first data. The preprocessing module 320 is also used to query the table data provided by the target information for values ​​corresponding to at least two target parameters.

[0269] In another example, the target information includes not only table data, but also the parsing rules include the calling method of at least one target parameter. The preprocessing module 320 is further used to query the value corresponding to at least one target parameter using the calling method of at least one target parameter, and to query the values ​​corresponding to the remaining target parameters in the table data provided by the target information.

[0270] For example, the preprocessing module 320 may include multiple parsing channels, each capable of retrieving cached key-value pairs based on parsing rules. In this way, the preprocessing module 320 can simultaneously parse multiple parsing rules, thereby improving the parsing efficiency of cached key-value pairs.

[0271] In some embodiments, the preprocessing module 320 is further configured to transmit key value parsing completion feedback to the first message queue after parsing the cached key value of the first data.

[0272] In some embodiments, the first message queue is further configured to retransmit the target information to the preprocessing module 320 if the first message queue does not receive feedback from the preprocessing module 320 indicating that the cache key-value parsing is complete within a second preset time period after the target information is transmitted.

[0273] In some embodiments, the preprocessing module 320 is further configured to transmit cached key-value pairs to a second message queue. The second message queue is used to transmit cached key-value pairs to the deletion module 330.

[0274] In some embodiments, the deletion module 330 is used to find and delete target cache data in the cache area after parsing the cache key value for a first preset time period.

[0275] In some embodiments, the deletion module 330 is further configured to transmit deletion completion feedback to the second message queue after completing the deletion of target cache data in the cache area.

[0276] In some embodiments, the second message queue is further configured to retransmit the cache key value to the deletion module 330 if the second message queue does not receive feedback from the deletion module 330 indicating that the deletion of the target cache data is complete within a third preset time period after transmitting the cache key value.

[0277] For example, the deletion module 330 may include multiple deletion channels, each capable of querying and deleting target cached data based on a cache key-value pair. In this way, the deletion module 330 can delete multiple target cached data simultaneously, thereby improving the efficiency of updating cached data.

[0278] This application also provides an electronic device, which includes a memory and a processor; the memory is coupled to the processor; wherein the memory stores computer program code, the computer program code including computer instructions, and when the computer instructions are executed by the processor, the electronic device performs the automatic cache update method provided in the foregoing embodiments.

[0279] Figure 13 This is a structural block diagram of a chip system provided in an embodiment of this application.

[0280] This application also provides a chip system, such as a system-on-a-chip (SoC), as shown in the embodiments. Figure 13As shown, the chip system includes at least one processor 1301 and at least one interface circuit 1302. The processor 1301 and the interface circuit 1302 are interconnected via lines. For example, the interface circuit 1302 can be used to receive signals from other devices (e.g., the memory of an electronic device). As another example, the interface circuit 1302 can be used to transmit signals to other devices (e.g., the processor 1301 or the touchscreen of an electronic device). Exemplarily, the interface circuit 1302 can read instructions stored in the memory and transmit those instructions to the processor 1301. When the instructions are executed by the processor 1301, the electronic device can perform the steps described in the above embodiments. Of course, the chip system may also include other discrete components, which are not specifically limited in this application embodiment.

[0281] This application also provides a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the cache auto-update method provided in the foregoing embodiments.

[0282] This application also provides a computer program product containing executable instructions that, when run on an electronic device, cause the electronic device to perform the automatic cache update method provided in the foregoing embodiments.

[0283] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0284] In the several embodiments provided in this application, it should be understood that the disclosed apparatus / device and method can be implemented in other ways. For example, the apparatus / device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0285] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0286] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0287] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0288] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for automatically updating a cache, characterized in that, include: The system detects a target operation on the first data in the first database and obtains the target information corresponding to the first data. The target operation includes update and delete operations, and the target information includes the parsing rules corresponding to the cache key-value pairs of the first data. The cache key value of the first data is obtained based on the parsing rules; Locate and delete the target cache data in the cache region that corresponds to the cache key value.

2. The automatic cache update method according to claim 1, characterized in that, The parsing rules include rule types and key-value rules; The process of obtaining the cached key value of the first data based on the parsing rules includes: When the rule type is a fixed value type, the key-value rule includes a fixed string; The string is identified as the cache key value.

3. The automatic cache update method according to claim 2, characterized in that, The step of obtaining the cache key value of the first data based on the parsing rule further includes: When the rule type is a function type, the key-value rule includes a user-defined function; The custom function is called to query the second database to obtain the cached key-value pair.

4. The automatic cache update method according to claim 2 or 3, characterized in that, The step of obtaining the cache key value of the first data based on the parsing rule further includes: When the rule type is a concatenated value type, the key-value rule includes a concatenation rule for at least two target parameters; Query the values ​​corresponding to at least two of the target parameters; The values ​​corresponding to at least two of the target parameters are concatenated according to the concatenation rules to obtain the cache key value.

5. The automatic cache update method according to claim 4, characterized in that, The target information also includes table data of the first data, wherein the table data is the data corresponding to the first data in the data table, and the first database uses the data table to store the first data; The query corresponds to at least two of the target parameters, including: Query the table data provided by the target information for the values ​​corresponding to at least two of the target parameters.

6. The automatic cache update method according to claim 4, characterized in that, The target information also includes table data of the first data, wherein the table data is the data corresponding to the first data in the data table, and the first database uses the data table to store the first data; The parsing rules also include at least one calling method for the target parameter; The query corresponds to at least two of the target parameters, including: The value corresponding to at least one of the target parameters is obtained by querying using the calling method of at least one of the target parameters; Query the remaining values ​​corresponding to the target parameters in the table data provided by the target information.

7. The automatic cache update method according to any one of claims 1-6, characterized in that, Locating and deleting the target cache data corresponding to the cache key value in the cache region includes: After parsing the cache key value for a first preset duration, the target cache data in the cache area is searched and deleted; Wherein, the first preset duration is longer than the operation duration for performing the target operation on the first data in the first database.

8. The automatic cache update method according to any one of claims 1-6, characterized in that, The detection of a first operation on first data in the first database and the acquisition of target information corresponding to the first data include: Monitor and parse the log files of the first database; If the operation type in the log file is found to include a target operation, it is determined that the target operation will be performed on the first data in the first database. Obtain the target information corresponding to the first data.

9. The automatic cache update method according to any one of claims 1-6, characterized in that, After detecting the first operation on the first data in the first database and obtaining the target information corresponding to the first data, the method further includes: The target information is transmitted through the first message queue; If the first message queue does not receive feedback that the cached key-value parsing is complete within a second preset time period after transmitting the target information in the first message queue, the first message queue will retransmit the target information.

10. The automatic cache update method according to any one of claims 1-6, characterized in that, Before searching for and deleting the target cache data corresponding to the cache key value in the cache region, the method further includes: The cached key value is transmitted via the second message queue; If the second message queue does not receive feedback that the target cache data deletion is complete within a third preset time period after transmitting the cache key value in the second message queue, the second message queue will retransmit the cache key value.

11. A cache automatic update device, characterized in that, include: The monitoring module is configured to: detect a target operation on the first data in the first database, and obtain the target information corresponding to the first data, wherein the target operation includes an update operation and a delete operation, and the target information includes the parsing rules corresponding to the cache key-value of the first data; The preprocessing module is configured to: obtain the cache key value of the first data based on the parsing rules; The deletion module is configured to: find and delete the target cache data in the cache area that corresponds to the cache key value.

12. An electronic device, characterized in that, include: A memory and one or more processors; the memory is coupled to the processors; wherein the memory stores computer program code, the computer program code including computer instructions, which, when executed by the processor, cause the electronic device to perform the automatic cache update method as described in any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, Includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the automatic cache update method as described in any one of claims 1-10.

14. A computer program product, characterized in that, When the computer program product is run on a computer, the computer performs the automatic cache update method as described in any one of claims 1-10.