Data caching method and device, storage medium and program product

By hierarchically managing the SQL statements of the client cache system, the LRU and LFU mechanisms are used to distinguish between hot and cold data, which solves the problem of low cache hit rate and improves the response speed and stability of client applications.

CN120296048APending Publication Date: 2025-07-11CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510344903.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

The existing client cache system has a low cache hit rate in different business scenarios, which cannot meet the system needs in complex business scenarios, affecting the operation of client applications.

Method used

By parsing the client's SQL statement, obtain the name information hash value and feature hash value, use the LRU mechanism to manage hot data and the LFU mechanism to manage cold data, manage cache resources in a hierarchical manner, and obtain context information to mount it to the corresponding handle, and add it to the client cache system.

Benefits of technology

It improves the cache hit rate, reduces the number of interactions between the client and the server, improves the response speed and user experience of the client application, and ensures the stability of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120296048A_ABST
    Figure CN120296048A_ABST
Patent Text Reader

Abstract

The invention provides a data caching method and device, a storage medium and a program product, firstly, an SQL statement of a client side is analyzed to obtain a name information hash value and an SQL feature hash value corresponding to the SQL statement, then according to the name information hash value and the SQL feature hash value, hierarchical management is conducted on the SQL statement according to a preset caching mechanism to distinguish hot data and cold data, and the SQL statement is cached according to the hot data and the cold data. Wherein the preset cache mechanism comprises an LRU mechanism of hot data and an LFU mechanism of cold data, then obtaining context information during the execution period of the SQL statement, mounting the context information to a corresponding handle generated by hierarchical management, and then adding the handle to a client cache system. The cache resources are subjected to hierarchical management, hot data and cold data are distinguished for classified processing, the cache hit rate is increased, and therefore the client application response speed and the user experience are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data caching, and in particular, to a data caching method, device, storage medium, and program product. Background Art

[0002] With the development of business and the increasing amount of data that client applications need to process, it is necessary to design a client caching system that can block a part of the traffic on the client side to reduce the interaction with the server.

[0003] However, the full-cache strategy and single-cache strategy of existing client caching systems have the problem of low cache hit rate for different business scenarios, which affects the operation of the client and cannot meet the system requirements in the current complex business scenarios. Therefore, there is an urgent need for a caching strategy to overcome the defects of the current client caching system. Summary of the Invention

[0004] This application provides a data caching method, device, storage medium, and program product, which are used to hierarchically manage cache resources, distinguish hot data and cold data for classification processing, and improve the cache hit rate, thereby effectively improving the response speed of client applications and the user experience.

[0005] In a first aspect, this application provides a data caching method, which includes:

[0006] Parse the SQL statement of the client to obtain the name information hash value and SQL feature hash value corresponding to the SQL statement;

[0007] According to the name information hash value and the SQL feature hash value, hierarchically manage the SQL statement according to a preset caching mechanism to distinguish hot data and cold data. The preset caching mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data;

[0008] Obtain the context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by hierarchical management, and add the handle to the client caching system.

[0009] In a possible implementation manner, the hierarchically managing the SQL statement according to a preset caching mechanism to distinguish hot data and cold data according to the name information hash value and the SQL feature hash value includes:

[0010] Determine whether the name information hash value hits the cache;

[0011] If not, generate a context parent handle corresponding to the SQL statement, and perform hierarchical management according to the SQL feature hash value;

[0012] If so, perform hierarchical management based on the SQL feature hash value and the hit feature hash value;

[0013] Among them, the context parent handles corresponding to the SQL statements include a name information context parent handle, an SQL statement context parent handle, and an SQL feature context parent handle.

[0014] In a possible implementation manner, the hierarchical management based on the SQL feature hash value includes:

[0015] When it is determined that the SQL feature hash value is the cold data, generate a context child handle corresponding to the SQL statement, and sort the context child handle corresponding to the SQL statement;

[0016] Among them, the context child handle corresponding to the SQL statement includes a name information context child handle,

[0017] an SQL statement context child handle, and an SQL feature context child handle.

[0018] In a possible implementation manner, the sorting of the context child handle corresponding to the SQL statement includes:

[0019] Using the name information hash value as the key, add the context child handle corresponding to the SQL statement to the LFU list;

[0020] In the LFU list, sort the context child handle corresponding to the SQL statement according to the usage frequency of the SQL statement.

[0021] In a possible implementation manner, after generating the context parent handle corresponding to the SQL statement, it further includes:

[0022] Using the name information hash value as the key, add the context parent handle corresponding to the SQL statement to the head of the LRU list.

[0023] In a possible implementation manner, the hierarchical management based on the SQL feature hash value and the hit feature hash value includes:

[0024] When it is determined that the SQL feature hash value is consistent with the hit feature hash value, and the SQL feature hash value is the cold data, obtain the child handle corresponding to the SQL feature hash value from the LFU list;

[0025] When it is determined that the SQL feature hash value is consistent with the hit feature hash value, and the SQL feature hash value is the hot data, obtain the parent handle corresponding to the SQL feature hash value from the LRU list;

[0026] When it is determined that the SQL feature hash value is inconsistent with the hit feature hash value, generate a context clause handle corresponding to the SQL statement, and sort the context clause handle corresponding to the SQL statement.

[0027] In a possible implementation manner, after obtaining the clause handle corresponding to the SQL feature hash value from the LFU list, it further includes:

