Data query method, device, equipment and storage medium

By directly outputting the data in the first type cache area and refreshing it asynchronously when querying in the cache, the problem of low data query efficiency in the existing technology is solved, and a more efficient query response and stable user experience are achieved.

CN114138840BActive Publication Date: 2024-09-10CHINA CONSTRUCTION BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111491266.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-08
Publication Date
2024-09-10
Estimated Expiration
2041-12-08

AI Technical Summary

Technical Problem

In the existing technology, the cache refresh operation caused by expiration judgment during the data query process results in low query efficiency, especially in high concurrency scenarios, query response time fluctuates greatly.

Method used

When the target data is queried in the cache, if the cache area where the target data is located is a first-type cache area, the data will be output directly and asynchronously refreshed to avoid expiration judgment during the query process.

Benefits of technology

It reduces the time consuming of data query, improves the efficiency of data query, reduces the fluctuation of query response time, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114138840B
    Figure CN114138840B
Patent Text Reader

Abstract

The present application provides a data query method, device, equipment and storage medium. It relates to the field of data access technology. The data query method includes: receiving a data query request; the data query request includes a target data identifier to be queried; according to the target data identifier, performing a data query in the cached data of the cache; if the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-class cache area, then the first target data is output; the cached data of the first-class cache area is refreshed in an asynchronous manner. The method of the present application refreshes the cached data of the first-class cache area by asynchronous refresh, which can save the time for expiration judgment of the first-class cache area during the data query process, thereby improving the data query efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to data access technology, and in particular to a data query method, device, equipment and storage medium. Background Art

[0002] The Internet provides users with a wealth of information. Through query conditions, users can perform data queries in information systems and obtain information of interest.

[0003] At present, when data query is performed in the information system, the data is queried from the cache when a data query request initiated by the user is received. If result data is queried from the cache, it is determined whether the result data is expired based on the cache validity period of the result data. If the result data is determined to be expired, it is necessary to query new result data from the database and update the result data in the cache based on the new result data so that data query can be performed directly from the cache next time.

[0004] The above data query process requires expiration judgment, which prolongs the time of the data query process and leads to low data query efficiency. Summary of the invention

[0005] The present application provides a data query method, device, equipment and storage medium to solve the problem of low data query efficiency.

[0006] In a first aspect, the present application provides a data query method, comprising: receiving a data query request; the data query request includes a target data identifier to be queried; based on the target data identifier, performing a data query in cached data in a cache; if the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first type of cache area, then outputting the first target data; the cache data in the first type of cache area is refreshed asynchronously.

[0007] In a second aspect, the present application provides a data query device, comprising: a receiving module for receiving a data query request; the data query request includes a target data identifier to be queried; a query module for performing a data query in cached data in a cache according to the target data identifier; an output module for outputting the first target data when the first target data corresponding to the target data identifier is queried in the cache and the target cache area where the first target data is located is a first type of cache area; the cache data of the first type of cache area is refreshed asynchronously.

[0008] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.

[0009] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.

[0010] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.

[0011] The data query method, device, equipment and storage medium provided by the present application receive a data query request, the data query request includes a target data identifier to be queried; and according to the target data identifier, perform data query in the cached data in the cache; if the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-class cache area, then the first target data is output; the cached data in the first-class cache area is refreshed in an asynchronous manner. Since the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-class cache area, then the first target data is output; the cached data in the first-class cache area is refreshed in an asynchronous manner, therefore, there is no need to perform expiration judgment on the first-class cache area during the data query process, thereby reducing the data query time and improving the data query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0013] Figure 1 An application scenario diagram for data query of prior art;

[0014] Figure 2 An application scenario diagram provided for an embodiment of the present application;

[0015] Figure 3 A schematic diagram of the structure of a cache unit provided in an embodiment of the present application;

[0016] Figure 4 The process of the data query method provided in the embodiment of the present application Figure 1 ;

[0017] Figure 5 The process of the data query method provided in the embodiment of the present application Figure 2 ;

[0018] Figure 6 A control logic diagram of asynchronous refresh provided in an embodiment of the present application;

[0019] Figure 7 The process of the data query method provided in the embodiment of the present application Figure 3 ;

[0020] Figure 8 A schematic diagram of the structure of a data query device provided in an embodiment of the present application;

[0021] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0022] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0023] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0024] Internet applications can provide users with convenient data query functions, based on which users can obtain a large amount of Internet information. For example, data queries can be performed for air tickets and train ticket information for popular holiday routes, social hot events, etc. In some scenarios where the query conditions are relatively popular, a large number of queries will be generated in a short period of time, which will put great pressure on the information system. Since the query conditions of these popular query requests are often the same, the existing scheme sets a cache for such popular query requests, and stores the query data of the popular query requests in the cache, so as to query the data directly from the cache, reduce the pressure on the information system, and improve the query response speed. The data query process of the prior art will be introduced in conjunction with the accompanying drawings below:

[0025] Figure 1 This is an application scenario diagram of data query in the prior art. Figure 1 As shown, the application scenario includes: a terminal device 11, a cache server 12 and a database server 13;

[0026] The terminal device 11 includes devices with information search functions such as smart phones, tablet computers, laptop computers, and desktop computers.

[0027] The cache server 12 is provided with a cache, and the database server 13 is provided with a database.

[0028] Currently, the cache-based data query solution includes the following steps:

[0029] Step 1: The cache server receives a data query request;

[0030] Step 2: The cache server queries data from the cache;

[0031] Step 3: If the result data is not found in the cache, that is, the cache is not hit, the cache server queries the data from the database, stores the result data found in the database in the cache, and returns the result data to the terminal device.

[0032] Step 4: If the result data is found in the cache, i.e., the cache is hit, the cache server determines whether the result data is expired according to the cache validity period of the result data stored in the cache;

[0033] Step 5: If the result data stored in the cache is expired, the cache server queries the database for data, updates the cache according to the new result data queried from the database, and then returns the new result data to the terminal device.

[0034] Step 6: If the result data stored in the cache has not expired, the result data is directly returned to the terminal device.

[0035] The above judgment of whether the result data stored in the cache is expired, and step 5 of querying data from the database if the result data stored in the cache is expired, and updating the cache according to the new result data queried from the database, can be understood as a cache refresh operation, that is, a real-time cache refresh operation is performed during data query. When performing a real-time cache refresh operation during data query, in a scenario where the query concurrency is large and the query cost (referring to the time spent on data query from the database) is high, it is easy for a large number of threads to update the same data instantly when the cache expires, and a large number of query requests query the database at the same time or are in a waiting state, and the query takes a long time, which ultimately causes a large fluctuation in the overall response time of the data query, affecting the user experience.