[0028] Update the usage frequency of the SQL statement, and sort the clause handle corresponding to the SQL feature hash value according to the updated usage frequency;

[0029] Wherein, the clause handle corresponding to the SQL feature hash value includes the context clause handle corresponding to the SQL statement.

[0030] In a possible implementation manner, after obtaining the parent clause handle corresponding to the SQL feature hash value from the LRU list, it further includes: updating the head of the LRU list.

[0031] In a possible implementation manner, the method further includes:

[0032] When initializing the client cache system, send a registration instruction to the database of the client cache system, so that a subscription and publication relationship is established between the database in response to the registration instruction and the client cache system.

[0033] In a possible implementation manner, the method further includes:

[0034] Detect the running environment of the client cache system, and obtain the memory capacity of the LRU list and the memory capacity of the LFU list;

[0035] Eliminate cache resources according to the memory capacity of the LRU list and the memory capacity of the LFU list.

[0036] In a possible implementation manner, eliminating cache resources according to the capacity of the LRU list and the memory capacity of the LFU list includes:

[0037] If the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, eliminate some cache resources of the LFU list.

[0038] In a possible implementation manner, after eliminating some cache resources of the LFU list, it further includes:

[0039] If the total capacity of the client cache system is greater than or equal to the total capacity threshold, eliminate some cache resources of the LRU list.

[0040] In a possible implementation, the method further includes:

[0041] If a readable event that is connected is detected, update the handle corresponding to the readable event in the client cache system.

[0042] In a possible implementation, parsing the SQL statement of the parsing client includes:

[0043] Normalize the SQL statement, and extract name information and feature values according to the normalized SQL statement;

[0044] Perform a hash process on the normalized SQL statement, the name information, and the feature values.

[0045] In a second aspect, the present application provides a data caching device, including:

[0046] A first processing module, configured to parse the SQL statement of the client to obtain a name information hash value and an SQL feature hash value corresponding to the SQL statement;

[0047] A second processing module, configured to classify and manage the SQL statement according to a preset caching mechanism based on the name information hash value and the SQL feature hash value to distinguish hot data and cold data, where the preset caching mechanism includes an LRU mechanism for the hot data and an LFU mechanism for the cold data;

[0048] A third processing module, configured to obtain context information during the execution of the SQL statement, mount the context information to a corresponding handle generated by the hierarchical management, and add the handle to the client cache system.

[0049] In a possible implementation, the second processing module is specifically configured to:

[0050] Determine whether the name information hash value hits the cache;

[0051] If not, generate a context parent handle corresponding to the SQL statement, and perform hierarchical management according to the SQL feature hash value;

[0052] If so, perform hierarchical management according to the SQL feature hash value and the hit feature hash value;

[0053] Wherein, the context parent handle corresponding to the SQL statement includes a name information context parent handle, an SQL statement context parent handle, and an SQL feature context parent handle.

[0054] In a possible implementation, the second processing module is further configured to:

[0055] When it is determined that the SQL feature hash value is the cold data, generate a context sub-handle corresponding to the SQL statement, and sort the context sub-handle corresponding to the SQL statement;

[0056] Among them, the context sub-handle corresponding to the SQL statement includes a name information context sub-handle,

[0057] an SQL statement context sub-handle, and an SQL feature context sub-handle.

[0058] In a possible implementation manner, the second processing module is further configured to:

[0059] Use the name information hash value as a key, and add the context sub-handle corresponding to the SQL statement to the LFU list;

[0060] In the LFU list, sort the context sub-handle corresponding to the SQL statement according to the usage frequency of the SQL statement.

[0061] In a possible implementation manner, the second processing module is further configured to:

[0062] Use the name information hash value as a key, and add the context parent handle corresponding to the SQL statement to the head of the LRU list.

[0063] In a possible implementation manner, the second processing module is further configured to:

[0064] When it is determined that the SQL feature hash value is consistent with the hit feature hash value, and the SQL feature hash value is the cold data, obtain the sub-handle corresponding to the SQL feature hash value from the LFU list;

[0065] When it is determined that the SQL feature hash value is consistent with the hit feature hash value, and the SQL feature hash value is the hot data, obtain the parent handle corresponding to the SQL feature hash value from the LRU list;

[0066] When it is determined that the SQL feature hash value is not consistent with the hit feature hash value, generate a context sub-handle corresponding to the SQL statement, and sort the context sub-handle corresponding to the SQL statement.

[0067] In a possible implementation manner, the second processing module is further configured to:

[0068] Update the usage frequency of the SQL statement, and sort the sub-handle corresponding to the SQL feature hash value according to the updated usage frequency;

[0069] Among them, the sub-handle corresponding to the SQL feature hash value includes the context handle corresponding to the SQL statement.

[0070] In a possible implementation manner, the second processing module is further configured to: update the head of the LRU list.

[0071] In a possible implementation manner, the apparatus further includes: a subscription module; the subscription module is configured to:

[0072] When initializing the client cache system, send a registration instruction to the database of the client cache system, so that a subscription and publication relationship is established between the database in response to the registration instruction and the client cache system.

[0073] In a possible implementation manner, the apparatus further includes: an elimination module; the elimination module is configured to:

[0074] Detect the running environment of the client cache system, and obtain the memory capacity of the LRU list and the memory capacity of the LFU list;

[0075] Eliminate cache resources according to the memory capacity of the LRU list and the memory capacity of the LFU list.

[0076] In a possible implementation manner, the elimination module is further configured to:

[0077] If the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, eliminate some cache resources of the LFU list.

[0078] In a possible implementation manner, the elimination module is further configured to:

[0079] If the total capacity of the client cache system is greater than or equal to the total capacity threshold, eliminate some cache resources of the LRU list.

[0080] In a possible implementation manner, the apparatus further includes: an update module; the update module is configured to:

[0081] If a readable event that is connected is monitored, update the handle corresponding to the readable event in the client cache system.

[0082] In a possible implementation manner, the first processing module is configured to:

[0083] Normalize the SQL statement, and extract name information and feature values according to the normalized SQL statement;

[0084] Perform hashing on the standardized SQL statement, the name information, and the eigenvalue.

[0085] In a third aspect, the present application provides an electronic device, including: a memory, a processor;

[0086] The memory stores computer-executable instructions;

[0087] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the various possible methods in the first aspect and / or the first aspect as described above.

[0088] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the various possible methods in the first aspect and / or the first aspect as described above.

[0089] In a fifth aspect, the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the various possible methods in the first aspect and / or the first aspect as described above.

[0090] The data caching method, device, storage medium, and program product provided by the present application first parse the SQL statement of the client to obtain the name information hash value and the SQL feature hash value corresponding to the SQL statement, and then, according to the name information hash value and the SQL feature hash value, perform hierarchical management on the SQL statement according to a preset caching mechanism to distinguish hot data and cold data, where the preset caching mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data. Then, obtain the context information during the execution of the SQL statement, and mount the context information to the corresponding handle generated by the hierarchical management, and then add the handle to the client caching system. Perform hierarchical management on the caching resources, distinguish hot data and cold data for classification processing, improve the caching hit rate, and thus effectively improve the response speed of the client application and the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0091] The drawings here are incorporated into the description and constitute a part of this description, showing the embodiments consistent with the present application, and are used together with the description to explain the principles of the present application.

[0092] Figure 1 It is a schematic diagram of the scenario of the data caching method provided by the present application;

[0093] Figure 2 It is a flowchart of the data caching method provided by the present application Figure 1 ;

[0094] Figure 3 It is a schematic diagram of the structures of hot data and cold data provided by the present application;

[0095] Figure 4 Flow schematic of the data caching method provided for this application Figure 2 ;

[0096] Figure 5 Flow schematic of the data caching method provided for this application Figure 3 ;

[0097] Figure 6 Structural schematic diagram of the data caching device provided for this application;

[0098] Figure 7 Structural schematic diagram of the electronic device provided for this application.

[0099] Through the above-mentioned drawings, specific embodiments of this application have been shown, and there will be more detailed descriptions hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. Detailed Description of Specific Embodiments

[0100] Here, exemplary embodiments will be described in detail, and their examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. On the contrary, they are merely examples of devices and methods consistent with some aspects of this application as detailed in the appended claims.

[0101] First, the terms related to this application are explained:

[0102] SQL: The full name is Structured Query Language, which refers to the structured query language;

[0103] LRU: The full name is Least Recently Used, which refers to the least recently used;

[0104] LFU: The full name is Least Frequently Used, which refers to the least frequently used;

[0105] Hot Data: Refers to data that is frequently accessed;

[0106] Cold Data: Refers to data that is rarely accessed or has not been accessed for a long time.

[0107] Figure 1 Scenario schematic diagram of the data caching method provided for this application, as Figure 1As shown in the figure, the specific application scenario of this application is that a client application runs in the client 100, and interactions occur between the client 100 and the server 200 when the client application runs. To improve the response speed of the client application and the user experience, a client cache system can be deployed on the server side to block a part of the traffic on the client 100 side and reduce the interaction between the client 100 and the server 200.

[0108] Combined with the above scenario, in the prior art, since the client cache system usually adopts a full - volume cache strategy or a single cache strategy, there is a problem of low cache hit rate for different business scenarios, which will further affect the operation of the client application in the client 100 and cannot meet the system requirements in the current complex business scenarios.

[0109] In view of this, the data caching method provided in the embodiments of this application can be applied to the server 200. First, by parsing the SQL statement of the client, the name - information hash value and the SQL - feature hash value corresponding to the SQL statement are obtained. Then, according to the name - information hash value and the SQL - feature hash value, the SQL statements are hierarchically managed according to a preset caching mechanism to distinguish hot data and cold data, where the preset caching mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data. Then, the context information during the execution of the SQL statement is obtained, and the context information is mounted to the corresponding handle generated by the hierarchical management, and then the handle is added to the client cache system. It can distinguish hot data and cold data for classification processing, and can achieve the effect of improving the cache hit rate and effectively improving the response speed of the client application and the user experience.

[0110] It should be noted that the client 100 and the server 200 can be devices such as smart phones, tablet computers, smart wearable devices, computers, servers, server clusters, etc. The embodiments of this application do not limit the device types of the client 100 and the server 200. Figure 1 In the figure, both the client 100 and the server 200 are shown by taking a computer as an example.

[0111] The technical solution of this application and how the technical solution of this application solves the above - mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0112] Figure 2 It is a flow schematic diagram of the data caching method provided by this application Figure 1 As Figure 2 shown, the method includes:

[0113] S101. Analyze the SQL statement of the client to obtain the name information hash value and SQL feature hash value corresponding to the SQL statement.

[0114] When the client is running, it needs to process SQL statements. The server analyzes the SQL statements that the client needs to process. After analysis, the name information hash value, SQL statement hash value, and SQL feature hash value corresponding to the SQL statements can be obtained.

[0115] In some embodiments, the possible implementation manners of step S101 include:

[0116] First, use a parser to normalize the SQL statement. For example, remove irrelevant characters such as extra spaces and line breaks to standardize it, unify the case to reduce differences caused by different cases, and perform parameterization processing, etc. The normalization processing is convenient for extracting name information and feature values and performing hashing. Then, extract the name information, feature values, etc. of the normalized SQL statement. Among them, the name information can be, for example, the table name, stored procedure name, anonymous block name, function name, type name, view name, etc. that the SQL statement operates on. The feature value can distinguish the type and scenario relationship of the SQL statement. Extracting the name information and feature values is beneficial to the hit rate of the SQL statement, achieving the purpose of refined hit, and facilitating the reuse of previously cached context information.

[0117] Furthermore, perform hashing processing on the normalized SQL statement, name information, and feature values respectively to obtain the SQL statement hash value, name information hash value, and SQL feature hash value in sequence. Among them, the name information hash value can be used as an index for subsequent hierarchical management. The SQL statement hash value is particularly applicable when the SQL statement is a batch binding statement. For other types of SQL statements, the probability of their reuse is not high, and they are generally in a subset or intersection relationship. Therefore, they are placed in the cold data area.

[0118] S102. According to the name information hash value and SQL feature hash value, perform hierarchical management on the SQL statement according to a preset caching mechanism to distinguish hot data and cold data.

[0119] Among them, the preset caching mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data.

[0120] Based on the name information hash value and SQL feature hash value, perform hierarchical management on the SQL statement according to a preset caching mechanism to distinguish whether the current SQL statement belongs to hot data or cold data. Among them, the LRU mechanism is used for hot data, so that an LRU list can be constructed, and the LFU mechanism is used for cold data, so that an LFU list can be constructed.

[0121] In some embodiments, through hierarchical management, in the client cache system, the SQL statement can be, for exampleFigure 3 The hot data and cold data shown are managed to distinguish between cold data and hot data, so that they can be dealt with separately, improving the cache hit rate and facilitating the implementation of the cache eviction policy.

[0122] S103. Obtain the context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by hierarchical management, and add the handle to the client cache system.

[0123] Refer to Figure 3 the structural schematic diagram of the hot data and cold data shown, further obtain the context information during the execution of the SQL statement, such as tracking and collecting the context information during the execution of the SQL statement, and mount it to the corresponding parent / child handle generated by the hierarchical management as shown in Figure 3 , and then add the mounted handle to the client cache system to facilitate the reuse of the subsequent context information.

[0124] The data caching method provided by the embodiment of the present application first parses the SQL statement of the client to obtain the name information hash value and SQL feature hash value corresponding to the SQL statement, and then, according to the name information hash value and SQL feature hash value, performs hierarchical management on the SQL statement according to a preset cache mechanism to distinguish hot data and cold data, where the preset cache mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data, and then obtains the context information during the execution of the SQL statement, mounts the context information to the corresponding handle generated by hierarchical management, and then adds the handle to the client cache system. Hierarchical management of the cache resources of the SQL statement, distinguishing hot data and cold data for classification processing, can improve the cache hit rate, reduce the interaction times between the client and the server, thereby effectively improving the response speed of the client application and the user experience, and ensuring the stability of the client application.

[0125] Figure 4 is a flow schematic of the data caching method provided by the present application Figure 2 , as Figure 4 shown, the method includes:

[0126] S201. Parse the SQL statement of the client to obtain the name information hash value and SQL feature hash value corresponding to the SQL statement.

[0127] The possible implementation manners, principles and technical effects of step S201 are similar to those of step S101. For detailed content, reference can be made to the description of the foregoing embodiments, and details are not described herein again.

[0128] S202: Determine whether the name information hash value hits the cache.

[0129] Determine whether the hash value of the name information hits. If it does not hit, execute step S203. If it hits, execute step S204, that is, perform hierarchical management based on the SQL feature hash value and the hit feature hash value. Among them, when the hash value of the name information already exists in the client cache system, it will hit; otherwise, it will not hit.

[0130] S203: Generate the context parent handle corresponding to the SQL statement.

[0131] When the hash value of the name information does not hit the cache, generate the context parent handle corresponding to the SQL statement. The context parent handle corresponding to the SQL statement includes the name information context parent handle, the SQL statement context parent handle, and the SQL feature context parent handle.

[0132] S205: Use the hash value of the name information as the key and add the context parent handle corresponding to the SQL statement to the head of the LRU list.

[0133] After generating the context parent handle corresponding to the SQL statement, use the hash value of the name information as the key and add the name information context parent handle, the SQL statement context parent handle, and the SQL feature context parent handle to the head of the LRU list, as Figure 3 shown in the hot data area.

[0134] S206: Determine whether the SQL feature hash value is cold data.