[0036] In response to the above technical problems, the present application proposes the following technical concept: when performing data query in the cache according to the target data identifier, if the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-type cache area, the first target data is directly output; and the cache data of the first-type cache area is refreshed in an asynchronous manner. By adopting an asynchronous refresh method for the first-type cache area during the data query process, the time consumption of data query can be reduced and the data query efficiency can be improved.

[0037] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following 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 the present application will be described below in conjunction with the accompanying drawings.

[0038] Figure 2 This is an application scenario diagram provided by the embodiment of the present application. Figure 2 As shown, the application scenario includes: a terminal device 21, an application server 22 and a database server 23;

[0039] The terminal device 21 includes devices with information search functions such as smart phones, tablet computers, laptop computers, and desktop computers.

[0040] The application server 22 is provided with a cache, and the database server 23 is provided with a database.

[0041] The database server 23 may be a single server or a server cluster including multiple servers.

[0042] As an optional implementation, Figure 2 The application server in the example may also be a cache server, and the cache server may be a single server or a server cluster including multiple servers.

[0043] The entire cache area used to cache data in the cache is called a cache area. The metadata stored in the cache area is a cache unit. The structure of the cache unit is as follows:

[0044] Figure 3 This is a schematic diagram of the structure of the cache unit provided in the embodiment of the present application. Figure 3As shown, the cache unit uses a key-value pair (KEY-VALUE) to cache data. KEY is the index number, and VALUE stores the cache data and cache information of the cache data. Each key-value pair is used to store a cache data. The size of the cache data in each cache unit can be the same or different, while the size of the cache occupied by other parts, such as refresh time, query hit count, query cost, and retention value, is the same, that is, the size of each cache unit can be the same or different.

[0045] The cache information of cached data includes refresh time, hit count, query cost and retention value. In the business system, cached data can also be called business data. Taking orders as an example, KEY can be information that can uniquely identify the order, such as the order number, and the cached data in VALUE can be the order status of the order corresponding to the order number. The order status includes completed, uncompleted, shipped, unshipped, etc. The storage structure of order data in the cache is shown in Table 1:

[0046] Table 1 Storage structure of order data

[0047]

[0048] The refresh time is the timestamp corresponding to the time when the cache is created or last refreshed. The refresh time is updated every time a refresh operation is performed on the cache data.

[0049] The query hit count is the number of query hits of the data to be queried in the cache from the refresh time to the current time. The hit count is updated every time the cache is queried.

[0050] The query cost is used to represent the time spent on searching the database for the data to be queried.

[0051] The retention value is used to indicate the cache value of cached data. The retention value is positively correlated with the cache value, that is, the larger the retention value, the larger the cache value, and the smaller the retention value, the smaller the cache value. The retention value can be calculated according to the following method:

[0052] V = Vp / 2 + a*n / (Tc-Tr) + b*C;

[0053] Among them, Vp is the current retention value of the cached data; n is the number of query hits of the cached data in the cache, Tc is the current time, Tr is the refresh time corresponding to the cached data, C is the query cost of the cached data, a and b are both weights, and a+b=1.

[0054] The cache in the application server 22 includes a first type of cache area, a second type of cache area, and a third type of cache area;

[0055] The first type of cache area is used to store cache data with a retention value greater than or equal to a preset retention value. The retention value is determined based on the query cost of the cache data and the number of query hits in the cache. The query cost of the cache data is the time consumed to query the cache data from the database. For two cache data, under the same refresh time and the same number of query hits, the higher the query cost, the higher the retention value, and it is more suitable to be stored in the first type of cache area. Among them, the cache data cached in the first type of cache area can be understood as data with a query hit probability in the cache greater than the preset probability and a query cost greater than the preset query cost.

[0056] The second type of cache area is used to store cache data newly added to the cache.

[0057] The third type of cache area is used to store cache data stored in the second type of cache area 222 for more than a preset time. Alternatively, the third type of cache area is used to store the first Q cache data after the cache data in the first type of cache area are sorted in descending order of retention value.

[0058] based on Figure 2 and Figure 3 , this application also proposes the following data query method. Specifically, Figure 4 The process of the data query method provided in the embodiment of the present application Figure 1 ,like Figure 4 As shown, the data query method includes:

[0059] S4001. Receive a data query request, where the data query request includes an identifier of target data to be queried.

[0060] The execution subject of the method of this embodiment can be as follows Figure 2 The application server shown. The user can send a data query request to the application server through the terminal device, and the application server receives the data query request sent by the terminal device.

[0061] For example, a user may input a search condition through a search box provided by a terminal device to initiate a data query request to an application server. The keyword in the search condition is the target data identifier.

[0062] S4002: According to the target data identifier, perform data query in the cached data.

[0063] Specifically, the application server searches the entire cache area, i.e., the first-category cache area, the second-category cache area, and the third-category cache area, for cache data corresponding to the target data identifier according to the target data identifier. If cache data corresponding to the target data identifier exists, the cache data corresponding to the target data identifier is determined as the target data, i.e., the target data is found in the cache. Otherwise, the target data is not found in the cache.

[0064] In a scenario where a user queries an order status in a cache by using an order number, the order number can be understood as a target data identifier, and specific order status data can be understood as target data.

[0065] After step S4002, it is also necessary to determine whether the first target data corresponding to the target data identifier is found in the cache.

[0066] S4003: If the first target data corresponding to the target data identifier is found in the cache, determine whether the target cache area where the first target data is located is a first-type cache area.

[0067] S4004: If the target cache area where the first target data is located is a first-type cache area, the first target data is output, and the cache data of the first-type cache area is refreshed in an asynchronous manner.

[0068] In this step, after the first target data is output, the query hit count of the target data needs to be updated. Specifically, the query hit count of the first target data in the first type of cache area is increased by 1, and the first target data is returned to the terminal device.

[0069] The above steps S4003 and S4004 can be summarized as follows: if the first target data corresponding to the target data identifier is found in the cache, and the target cache area where the first target data is located is a first-type cache area, the first target data is output; wherein the cache data in the first-type cache area is refreshed in an asynchronous manner. Outputting the first target data means returning the first target data to the user's terminal device. The specific implementation method of asynchronous refresh will be introduced in subsequent embodiments.

[0070] Still taking the order status query as an example, if the order status of an order is queried in the first type of cache area, the query hit count of the order in the first type of cache area is increased by 1, and the queried order status is returned to the terminal device.