[0135] After step S205, further perform hierarchical management according to the SQL feature hash value. Specifically, determine whether the SQL feature hash value is cold data. If so, execute step S207. If not, that is, the SQL feature hash value is hot data, execute step S2011. Among them, the respective scopes of cold data and hot data can be preset in advance. By determining whether the SQL feature hash value belongs to the scope corresponding to cold data or the scope corresponding to hot data, it can be determined whether the SQL feature hash value is cold data or hot data. The specific content of the respective scopes of cold data and hot data in the embodiments of the present application is not limited.

[0136] S204: Determine whether the SQL feature hash value is consistent with the hit feature hash value.

[0137] If the hash value of the name information hits in step S202, execute step S204 to perform hierarchical management based on the SQL feature hash value and the hit feature hash value. Specifically, first determine whether the SQL feature hash value and the hit feature hash value are consistent. If they are consistent, execute step S208. Otherwise; if they are not consistent, that is, the judgment result is negative, execute step S207.

[0138] S207: Generate the context handle corresponding to the SQL statement, and sort the context handle corresponding to the SQL statement.

[0139] Although the hash value of the name information hits, if the SQL feature hash value is not the same as the hit feature hash value, it means that the current SQL statement can be classified into the cold data area as shown in Figure 3 . Therefore, further generate the context handle corresponding to the SQL statement, and sort the context handle. Among them, the context handle corresponding to the SQL statement includes the name information context handle, the SQL statement context handle, and the SQL feature context handle.

[0140] In some embodiments, sorting the context handle corresponding to the SQL statement may include:

[0141] Using the hash value of the name information as the key, add the context handle corresponding to the SQL statement to the LFU list, as shown in the cold data area in Figure 3 .

[0142] Furthermore, in the LFU list, the context handle corresponding to the SQL statement can be sorted according to the usage frequency of the SQL statement.

[0143] It should be noted that after the determination result of step S206 is yes, step S207 is also executed, that is, when it is determined that the SQL feature hash value is cold data, generate the context handle corresponding to the SQL statement, and sort the context handle corresponding to the SQL statement.

[0144] S208: Determine whether the SQL feature hash value is cold data.

[0145] In step S204, if the SQL feature hash value is the same as the hit feature hash value, then execute step S208 to further determine whether the SQL feature hash value is cold data. After judgment, if the SQL feature hash value is not cold data, that is, hot data, then execute step S209; otherwise, if the SQL feature hash value is cold data, then execute step S2010. Among them, the respective scopes of hot data and cold data are preset in advance.

[0146] S209: Obtain the parent handle corresponding to the SQL feature hash value from the LRU list, and update the head of the LRU list.

[0147] When it is determined that the SQL feature hash value is the same as the hit feature hash value and the SQL feature hash value is hot data, hit the parent handle corresponding to the SQL feature hash value from the LRU list, that is, hit the context parent handle corresponding to the SQL statement corresponding to the SQL feature hash value.

[0148] And update the obtained parent handle to the head of the LRU list to update the head of the LRU list.

[0149] S2010: Obtain the child handle corresponding to the SQL feature hash value from the LFU list, update the usage frequency of the SQL statement, and sort the child handle corresponding to the SQL feature hash value according to the updated usage frequency.

[0150] When it is determined that the SQL feature hash value is consistent with the hit feature hash value and the SQL feature hash value is cold data, the child handle corresponding to the SQL feature hash value is hit from the LFU list, that is, the context child handle corresponding to the SQL statement corresponding to the SQL feature hash value is hit to obtain the child handle corresponding to the SQL feature hash value. Among them, the child handle corresponding to the SQL feature hash value includes the context child handle corresponding to the SQL statement pair.

[0151] And update the usage frequency of the SQL statement corresponding to the SQL feature hash value, and sort the context child handle corresponding to the SQL statement according to the updated usage frequency.

[0152] So far, through steps S202 to S2010, the SQL statements are hierarchically managed according to the name information hash value and the SQL feature hash value according to the preset cache mechanism, and the hot data and cold data are distinguished.

[0153] S2011: Obtain the context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by the hierarchical management, and add the handle to the client cache system.

[0154] After the judgment result in step S206 is No, steps S207, S209, and S2010, step S2011 can be further executed, that is, track and collect the context information during the execution of the SQL statement by the client application, and mount the context information to the corresponding corresponding handles according to the distinguished hot data and cold data respectively. For example, if it is hot data, mount the context information during the execution of the SQL statement to the corresponding parent handle, and if it is cold data, mount the context information during the execution of the SQL statement to the corresponding child handle. Then add the corresponding parent / child handle to the client cache system.

[0155] The data caching method provided by the embodiments of the present application hierarchically manages SQL statements based on a preset caching mechanism according to the name information hash value and the SQL feature hash value, and finely distinguishes whether the SQL statements required for the current client processing are hot data or cold data. Compared with the traditional caching strategy, it can greatly improve the hit rate of cached data, reduce the number of interactions between the client and the server, thereby effectively improving the response speed of the client application and the user experience, and ensuring the stability of the client application. In addition, the preset caching mechanism based on the LRU mechanism for hot data and the LFU mechanism for cold data can integrate the elimination strategies of LRU and LFU, improve the cache elimination effect, and to a certain extent, further improve the cache hit rate.

[0156] The caching system will inevitably bring data consistency problems. To address the data consistency problem, the data caching method provided by the embodiments of the present application adopts a publish-subscribe mode. And the data caching method provided by the present application adopts a cache elimination strategy that preferentially eliminates cold data for the differentiated processing of hot data and cold data. Therefore, the data caching method provided by the embodiments of the present application further includes as Figure 5 shown in the steps. Figure 5 is a flowchart of the data caching method provided by the present application Figure 3 As Figure 5 shown, the method includes:

[0157] S301: When initializing the client caching system, send a registration instruction to the database of the client caching system, so that the database responds to the registration instruction to establish a publish-subscribe relationship with the client caching system.

[0158] When the client caching system is started, the client caching system will be initialized. The client caching system will register with its corresponding database. For example, the client caching system sends a registration instruction to the database. The client caching system, as a subscriber, causes the database to respond to the registration instruction to establish a relationship in the publish-subscribe mode with it. Once the database senses a data change, it will notify the client caching system, and the client caching system can then update the context parent handle and the context child handle corresponding to the changed data according to the notification to achieve data synchronization, ensuring cache reliability and the correctness of the cached data.

[0159] Optionally, after the client caching system updates the corresponding handle, it can also mark the corresponding data under the updated corresponding handle as expired.

[0160] Further, S302: Detect the operating environment of the client caching system, and obtain the memory capacity of the LRU list and the memory capacity of the LFU list.

[0161] Detect the operating environment of the current client cache system, and automatically evaluate the cache capacity size for the dynamic implementation of the elimination strategy. Specifically, the memory capacity of the LRU list and the memory capacity of the LFU list can be obtained respectively.

[0162] S303: Determine whether the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold.

[0163] After judgment, if the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, then execute step S304; otherwise, execute step S307.

[0164] S304: Eliminate some cache resources in the LFU list.

[0165] If the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, then eliminate some cache resources in the LFU list to achieve the preferential elimination of the cold data area. Among them, the part of the cache resources to be eliminated can be multiple cache resources close to the end in the sorting, and the specific quantity can be set according to the actual working conditions.

[0166] S305: Determine whether the total capacity of the client cache system is greater than or equal to the total capacity threshold.

[0167] After eliminating some cache resources in the LFU list, further determine whether the total capacity of the client cache system still exceeds the total capacity threshold. If so, execute step S306; otherwise, execute step S307.

[0168] S306: Eliminate some cache resources in the LRU list.

[0169] After preferentially eliminating some cache resources in the cold data area, if the total capacity still exceeds the total capacity threshold, then eliminate some cache resources in the LRU list. The elimination order of the part of the cache resources in the LRU list can be set by itself, and the embodiments of the present application do not make any limitations in this regard.

[0170] It should be noted that the capacity threshold of the client cache system memory can change dynamically with the change of the current client. Once the resources of the client are relatively scarce within a certain period of time, at this time, the client cache system also needs to change accordingly, reducing the capacity threshold and / or the total capacity threshold. At present, the calculation of the capacity threshold and / or the total capacity threshold relies on the empirical coefficient and the linear regression of the current available memory.

[0171] Further, S307: Monitor whether there is a readable event on the connection.

[0172] Monitor whether data arrives between the monitoring client and the client cache system. If so, it means that a readable event is detected, and step S308 is executed; otherwise, it means that no readable event is detected, and step S302 is executed.

[0173] S308: Update the handle corresponding to the readable event in the client cache system.

[0174] If a readable event is detected, update the cache data of the parent / child handle corresponding to the readable event in the client cache system to achieve dynamic update and ensure cache reliability.

[0175] The data caching method provided by the embodiments of this application classifies and processes hot data and cold data, integrates the LRU and LFU elimination strategies, preferentially eliminates cold data, and improves the cache hit rate to a certain extent. Among them, the capacity threshold of the memory is obtained through a dynamic calculation formula, which can also ensure the stability of the client operation. Furthermore, for the data consistency problem, the embodiments of this application adopt the publish-subscribe mode, which can ensure cache reliability and correctness.

[0176] Figure 6 It is a schematic structural diagram of the data caching device provided by this application, as Figure 6 shown. The data caching device 40 includes:

[0177] A first processing module 401, configured to parse the SQL statement of the client to obtain the name information hash value and the SQL feature hash value corresponding to the SQL statement;

[0178] A second processing module 402, configured to classify and manage the SQL statement according to a preset caching mechanism based on the name information hash value and the SQL feature hash value to distinguish hot data and cold data. The preset caching mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data;

[0179] A third processing module 403, configured to obtain the context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by the hierarchical management, and add the handle to the client cache system.

[0180] In a possible implementation manner, the second processing module 402 is specifically configured to:

[0181] Determine whether the name information hash value hits the cache;

[0182] If not, generate a context parent handle corresponding to the SQL statement and perform hierarchical management according to the SQL feature hash value;

[0183] If so, perform hierarchical management according to the SQL feature hash value and the already hit feature hash value;

[0184] Among them, the context parent handles corresponding to the SQL statements include the name information context parent handle, the SQL statement context parent handle, and the SQL feature context parent handle.

[0185] In a possible implementation manner, the second processing module 402 is further configured to:

[0186] When it is determined that the SQL feature hash value is cold data, generate the context child handles corresponding to the SQL statements, and sort the context child handles corresponding to the SQL statements;

[0187] Among them, the context child handles corresponding to the SQL statements include the name information context child handle, the SQL statement context child handle, and the SQL feature context child handle.

[0188] In a possible implementation manner, the second processing module 402 is further configured to:

[0189] Using the name information hash value as the key, add the context child handles corresponding to the SQL statements to the LFU list;

[0190] In the LFU list, sort the context child handles corresponding to the SQL statements according to the usage frequency of the SQL statements.

[0191] In a possible implementation manner, the second processing module 402 is further configured to:

[0192] Using the name information hash value as the key, add the context parent handles corresponding to the SQL statements to the head of the LRU list.

[0193] In a possible implementation manner, the second processing module 402 is further configured to:

[0194] When it is determined that the SQL feature hash value is consistent with the hit feature hash value and the SQL feature hash value is cold data, obtain the child handles corresponding to the SQL feature hash value from the LFU list;

[0195] When it is determined that the SQL feature hash value is consistent with the hit feature hash value and the SQL feature hash value is hot data, obtain the parent handles corresponding to the SQL feature hash value from the LRU list;

[0196] When it is determined that the SQL feature hash value is inconsistent with the hit feature hash value, generate the context child handles corresponding to the SQL statements, and sort the context child handles corresponding to the SQL statements.

[0197] In a possible implementation manner, the second processing module 402 is further configured to:

[0198] Update the usage frequency of the SQL statements, and sort the child handles corresponding to the SQL feature hash value according to the updated usage frequency;

[0199] Among them, the sub-handles corresponding to the SQL feature hash values include the context sub-handles corresponding to the SQL statements.

[0200] In a possible implementation manner, the second processing module 402 is further configured to: update the head of the LRU list.

[0201] In a possible implementation manner, the data caching device 40 further includes: a subscription module; the subscription module is configured to:

[0202] When initializing the client caching system, send a registration instruction to the database of the client caching system, so that a subscription and publication relationship is established between the database and the client caching system in response to the registration instruction.

[0203] In a possible implementation manner, the data caching device 40 further includes: an elimination module; the elimination module is configured to:

[0204] Detect the operating environment of the client caching system, and obtain the memory capacity of the LRU list and the memory capacity of the LFU list;

[0205] Eliminate caching resources according to the memory capacity of the LRU list and the memory capacity of the LFU list.

[0206] In a possible implementation manner, the elimination module is further configured to:

[0207] If the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, eliminate some caching resources of the LFU list.

[0208] In a possible implementation manner, the elimination module is further configured to:

[0209] If the total capacity of the client caching system is greater than or equal to the total capacity threshold, eliminate some caching resources of the LRU list.

[0210] In a possible implementation manner, the data caching device 40 further includes: an update module; the update module is configured to:

[0211] If a readable event that is connected is monitored, update the handle corresponding to the readable event in the client caching system.

[0212] In a possible implementation manner, the first processing module 401 is configured to:

[0213] Normalize the SQL statement, and extract the name information and feature values according to the normalized SQL statement;

[0214] Perform hash processing on the normalized SQL statement, name information, and feature values.

[0215] The data caching device provided by the embodiment of the present application can execute the method provided by the above method embodiment. The implementation principle and technical effects are similar, and will not be elaborated here in this embodiment.

[0216] Figure 7 It is a schematic structural diagram of the electronic device provided by the present application. As Figure 7 shown, the electronic device 50 provided by this embodiment includes: at least one processor 501 and a memory 502.

[0217] Optionally, the device 50 further includes a communication component 503. Among them, the processor 501, the memory 502, and the communication component 503 are connected through a bus 504.

[0218] In a specific implementation process, at least one processor 501 executes the computer execution instructions stored in the memory 502, so that at least one processor 501 executes the above method.

[0219] For the specific implementation process of the processor 501, reference can be made to the above method embodiment. The implementation principle and technical effects are similar, and will not be elaborated here in this embodiment.

[0220] In the above embodiment, it should be understood that the processor may be a central processing unit (English: Central Processing Unit, abbreviated: CPU), and may also be other general-purpose processors, digital signal processors (English: Digital Signal Processor, abbreviated: DSP), application specific integrated circuits (English: Application Specific Integrated Circuit, abbreviated: ASIC), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.

[0221] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.

[0222] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience in representation, the buses in the attached drawings of this application are not limited to only one bus or one type of bus.

[0223] This application also provides a computer program product, including a computer program which, when executed by a processor, implements the above-mentioned method.

[0224] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-mentioned method.

[0225] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk. The readable storage medium can be any available medium accessible by a general-purpose or special-purpose computer.

[0226] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an Application Specific Integrated Circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in a device.

[0227] The division of units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces, and the indirect coupling or communication connection of devices or units can be in an electrical, mechanical or other forms.

[0228] The unit described as a separation component may or may not be physically separated. The component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0229] In addition, in each embodiment of the present invention, each functional unit may be integrated in a processing unit, may exist separately physically for each unit, or two or more units may be integrated in one unit.

[0230] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.

[0231] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above method embodiments; and the aforementioned storage medium includes: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes.

[0232] Finally, it should be noted that: After considering the specification and practicing the invention disclosed herein, those skilled in the art will easily think of other implementation schemes of the present invention. The present invention aims to cover any variations, uses, or adaptive changes of the present invention. These variations, uses, or adaptive changes follow the general principles of the present invention and include common general knowledge or conventional technical means in the technical field not disclosed in the present invention. It is not limited to the exact structure described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present invention is only limited by the appended claims.

Claims