[0071] Among them, the first type of cache area is used to store data with a large query volume and high query cost, so it can improve the query hit probability in the cache, thereby reducing the access to the database. Asynchronous refresh includes: setting the data in the cache area to directly return the first target data queried in the first type of cache area after the query request hits the first type of cache area, and then end after updating the query hit count of the first target data in the cache, that is, returning the first target data queried in the cache area, and updating the query hit count in the cache, and then not refreshing the cache area.

[0072] This embodiment receives a data query request, which includes a target data identifier to be queried; and performs data query in the cached data in the cache according to the target data identifier; if the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-type cache area, the first target data is output; and the cached data in the first-type cache area is refreshed in an asynchronous manner. Since the first target data corresponding to the target data identifier is queried in the cache, and the target cache area where the first target data is located is a first-type cache area, the first target data is output; and the cached data in the first-type cache area is refreshed in an asynchronous manner, there is no need to perform expiration judgment on the first-type cache area during the data query process, thereby reducing the data query time and improving the data query efficiency.

[0073] Figure 5 The process of the data query method provided in the embodiment of the present application Figure 2 .like Figure 5 As shown, after S4003, this embodiment may further include the following steps:

[0074] S4005: If the target cache area where the first target data is located is not a first-type cache area, determine whether the first target data is expired according to the cache validity period of the first target data.

[0075] The cache data in the cache is set with a cache validity period. When the application server queries the first target data in the cache, it determines whether the first target data is expired based on the cache validity period of the first target data, the time when the first target data is added to the cache (that is, the time when the first target data is added to the cache), and the current time. If it is determined that the first target data is expired, the application server forwards the data query request to the database server. The database server obtains the second target data from the database and returns the second target data to the application server. The application server updates the first target data according to the second target data, that is, uses the second target data to replace the expired first target data in the cache.

[0076] In this embodiment, if the first target data is obtained by querying in the first type of cache area, the first target data is directly returned to the terminal device and the process ends. That is, after the first target data is obtained by querying in the first type of cache area, the first target data in the first type of cache area is not judged to be expired. Instead, when the first target data is queried in a non-first type of cache area, that is, a second type of cache area or a third type of cache area, the first target data is judged to be expired.

[0077] S4006: If it is determined that the first target data is expired, query the second target data from the database according to the first target data identifier.

[0078] S4007. Update the first target data and cache information of the first target data according to the second target data.

[0079] Still taking order query as an example, if the target data is identified as order status, the specific content of the order status is unsuccessful, and the cache validity period is 5 minutes. Within the 5 minutes, the order system has updated the order status of the order in the database to completed. After the unsuccessful order status is stored in the second cache area or the third cache area for more than 5 minutes, the application server queries the second cache area or the third cache area according to the order identifier and obtains that the order status is unsuccessful. At this time, the latest order status of the order in the database has been updated to completed. Therefore, the first target data in the second cache area or the third cache area has expired, and it is necessary to obtain the second target data from the database and use the second target data to replace the first target data.

[0080] It should be understood that the above examples are only for illustrative purposes, and in practice, the second target data obtained from the database according to the target data identifier may also be the same as the first target data, for example, the order status has not changed. Regardless of whether the order status has changed, as long as the first target data in the cache has expired, it is necessary to query the database for the second target data and use the second target data to update the first target data.

[0081] S4008. Output the second target data.

[0082] It should be understood that there is no restriction on the order of step S4007 and step S4008. Step S4007 may be performed first and then step S4008, or step S4008 may be performed first and then step S4007, or step S4007 and step S4008 may be performed simultaneously.

[0083] In some embodiments, the cache information includes the query hit count, and updating the cache information of the first target data includes: updating the query hit count of the first target data. Optionally, the query hit count of the first target data in the cache may be increased by 1.

[0084] In some other embodiments, the cache information includes the query cost, and updating the cache information of the first target data includes:

[0085] Step A: obtaining the query cost of the second target data, where the query cost of the second target data is the time consumed in querying the second target data from the database.

[0086] Step B: updating the query cost of the first target data according to the query cost of the second target data.

[0087] If the cache information of the first target data includes the query hit count and the query cost, the query hit count and the query cost of the first target data are updated simultaneously according to the above implementation method of updating the query hit count and the implementation method of updating the query cost.

[0088] For example, the query cost of the first target data is t'1, the query hit count is n, and the query cost of the second target data is t'2, then the query cost of the first target data is updated to t'2, and n is updated to n+1.

[0089] Table 2 Cache information of the first target data

[0090]

[0091] Table 3 Cache information of the second target data

[0092]

[0093] S4009: If it is determined that the first target data is not expired, the query hit count of the first target data is updated, and step S4008 is executed, that is, the first target data is output.

[0094] Optionally, the query hit count of the first target data may be increased by 1. Still taking the order as an example, if before step S4009, the cache information of the first target data is as shown in Table 2, then the cache information of the first target data after being updated in this step is as shown in Table 4:

[0095] Table 4 Cache information of the first target data

[0096]

[0097] S4010: If the first target data is not found in the cache, query the second target data from the database according to the target data identifier, and execute step S4008, that is, output the second target data.

[0098] The above steps S4001 to S4010 can be summarized into the following four optional implementations:

[0099] a1. If the first target data is found in the cache, and the target cache area where the first target data is located is a first-type cache area, the first target data is output.

[0100] a2. If the first target data is found in the cache, and the target cache area where the first target data is located is not the first type of cache area, and it is determined that the first target data is not expired based on the cache validity period of the target data, the first target data is output.

[0101] a3. If the first target data is found in the cache, and the target cache area where the first target data is located is not the first type of cache area, and the first target data is determined to be expired based on the cache validity period of the target data, then query the database based on the target data identifier to obtain the second target data corresponding to the target data identifier, and output the second target data.

[0102] a4. If the data corresponding to the target data identifier is not found in the cache, query the database according to the target data identifier to obtain the second target data corresponding to the target data identifier, and output the second target data.

[0103] It should be noted that for the above a1 to a3, if the first target data is found in the cache, the cache information of the first target data in the target cache area needs to be updated. The cache information includes: query hit count, query cost, retention value and refresh time; the query cost is used to characterize the time spent on querying from the database, and the retention value is used to characterize the cache value; and updating the cache information of the first target data in the target cache area includes:

[0104] a1-1. If the first target data is found in the cache, and the target cache area where the first target data is located is a first-type cache area, the query hit count of the first target data in the target cache area is updated.

[0105] Here, a1-1 can be understood as that, based on a1, the number of query hits of the first target data in the target cache area needs to be updated.

[0106] a2-1. If the first target data is found in the cache, and the target cache area where the first target data is located is not the first type of cache area, and the first target data is not expired, the query hit count of the first target data in the target cache area is updated.

[0107] Here, a2-1 can be understood as that, based on a2, the number of query hits of the first target data in the target cache area needs to be updated.

[0108] a3-1. If the first target data is found in the cache, and the target cache area where the first target data is located is not the first type of cache area, and the first target data is expired, then all cache information of the first target data in the target cache area and the first target data are updated according to the second target data.

[0109] Among them, a3-1 can be understood as that on the basis of a3, all cache information of the first target data in the target cache area and the first target data need to be updated.

[0110] For the above a4, if the data corresponding to the target data identifier is not found in the cache, the database is queried according to the target data identifier. After obtaining the second target data corresponding to the target data identifier, steps S4011 and S4012 need to be executed:

[0111] S4011. Determine whether there is any remaining cache space in the second-type cache area; the second-type cache area is used to store data newly added to the cache.

[0112] S4012: If there is no remaining cache space in the second type of cache area, then end.

[0113] Specifically, if the target data is not found in the cache and there is no remaining cache space in the second type of cache area, that is, the cache space in the second type of cache area is full, it means that the entire cache area is full and cannot accommodate more cache data. The query program in the application server will query the target data from the database and directly return the target data.

[0114] S4013: If there is remaining cache space in the second-type cache area, add the second target data and cache information of the second target data to the second-type cache area.

[0115] In this step, the cache information of the second target data includes at least one of the query hit count, query cost, and refresh time. Then, the cache information of the second target data is added to the second type of cache area, including:

[0116] Step b1, record the number of query hits for the second target data.

[0117] The second target data is added to the cache for the first time. After this step, the query hit count of the second target data is 1.

[0118] Step b2: record the query cost of the second target data.

[0119] Before step b2, the query cost of the second target data needs to be determined. Specifically, determining the query cost of the second target data includes: obtaining the time consumed for querying the second target data from the database.

[0120] Specifically, when querying the second target data corresponding to the target data identifier from the database, the query record will include the time consumed in querying the second target data corresponding to the target data identifier from the database. Therefore, the query record of querying the second target data corresponding to the target data identifier from the database can be directly obtained, and the time consumed in querying the second target data from the database can be obtained, and the time consumed in querying the second target data from the database can be determined as the query cost of the second target data.

[0121] Step b3: Record the time when the second target data is added to the second type of cache area as the refresh time of the second target data.

[0122] Since the second target data is added to the cache for the first time, the refresh time of the second target data is the addition time when the second target data is first added to the cache.

[0123] Step b4: record the retained value of the second target data.

[0124] Since the second target data is added to the cache for the first time and the retention value is not needed in the data query process, the retention value of the second target data may not be calculated in this step, and the retention value of the second target data may be directly recorded as 0. The update of the retention value of the second target data will be performed during the asynchronous refresh process.

[0125] The above embodiments can be summarized as follows:

[0126] 1) If the cache misses, that is, the first target data is not found in the entire cache area, and the second type of cache area is full, it means that the space of the entire cache area is full and cannot accommodate more cache data. The query program directly queries the second target data from the database and returns it to the terminal device.

[0127] 2) If the cache hits, that is, the first target data is found in the entire cache area, and the hit cache area is a first-type cache area, the first target data is directly obtained and returned to the terminal device without cache expiration judgment and cache refresh operations.

[0128] 3) If the cache hits, that is, the first target data is found in the entire cache area, and the hit cache area does not belong to the first type of cache area, it is necessary to determine whether the first target data is expired. If expired, a cache refresh operation is performed.

[0129] 4) For the cache refresh time field, if the cache data is newly added to the cache, the refresh time of the cache data is recorded as the time when the cache data is added to the second type of cache area.

[0130] 5) If the cache is hit and the second type of cache area is not full, when querying the second target data through the database, the first target data in the cache and the query cost of the first target data need to be updated.

[0131] 6) Whenever a cache hit occurs or a new cache entry is added, the hit count must be incremented by 1.

[0132] In the above embodiment, it has been introduced that in order to improve the efficiency of data query, the first type of cache area is not subjected to expiration judgment and refresh operation during the data query process. In order to ensure that the cached data in the first type of cache area is the latest data, the first type of cache area is refreshed by asynchronous refresh. The following will introduce the asynchronous refresh in detail with reference to the accompanying drawings:

[0133] Figure 6 The process of the data query method provided in the embodiment of the present application Figure 2 .like Figure 6 As shown, the data query method includes the following steps:

[0134] S6001. Receive a trigger message for cache refresh.

[0135] Optionally, a timing unit may be set in the application server, and the timing unit sends a trigger message for cache refresh to the refresh unit in a timing triggering manner. The refresh unit receives the trigger message for cache refresh sent by the timing unit at regular intervals. The trigger message is used to trigger the refresh unit to refresh the entire cache area through a refresh program.

[0136] S6002: Determine whether the cache area to be refreshed during cache refresh is a first-type cache area.

[0137] In this embodiment, the entire cache area of ​​the cache can be understood as a number of cache areas, each of which has a corresponding cache area identifier, and the cache area identifier is used to identify whether the cache area is a first-class cache area, a second-class cache area, or a third-class cache area. For example, if the cache area identifier is 1, it means that the cache area is a first-class cache area; if the cache area identifier is 2, it means that the cache area is a second-class cache area; if the cache area identifier is 3, it means that the cache area is a third-class cache area. By traversing a number of cache areas and according to the identifier of the currently traversed cache area, it is possible to determine whether the cache area to be refreshed is a first-class cache area.

[0138] S6003: If the cache area to be refreshed is a first-type cache area during cache refresh, the cache data and cache information of the cache data stored in the cache area to be refreshed are asynchronously refreshed.

[0139] The cache information of the cache data asynchronously refreshed in step S6003 includes: query cost, retention value, refresh time and query hit count:

[0140] Specifically, asynchronously refreshing the cache data and cache information of the cache data stored in the cache area to be refreshed includes:

[0141] Step c1: asynchronously query the database to obtain new cache data.

[0142] Optionally, new cache data may be queried in the database according to the identifier of the cache data stored in the cache area to be refreshed.

[0143] Step c2: Refresh the cache data stored in the cache area to be refreshed according to the new cache data.

[0144] Specifically, the cache data stored in the cache area to be refreshed is replaced with new cache data.