1. A data caching method, characterized in that The method includes: Parsing the SQL statement of the client to obtain the name information hash value and the SQL feature hash value corresponding to the SQL statement; According to the name information hash value and the SQL feature hash value, hierarchically manage the SQL statement according to a preset cache mechanism to distinguish hot data and cold data, where the preset cache mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data; Obtain the context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by hierarchical management, and add the handle to the client cache system.

2. The method according to claim 1, wherein The hierarchically managing the SQL statement according to the name information hash value and the SQL feature hash value to distinguish hot data and cold data includes: Judging whether the name information hash value hits the cache; If not, generating the context parent handle corresponding to the SQL statement and hierarchically managing it according to the SQL feature hash value; If so, hierarchically managing it according to the SQL feature hash value and the hit feature hash value; Among them, the context parent handle corresponding to the SQL statement includes a name information context parent handle, an SQL statement context parent handle, and an SQL feature context parent handle.

3. The method according to claim 2, wherein The hierarchically managing according to the SQL feature hash value includes: When it is determined that the SQL feature hash value is the cold data, generating the context child handle corresponding to the SQL statement and sorting the context child handle corresponding to the SQL statement; Among them, the context child handle corresponding to the SQL statement includes a name information context child handle, an SQL statement context child handle, and an SQL feature context child handle.

4. The method according to claim 3, characterized in that, The sorting the context child handle corresponding to the SQL statement includes: Using the name information hash value as the key, adding the context child handle corresponding to the SQL statement to the LFU list; In the LFU list, sorting the context child handle corresponding to the SQL statement according to the usage frequency of the SQL statement.

5. The method according to claim 2, wherein After generating the context parent handle corresponding to the SQL statement, it further includes: Using the name information hash value as the key, adding the context parent handle corresponding to the SQL statement to the head of the LRU list.

6. The method according to claim 2, wherein The hierarchically managing according to the SQL feature hash value and the hit feature hash value includes: When it is determined that the SQL feature hash value is consistent with the hit feature hash value and the SQL feature hash value is the cold data, obtaining the child handle corresponding to the SQL feature hash value from the LFU list; When it is determined that the SQL feature hash value is consistent with the hit feature hash value and the SQL feature hash value is the hot data, obtaining the parent handle corresponding to the SQL feature hash value from the LRU list; When it is determined that the SQL feature hash value is not consistent with the hit feature hash value, generating the context child handle corresponding to the SQL statement and sorting the context child handle corresponding to the SQL statement.

7. The method according to claim 6, wherein After obtaining the sub-handle corresponding to the SQL feature hash value from the LFU list, the following steps are further included: Update the usage frequency of the SQL statement, and sort the sub-handles corresponding to the SQL feature hash value according to the updated usage frequency; Among them, the sub-handle corresponding to the SQL feature hash value includes the context sub-handle corresponding to the SQL statement.

8. The method according to claim 6, wherein After obtaining the parent handle corresponding to the SQL feature hash value from the LRU list, the following step is further included: Update the head of the LRU list.

9. The method according to claim 6, characterized in that The method further includes: When initializing the client cache system, send a registration instruction to the database of the client cache system, so that a subscription and publication relationship is established between the database in response to the registration instruction and the client cache system.

10. The method according to claim 6, wherein The method further includes: Detect the running environment of the client cache system, and obtain the memory capacity of the LRU list and the memory capacity of the LFU list; Eliminate cache resources according to the memory capacity of the LRU list and the memory capacity of the LFU list.

11. The method according to claim 10, wherein Eliminating cache resources according to the capacity of the LRU list and the memory capacity of the LFU list includes: If the memory capacity of the LRU list and / or the memory capacity of the LFU list is greater than or equal to the capacity threshold, eliminate some cache resources of the LFU list.

12. The method according to claim 11, wherein After eliminating some cache resources of the LFU list, the following step is further included: If the total capacity of the client cache system is greater than or equal to the total capacity threshold, eliminate some cache resources of the LRU list.

13. The method according to claim 12, characterized in that, The method further includes: If a readable event on the connection is monitored, update the handle corresponding to the readable event in the client cache system.

14. The method according to any one of claims 1-13, characterized in that, Parsing the SQL statement of the client includes: Normalize the SQL statement, and extract name information and feature values according to the normalized SQL statement; Perform hash processing on the normalized SQL statement, the name information, and the feature values.

15. A data caching device, characterized in that, Applied to a client cache system, the device includes: A first processing module, configured to parse the SQL statement of the client to obtain the name information hash value and the SQL feature hash value corresponding to the SQL statement; A second processing module, configured to classify and manage the SQL statement according to a preset cache mechanism according to the name information hash value and the SQL feature hash value to distinguish hot data and cold data, and the preset cache mechanism includes the LRU mechanism for hot data and the LFU mechanism for cold data; A third processing module, configured to obtain context information during the execution of the SQL statement, mount the context information to the corresponding handle generated by hierarchical management, and add the handle to the client cache system.

16. An electronic device, characterized in that, It includes: A memory, a processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, so that the processor executes the method according to any one of claims 1-14.

17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1-14 when executed by a processor.

18. A computer program product, characterized in that, It includes a computer program, which implements the method according to any one of claims 1-14 when executed by a processor.

Citation Information

Cited By

  • Cache optimization method and device for tenant configuration modification, equipment and storage medium

    CN121277845A