[0145] Step c3: Refresh the cache information of the cache data stored in the cache area to be refreshed according to the query information of the new cache data.

[0146] The cache information includes: query hit count, query cost, retention value, and refresh time; the query cost is used to represent the time spent on querying from the database, and the retention value is used to represent the cache value. Based on the query information of the new cache data, the cache information of the cache data stored in the cache area to be refreshed is refreshed, including:

[0147] Step c31: Determine the query cost after the cache data is refreshed according to the query information of the new cache data.

[0148] The query information of the new cache data includes: the time spent in querying the new cache data from the database. The query cost after the cache data is refreshed is determined according to the query information of the new cache data, including: determining the time spent in querying the new cache data from the database as the query cost after the cache data is refreshed.

[0149] Step c32: Obtain the retention value after the cache data is refreshed according to the query cost after the cache data is refreshed, the number of query hits before the refresh, and the refresh time before the refresh.

[0150] Specifically, according to the query cost after the cache data is refreshed, the number of query hits before the refresh, and the refresh time before the refresh, the retention value after the cache data is refreshed is obtained, including:

[0151] Step c321, determine the time difference between the current time and the refresh time before the cache data is refreshed.

[0152] Step c322, obtaining a first value by dividing the number of query hits before the cache data is refreshed by the time difference;

[0153] Step c323: Obtain the retention value after the cache data is refreshed according to the retention value before the cache data is refreshed, the first value, and the query cost after the cache data is refreshed.

[0154] Among them, the retention value after the cache data is refreshed is obtained according to the retention value before the cache data is refreshed, the product of the first numerical value and the first weight, and the product of the second weight and the query cost after the cache data is refreshed, including: the retention value after the cache data is refreshed is obtained by the sum of half of the retention value before the cache data is refreshed, the product of the first numerical value and the first weight, and the product of the second weight and the query cost after the cache data is refreshed.

[0155] In this embodiment, the retention value comprehensively considers the query hit count and query cost of the cached data. At the same time, when calculating the retention value, half of the current retention value is taken into account, which can make the change of the retention value smoother, thereby avoiding cache jitter, that is, some cached data is migrated too frequently.

[0156] Step c33: Use the query cost after the cache data is refreshed to refresh the query cost of the cache data stored in the cache area to be refreshed, and use the retention value after the cache data is refreshed to refresh the retention value of the cache data stored in the cache area to be refreshed.

[0157] Specifically, the query cost of the cache data stored in the cache area to be refreshed is replaced with the query cost after the cache data is refreshed, and the retention value of the cache data stored in the refresh cache area is replaced with the retention value after the cache data is refreshed.

[0158] Step c34: Refresh the query hit count and refresh time of the cache data stored in the cache area to be refreshed.

[0159] The query hit count after refresh refers to clearing the query hit count of the new cache data to zero, that is, setting it to 0. The refresh time after refresh refers to the time for performing a refresh operation on the refresh time of the cache data stored in the cache area to be refreshed.

[0160] S6004. If the cache area to be refreshed during cache refresh is a second-category cache area or a third-category cache area, the retention value of the cache data after refresh is obtained according to the query cost, query hit count, and refresh time of the cache data; the second-category cache area is used to store data newly added to the cache, and the third-category cache area is used to store the first Q cache data in the first-category cache area after the cache data is sorted in descending order according to the retention value. The cache data of the second-category cache area and the third-category cache area are refreshed based on the cache validity time, and Q is an integer greater than or equal to 1.

[0161] Specifically, if the cache area to be refreshed during cache refresh is a second-category cache area or a third-category cache area, the retention value of the cache data after refreshing is obtained according to the query cost, query hit count, and refresh time of the cache data, including:

[0162] Step d1, determining the time difference between the current time and the refresh time before the cache data is refreshed.

[0163] Step d2, obtaining a first value by dividing the number of query hits before the cache data is refreshed by the time difference;

[0164] Step d3: Obtain the retention value after the cache data is refreshed according to the retention value before the cache data is refreshed, the first value, and the query cost after the cache data is refreshed.

[0165] Among them, the retention value after the cache data is refreshed is obtained according to the retention value before the cache data is refreshed, the product of the first numerical value and the first weight, and the product of the second weight and the query cost after the cache data is refreshed, including: the retention value after the cache data is refreshed is obtained by the sum of half of the retention value before the cache data is refreshed, the product of the first numerical value and the first weight, and the product of the second weight and the query cost after the cache data is refreshed.

[0166] S6005. Use the retention value after the cache data is refreshed to refresh the retention value of the cache data stored in the cache area to be refreshed, and refresh the refresh time and query hit count of the cache data.

[0167] Specifically, the query cost of the cache data stored in the cache area to be refreshed is replaced with the query cost after the cache data is refreshed, and the retention value of the cache data stored in the refresh cache area is replaced with the retention value after the cache data is refreshed.

[0168] The query hit count after refresh refers to clearing the query hit count of the new cache data to zero, that is, setting it to 0. The refresh time after refresh refers to the time for performing a refresh operation on the refresh time of the cache data stored in the cache area to be refreshed.

[0169] It should be understood that for the first type of cache area, the second type of cache area and the third type of cache area, the retention value is calculated first and then the refresh time is updated in this embodiment because if the refresh time is updated first and then the retention value is calculated, the denominator (Tc-Tr) of the second term on the right side of the equal sign of the retention value calculation formula: V=Vp / 2+a*N / (Tc-Tr)+b*C will be 0, which makes the second term infinite, and then leads to inaccurate calculation of the retention value. Therefore, in this embodiment, it is necessary to calculate the retention value first and then update the refresh time.

[0170] As for the second type of cache area, since it stores data newly added to the cache and records the refresh time, in order to avoid frequent changes in the refresh time, the refresh time and query hit count of the cache data in the second type of cache area may not be refreshed during the asynchronous refresh process of this embodiment.

[0171] In addition, since the cached data in the second type of cache area may be queried during the interval between two adjacent refresh operations, and the query hit count, refresh time, and query cost of the cached data may be updated, the retention value of the cached data in the second type of cache area may also change. In the data query process, in order to save data query time, the retention value of the cached data in the second type of cache area is not updated. In the asynchronous refresh process of this embodiment, the retention value of the cached data in the second type of cache area is updated, and the retention value of the cached data in the second type of cache area can be determined in real time.

[0172] The timed refresh process of this embodiment includes three types of operations: the first type of operation is to query new cache data from the database and update the cache data in the cache; the second type of operation is to calculate the retention value of the cache data; the third type of operation is to clear the number of query hits and update the refresh time of the cache data. Among them, for the first type of cache area, since the cache data in the first type of cache area is not judged to be expired and refreshed during the data query process. In order to avoid the expiration of the cache data in the first type of cache area, this embodiment can ensure that the cache data in the first type of cache area is the latest state of cache data by performing the first type of operation on the cache data in the first type of cache area during the timed refresh process, thereby providing accurate query results for users. In addition, the cache data in the first type of cache area can be used directly during the data query process, thereby improving data query efficiency.

[0173] Optionally, the above asynchronous refresh process may be initiated in the form of a daemon process, and the time interval between each initiation round may be determined according to the business scenario and the storage space size of the first type of cache area.

[0174] Optionally, this embodiment can also use a single thread or multiple threads concurrently to perform timed refresh to improve refresh efficiency. Specifically, multiple threads can be used to perform timed refresh on three types of cache areas at the same time, that is, each type of cache area uses one thread to perform timed refresh, and at least two types of cache areas can be refreshed at the same time.

[0175] After the retention values ​​of the cached data in the first cache area, the second cache area, and the third cache area are updated through the above embodiments, the cached data in the first cache area, the second cache area, and the third cache area can also be adjusted according to the retention values ​​of the cached data in the first cache area, the second cache area, and the third cache area. The adjustment process for the cached data in the first cache area, the second cache area, and the third cache area will be specifically described below.

[0176] Figure 7 The process of the data query method provided in the embodiment of the present application Figure 3 .like Figure 7As shown, the data query method further includes:

[0177] S7001. Determine the first M cache data in the first type of cache area and the first N cache data in the third type of cache area in descending order of retention values; M and N are both integers greater than or equal to 0, and M and N are not 0 at the same time.

[0178] S7002. Migrate the first N cache data from the third type cache area to the first type cache area.

[0179] S7003. Migrate cache data except the first M cache data in the first type of cache area from the first type of cache area to the third type of cache area.

[0180] Exemplarily, all cache data in the first cache area and the third cache area are sorted in descending order according to the retention value, and the first M cache data in the first cache area and the first N cache data in the third cache area are determined. The first N cache data in the third cache area are migrated from the third cache area to the first cache area, and the cache data in the first cache area except the first M cache data are migrated from the first cache area to the third cache area.

[0181] It should be understood that the cumulative sum of the storage space of the M cache data and the N cache data is the maximum storage space of the first type of cache area. The cumulative sum of the storage space of the cache data other than the first M cache data in the first type of cache area and the cache data other than the first N cache data in the third type of cache area is not greater than the maximum storage space of the third type of cache area.

[0182] The above steps S7001 to S7003 can be understood as sorting all cache data in the first and third cache areas in descending order according to the retention value, and determining the first N' cache data in the sorting result, and storing the N' cache data in the first cache area, and storing the cache data other than the N' cache data in the sorting result in the third cache area. Wherein, N' is an integer greater than or equal to 1, and its value is less than the number of all cache data in the first and third cache areas.

[0183] After step S7003, this embodiment may further include:

[0184] S7004: Determine whether the remaining storage space of the third type of cache area is less than a preset storage space threshold.

[0185] S7005. If the remaining storage space of the third type of cache area is less than the preset storage space threshold, delete the last Q cache data in the third type of cache area in descending order of retention values, where Q is an integer greater than or equal to 1, so that the remaining storage space of the third type of cache area is equal to the preset storage space threshold;

[0186] S7006. Migrate the first Q cache data in the second-type cache area from the second-type cache area to the third-type cache area in descending order of retention values.

[0187] Optionally, after S7004, the following steps may also be included:

[0188] S7007. If the remaining storage space of the third type of cache area is greater than the preset storage space threshold, the first X cache data in the second type of cache area are migrated from the second type of cache area to the third type of cache area in descending order of retention value, where X is an integer greater than or equal to 1.

[0189] S7008. If the remaining storage space of the third type of cache area is equal to the preset storage space threshold, the first Y cache data in the second type of cache area are migrated from the second type of cache area to the third type of cache area in order of retention value from large to small, where Y is an integer greater than or equal to 1.

[0190] After steps S7006, S7007 and S7008, the remaining storage space of the third type of cache area may be 0. Of course, there is also a situation where all cache data in the second type of cache area is migrated from the second type of cache area to the third type of cache area, and the remaining storage space of the third type of cache area is still not 0.

[0191] In this embodiment, the storage space refers to the amount of cache data that can be stored. Exemplarily, the storage space sizes of the second-type cache area, the third-type cache area, and the first-type cache area are N1, N2, and N3, respectively, that is, the maximum amount of cache data that can be stored in the second-type cache area, the third-type cache area, and the first-type cache area is N1, N2, and N3, respectively. This embodiment sorts the N2+N3 cache data of the first and third cache areas in order from large to small, and stores the first N3 cache data in the sorting result to the first cache area, and stores the remaining N2 cache data in the sorting result to the third cache area; then, determines whether the remaining storage space of the second cache area is greater than N" (N" is the preset number of cache data to be cleaned, and the size can be between one-fifth and one-tenth of N3); if it is less than N", the last Q cache data in the third cache area are cleaned in order from large to small in retention value to reserve N" spaces; finally, the first Q cache data in the second cache area are migrated to the third cache area in order from large to small in retention value.

[0192] This embodiment determines the first M cache data in the first type of cache area and the first N cache data in the third type of cache area in order of retention values ​​from large to small; M and N are both integers greater than or equal to 0, and M and N are not 0 at the same time, and the sum of M and N is equal to the maximum storage space of the first type of cache area; the first N cache data are migrated from the third type of cache area to the first type of cache area; the cache data in the first type of cache area except the first M cache data are migrated from the first type of cache area to the third type of cache area; the sum of the storage space of the cache data in the first type of cache area except the first M cache data and the cache data in the third type of cache area except the first N cache data is not greater than the maximum storage space of the third type of cache area. Compared to the longest miss algorithm in the prior art, that is, if the cached data in the cache misses for more than a preset time, the cached data will be deleted from the cache to release cache space, this embodiment classifies and stores the cached data in each cache area according to the retention value of the cached data in the first cache area, the second cache area and the third cache area, and cleans up the cached data in the third cache area according to the retention value, thereby releasing cache space.

[0193] This embodiment can be applied to ordinary memory cache and other KEY-VALUE-based cache middleware. For some popular queries, this embodiment can reduce the pressure on the information system and improve the query speed. It does not need to introduce cache middleware and can directly use the memory of the application server for cache. When the memory space of the application server is limited, it can improve the utilization rate of the cache space and improve the data query efficiency.

[0194] Based on the above method embodiment, the embodiment of the present application also provides a data query device. Figure 8 This is a schematic diagram of the structure of the data query device provided in the embodiment of the present application. Figure 8 As shown, the data query device includes: a receiving module 81, a query module 82 and an output module 83; wherein the receiving module 81 is used to receive a data query request; the data query request includes a target data identifier to be queried; the query module 82 is used to perform data query in the cached data according to the target data identifier; the output module 83 is used to output the first target data if the first target data corresponding to the target data identifier is queried in the cache and the target cache area where the first target data is located is a first type of cache area; the cache data of the first type of cache area is refreshed in an asynchronous manner.

[0195] In some embodiments, the device also includes: a determination module 84; a determination module 84, which is used to determine whether the first target data is expired according to the cache validity period of the first target data if the first target data is queried in the cache and the target cache area is not a first-type cache area; an output module 83, which is also used to output the first target data if the first target data is not expired; a query module 82, which is also used to query from the database according to the target data identifier if the first target data is expired, or the data corresponding to the target data identifier is not queried in the cache, to obtain the second target data corresponding to the target data identifier, and output the second target data through the output module 83.

[0196] In some embodiments, the device further includes: an updating module 85, configured to update cache information of the first target data in the target cache area.

[0197] In some embodiments, the cache information includes: query hit count, query cost, retention value and refresh time; the query cost is used to characterize the time consumed in querying from the database, and the retention value is used to characterize the cache value; the update module 85 updates the cache information of the first target data in the target cache area, specifically including: if the target cache area is a first-class cache area, or the target cache area is not a first-class cache area, and the first target data is not expired, then the query hit count of the first target data in the target cache area is updated; or, if the target cache area is not a first-class cache area and the first target data is expired, then according to the second target data, all cache information of the first target data in the target cache area, as well as the first target data, are updated.

[0198] In some embodiments, the determination module 84 is also used to determine whether there is remaining cache space in the second type of cache area of ​​the cache; the second type of cache area is used to store data newly added to the cache; and if there is remaining cache space in the second type of cache area, the second target data and the cache information of the second target data are added to the second type of cache area.

[0199] In some embodiments, the device also includes: a refresh module 86; a receiving module 81, which is also used to receive a trigger message for cache refresh; a determination module 84, which is also used to determine whether the cache area to be refreshed during cache refresh is the first type of cache area; the refresh module 86 is used to asynchronously refresh the cache data and cache information of the cache data stored in the cache area to be refreshed if the cache area to be refreshed during cache refresh is the first type of cache area.

[0200] In some embodiments, the refresh module 86 asynchronously refreshes the cache data and cache information of the cache data stored in the cache area to be refreshed, specifically including: asynchronously querying the database to obtain new cache data; refreshing the cache data stored in the cache area to be refreshed according to the new cache data; refreshing the cache information of the cache data stored in the cache area to be refreshed according to the query information of the new cache data.

[0201] In some embodiments, the cache information includes: query hit count, query cost, retention value, and refresh time; the query cost is used to characterize the time consumed in querying from the database, and the retention value is used to characterize the cache value; the refresh module 86 refreshes the cache information of the cache data stored in the cache area to be refreshed according to the query information of the new cache data, specifically including: determining the query cost after the cache data is refreshed according to the query information of the new cache data; obtaining the retention value of the cache data after the refresh according to the query cost after the cache data is refreshed, the query hit count before the refresh, and the refresh time before the refresh; using the query cost after the cache data is refreshed to refresh the query cost of the cache data stored in the cache area to be refreshed, and using the retention value after the cache data is refreshed to refresh the retention value of the cache data stored in the cache area to be refreshed; refreshing the query hit count and refresh time of the cache data stored in the cache area to be refreshed.

[0202] In some embodiments, the device also includes an acquisition module 87, which is used to obtain the retention value of the cache data after the refresh according to the query cost, query hit number and refresh time of the cache data if the cache area to be refreshed during the cache refresh is a second-type cache area or a third-type cache area; the second-type cache area is used to store data newly added to the cache, and the third-type cache area is used to store the first Q cache data in the first-type cache area after the cache data is sorted in order from large to small according to the retention value, and Q is an integer greater than or equal to 1; the cache data of the second-type cache area and the third-type cache area are refreshed based on the cache effective time; the refresh module 86 is also used to use the retention value after the cache data is refreshed to refresh the retention value of the cache data stored in the cache area to be refreshed, and refresh the refresh time and query hit number of the cache data.

[0203] In some embodiments, the device also includes: a migration module 88; a determination module 84, which is also used to determine the first M cache data in the first type of cache area and the first N cache data in the third type of cache area in order of retention values ​​from large to small; the M and the N are both integers greater than or equal to 0, and the M and the N are not 0 at the same time, and the sum of the M and the N is equal to the maximum storage space of the first type of cache area; the migration module 88 is used to migrate the first N cache data from the third type of cache area to the first type of cache area; and to migrate the cache data in the first type of cache area except the first M cache data from the first type of cache area to the third type of cache area; the sum of the storage space of the cache data in the first type of cache area except the first M cache data and the cache data in the third type of cache area except the first N cache data is not greater than the maximum storage space of the third type of cache area.

[0204] In some embodiments, the determination module 84 is also used to determine whether the remaining storage space of the third type of cache area is less than a preset storage space threshold; the migration module 88 is also used to delete the last Q cache data in the third type of cache area in descending order of retention value if the remaining storage space of the third type of cache area is less than the preset storage space threshold; the migration module 88 is also used to migrate the first Q cache data in the second type of cache area from the second type of cache area to the third type of cache area in descending order of retention value.

[0205] The data query device provided in the embodiment of the present application can be used to execute the technical solution of the data query method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0206] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the query module 82 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the query module 82. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0207] Fig. 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig. 9 As shown, the electronic device may include: a transceiver 91 , a processor 92 , and a memory 93 .

[0208] The processor 92 executes the computer execution instructions stored in the memory, so that the processor 92 executes the scheme in the above embodiment. The processor 92 can be a general-purpose processor, including a central processing unit CPU, a network processor (NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0209] The memory 93 is connected to the processor 92 via a system bus and completes communication between them. The memory 93 is used to store computer program instructions.

[0210] The transceiver 91 may be configured to receive a data query request.

[0211] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.

[0212] The electronic device provided in the embodiment of the present application may be the application server or cache server of the above-mentioned embodiment.

[0213] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the data query method in the above embodiment.

[0214] The embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the data query method of the above embodiment.

[0215] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the data query method in the above embodiment.

[0216] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0217] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A data query method, characterized in that: include: Receiving a data query request; the data query request includes an identifier of target data to be queried; According to the target data identifier, performing data query in the cached data; If the first target data corresponding to the target data identifier is found in the cache, and the target cache area where the first target data is located is a first-type cache area, outputting the first target data; The cache data in the first type of cache area is refreshed in an asynchronous manner; If the first target data is found in the cache, the method further includes: Update cache information of the first target data in the target cache area, the cache information including query cost, query hit count, refresh time and retention value, the retention value being used to characterize cache value, the retention value after cache data is refreshed is obtained based on the query cost after cache data is refreshed, the query hit count before refresh and the refresh time before refresh, the query cost being used to characterize the time spent querying from a database, the retention value being related to the query cost, the higher the query cost, the larger the retention value, the first type of cache area being used to store cache data having a retention value greater than or equal to a preset retention value.

2. The method according to claim 1, characterized in that After performing data query in the cached data according to the target data identifier, the method further includes: If the first target data is found in the cache, and the target cache area is not a first-category cache area, determining whether the first target data is expired according to the cache validity period of the first target data; If the first target data is not expired, outputting the first target data; Alternatively, if the first target data is expired, or the data corresponding to the target data identifier is not found in the cache, the second target data corresponding to the target data identifier is queried from the database according to the target data identifier, and the second target data is output.

3. The method according to claim 2, characterized in that The updating of cache information of the first target data in the target cache area includes: If the target cache area is a first-type cache area, or if the target cache area is not a first-type cache area and the first target data is not expired, updating the query hit count of the first target data in the target cache area; Alternatively, if the target cache area is not a first-type cache area and the first target data is expired, all cache information of the first target data in the target cache area and the first target data are updated according to the second target data.

4. The method according to claim 2, characterized in that: If the data corresponding to the target data identifier is not found in the cache, then after querying from the database according to the target data identifier to obtain the second target data corresponding to the target data identifier, the method further includes: Determine whether there is remaining cache space in the second type of cache area of ​​the cache; the second type of cache area is used to store data newly added to the cache; If there is remaining cache space in the second-type cache area, the second target data and cache information of the second target data are added to the second-type cache area.

5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Receive cache refresh trigger message; Determine whether the cache area to be refreshed during cache refresh is the first type of cache area; If the cache area to be refreshed during cache refresh is the first type of cache area, the cache data and cache information of the cache data stored in the cache area to be refreshed are asynchronously refreshed.

6. The method according to claim 5, characterized in that The asynchronously refreshing the cache data and cache information of the cache data stored in the cache area to be refreshed includes: Asynchronously query the database to obtain new cache data; Refresh the cache data stored in the cache area to be refreshed according to the new cache data; According to the query information of the new cache data, the cache information of the cache data stored in the cache area to be refreshed is refreshed.

7. The method according to claim 6, characterized in that The refreshing of cache information of the cache data stored in the cache area to be refreshed according to the query information of the new cache data includes: Determine the query cost after the cache data is refreshed according to the query information of the new cache data; obtain the retention value after the cache data is refreshed according to the query cost after the cache data is refreshed, the number of query hits before the refresh, and the refresh time before the refresh; Refresh the query cost of the cached data stored in the cache area to be refreshed using the query cost after the cached data is refreshed, and refresh the retention value of the cached data stored in the cache area to be refreshed using the retention value after the cached data is refreshed; Refresh the query hit count and refresh time of the cache data stored in the cache area to be refreshed.

8. The method according to claim 7, characterized in that After determining whether the cache area to be refreshed during cache refresh is the first type of cache area, the method further includes: If the cache area to be refreshed during cache refresh is the second-category cache area or the third-category cache area, the retention value of the cache data after refreshing is obtained according to the query cost, query hit count, and refresh time of the cache data; the second-category cache area is used to store data newly added to the cache, and the third-category cache area is used to store the first Q cache data in the first-category cache area after the cache data is sorted in descending order according to the retention value, where Q is an integer greater than or equal to 1; the cache data of the second-category cache area and the third-category cache area are refreshed based on the cache validity time; The retention value after the cache data is refreshed is used to refresh the retention value of the cache data stored in the cache area to be refreshed, and the refresh time and query hit count of the cache data are refreshed.

9. The method according to claim 8, characterized in that The method further comprises: Determine the first M cache data in the first-category cache area and the first N cache data in the third-category cache area in descending order of retention values; both M and N are integers greater than or equal to 0, and M and N are not 0 at the same time, and the sum of M and N is equal to the maximum storage space of the first-category cache area; Migrating the first N cache data from the third type of cache area to the first type of cache area; The cache data except the first M cache data in the first type of cache area are migrated from the first type of cache area to the third type of cache area; the sum of the storage space of the cache data except the first M cache data in the first type of cache area and the cache data except the first N cache data in the third type of cache area is not greater than the maximum storage space of the third type of cache area.

10. The method according to claim 9, characterized in that After migrating the cache data except the first M cache data in the first cache area from the first cache area to the third cache area, the method further includes: Determining whether the remaining storage space of the third type of cache area is less than a preset storage space threshold; If the remaining storage space of the third type of cache area is less than the preset storage space threshold, the last Q cache data in the third type of cache area are deleted in descending order of retention values; The first Q cache data in the second-type cache area are migrated from the second-type cache area to the third-type cache area in the order of the retention values ​​from large to small.

11. A data query device, characterized in that: include: A receiving module, used for receiving a data query request; the data query request includes an identifier of target data to be queried; A query module, used to perform data query in the cached data according to the target data identifier; an output module, configured to output the first target data when the first target data corresponding to the target data identifier is found in the cache and the target cache area where the first target data is located is a first type of cache area; The cache data in the first type of cache area is refreshed in an asynchronous manner; An update module is used to update cache information of the first target data in the target cache area, the cache information includes query cost, query hit number, refresh time and retention value, the retention value is used to characterize the cache value, the retention value after the cache data is refreshed is obtained according to the query cost after the cache data is refreshed, the query hit number before the refresh and the refresh time before the refresh, the query cost is used to characterize the time consumed for querying from the database, the retention value is related to the query cost, the higher the query cost, the larger the retention value, the first type of cache area is used to store cache data whose retention value is greater than or equal to the preset retention value.

12. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 10.

13. 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 to 10 when executed by a processor.

14. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 10 when being executed by a processor.