A method and device for determining cache hit rate

By using Spring AOP interception technology in a production environment, generating point-cut expressions and determining cache hit rate, the risk and performance consumption of existing cache hit rate statistics methods are solved, and efficient and real-time cache hit rate monitoring and exhibit.

CN113761418BActive Publication Date: 2024-12-10BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 4 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing cache hit rate statistics method is dangerous and performant in production environments, and it is impossible to view the usage of specific caches in real time, and the encoding implementation requires repeated development and time-consuming and labor-intensive.

Method used

By receiving cache hit rate requests, querying the target system code, generating point-cut expressions, using Spring AOP for interception, determining cache hit rate based on preset logic, avoiding repeated development and reducing costs.

Benefits of technology

It realizes efficient determination of cache hit rate in a production environment, avoids duplicate development and performance consumption, can view the usage of each cache in real time, and displays the cache hit rate in a graph form, making it easier for users to view.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113761418B_ABST
    Figure CN113761418B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for determining a cache hit rate, and relates to the field of computer technology. A specific implementation of the method includes: receiving a request for determining a cache hit rate, and querying a target call cache code from a system code corresponding to a target system according to the request; generating a pointcut expression corresponding to the target call cache code, configuring the pointcut expression corresponding to the target call cache code, and obtaining configuration data corresponding to the request; in the process of running the system code, intercepting using Spring AOP according to the configuration data, and then determining the cache hit rate corresponding to the request based on a preset cache hit implementation logic. This implementation is used in a production environment, and avoids repeated development, reduces costs, improves the efficiency of determining a cache hit rate, and provides a good user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for determining a cache hit rate. Background Art

[0002] The cache is a buffer for data exchange. When data needs to be read, the required data will be searched from the cache first. If the required data is obtained through the cache, it is considered a cache hit; if the required data cannot be obtained directly through the cache, it is considered a cache miss and needs to be searched from the memory or database. Cache hit rate = number of cache hits / total number of cache requests. It is an important indicator for measuring cache performance. It is important to count and view the cache hit rate.

[0003] Currently, the following methods can be used to calculate cache hit rate statistics: 1. Use the cache's own operation and maintenance tools (commands) to view cache usage statistics, such as the number of hits and misses, and then calculate the cache hit rate; 2. Through coding, count the total number of calls using the cache and the number of database queries after the cache is penetrated, and then calculate the cache hit rate = 1-number of penetrations / total number of calls.

[0004] However, the existing cache hit rate statistics method has the following problems: First, the operation and maintenance tools that come with the cache can generally only be used in the development and testing environment, which is relatively performance-intensive and dangerous, and can only count the overall usage of the cache, but cannot view the usage of a specific cache call; Second, when implemented through coding, the code needs to be manually modified, and processes such as testing, verification, and regression are required. When it goes online, it needs to go through an approval process, which has a long cycle and is costly, and the statistics of different cache requirements require repeated development, which is time-consuming and labor-intensive. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a cache hit rate determination method and device, which can be used in a production environment, avoids repeated development, reduces costs, improves the efficiency of determining cache hit rates, and provides a better user experience.

[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for determining a cache hit rate is provided.

[0007] A method for determining a cache hit rate in an embodiment of the present invention includes: receiving a request for determining a cache hit rate, and querying a target call cache code from a system code corresponding to a target system according to the request; generating a pointcut expression corresponding to the target call cache code, configuring the pointcut expression corresponding to the target call cache code, and obtaining configuration data corresponding to the request; during the running of the system code, intercepting using SpringAOP according to the configuration data, and then determining the cache hit rate corresponding to the request based on a preset cache hit implementation logic.

[0008] Optionally, generating a pointcut expression corresponding to the target call cache code includes: based on SpringAOP expression rules, extracting the target call cache code according to package name, class name, and method name, and generating a pointcut expression corresponding to the target call cache code.

[0009] Optionally, before generating a pointcut expression corresponding to the target call cache code, the method further includes: determining whether the target call cache code includes code for counting the number of calls; if so, reconstructing the target call cache code and then generating a pointcut expression corresponding to the reconstructed code; if not, generating a pointcut expression corresponding to the target call cache code.

[0010] Optionally, the pointcut expression corresponding to the target call cache code is configured to obtain the configuration data corresponding to the request, including: configuring the pointcut expression corresponding to the target call cache code in the form of key-value to obtain the configuration data corresponding to the target call cache code, wherein the key is the unique identifier of the pointcut expression and the value is the pointcut expression; adding the configuration data corresponding to the target call cache code to the configuration data corresponding to the request.

[0011] Optionally, during the running of the system code, Spring AOP is used for interception according to the configuration data, including: during the running of the system code, the configuration data is read to obtain the pointcut expression corresponding to the target call cache code in the configuration data; according to the pointcut expression corresponding to the target call cache code, Spring AOP is used to intercept the target call cache code.

[0012] Optionally, the cache hit implementation logic based on the preset cache hit determines the cache hit rate corresponding to the request, including: obtaining a cache identifier according to the input parameter corresponding to the target call cache code; assembling the application name, class name, method name and the obtained cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code; running the target call cache code to obtain the call time and call result, and storing the statistical identifier, the call time and the call result as data; and performing statistics on the stored data according to the request to determine the cache hit rate corresponding to the request.

[0013] To achieve the above objective, according to another aspect of an embodiment of the present invention, a cache hit rate determination device is provided.

[0014] A cache hit rate determination device according to an embodiment of the present invention includes: a query module, which is used to receive a request for determining a cache hit rate, and query a target call cache code from a system code corresponding to a target system according to the request; a generation module, which is used to generate a pointcut expression corresponding to the target call cache code, configure the pointcut expression corresponding to the target call cache code, and obtain configuration data corresponding to the request; a determination module, which is used to intercept using Spring AOP according to the configuration data during the running of the system code, and then determine the cache hit rate corresponding to the request based on a preset cache hit implementation logic.

[0015] Optionally, the generation module is further used to: extract the target call cache code according to the package name, class name, and method name based on the expression rules of Spring AOP, and generate a pointcut expression corresponding to the target call cache code.

[0016] Optionally, the generation module is also used to: determine whether the target call cache code includes code for counting the number of calls; if so, reconstruct the target call cache code and then generate a pointcut expression corresponding to the reconstructed code; if not, generate a pointcut expression corresponding to the target call cache code.

[0017] Optionally, the generation module is also used to: configure the pointcut expression corresponding to the target call cache code in the form of key-value to obtain the configuration data corresponding to the target call cache code, wherein the key is the unique identifier of the pointcut expression and the value is the pointcut expression; and add the configuration data corresponding to the target call cache code to the configuration data corresponding to the request.

[0018] Optionally, the determination module is also used to: during the running of the system code, read the configuration data to obtain the pointcut expression corresponding to the target call cache code in the configuration data; and intercept the target call cache code using Spring AOP according to the pointcut expression corresponding to the target call cache code.

[0019] Optionally, the determination module is also used to: obtain a cache identifier according to the input parameters corresponding to the target call cache code; assemble the application name, class name, method name and the obtained cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code; run the target call cache code to obtain the call time and call result, and store the statistical identifier, the call time and the call result in data; perform statistics on the stored data according to the request to determine the cache hit rate corresponding to the request.

[0020] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0021] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the cache hit rate determination method according to the embodiment of the present invention.

[0022] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0023] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the cache hit rate determination method according to the embodiment of the present invention is implemented.

[0024] One embodiment of the above invention has the following advantages or beneficial effects: the target call cache code for which the cache hit rate needs to be counted can be analyzed, the cut-off expression corresponding to the target call cache code can be obtained and configured, and then during the code running process, Spring AOP is used to intercept in combination with the configuration data, and finally the cache hit rate can be determined. Therefore, the cache hit rate determination method of the embodiment of the present invention is not only used in the development and testing environment, but also in the production environment, avoiding the danger of using the cache's own operation and maintenance tools to perform cache hit rate statistics, and can also view the usage of each specific cache, and avoid repeated development, reduce costs, and improve the efficiency of determining the cache hit rate. In addition, the cache hit rate can be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days, which is convenient for users to view and has a good user experience.

[0025] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0027] Figure 1 is a schematic diagram of main steps of a method for determining a cache hit rate according to an embodiment of the present invention;

[0028] Figure 2 It is a code example for obtaining payment rules online in a certain system;

[0029] Figure 3 is a schematic diagram of a cache hit rate corresponding to a certain key obtained according to an embodiment of the present invention;

[0030] Figure 4 is a schematic diagram of a main process of obtaining configuration data corresponding to a request according to an embodiment of the present invention;

[0031] Figure 5 It is a main schematic diagram of the main process of intercepting using Spring AOP to obtain cache hit rate according to an embodiment of the present invention;

[0032] Figure 6 is a schematic diagram of main modules of a cache hit rate determination device according to an embodiment of the present invention;

[0033] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0034] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0036] At present, the method of using built-in operation and maintenance tools to perform cache hit rate statistics can generally only be used in development and testing environments, is relatively performance-intensive, and has certain risks. Taking the commonly used key command as an example, the key command is very convenient to use in the development and testing environment, but when the production environment has a large amount of data and a large number of data, the key command is time-consuming, causing the server CPU to increase sharply. In addition, when executing key commands with high time complexity, other commands will be blocked, which may cause cache avalanche in production. In this way, a large number of requests are all hit on the memory or database, causing the memory or database to be overwhelmed, causing the entire system to crash. In addition, this method can only count the overall usage of the cache, and cannot view the usage of a specific cache.

[0037] In addition, the method of performing cache hit rate statistics through coding requires manual code modification (that is, when there is a need to count the cache hit rate, it is necessary to embed points in the code here to assist in counting the number of calls), and requires testing, verification, regression and other processes. When going online, it is necessary to go through the approval process, which has a long cycle and consumes costs. In addition, the statistical requirements of different caches require repeated development, which is time-consuming and labor-intensive. In addition, using the built-in operation and maintenance tools and the method of performing cache hit rate statistics through coding can only view the cache hit rate at a certain moment, and cannot be counted and viewed over a continuous period of time, which is not convenient for analysis.

[0038] To solve the above problem, an embodiment of the present invention provides a method for determining a cache hit rate. Figure 1 Schematic diagram of the main steps of the method for determining cache hit rate according to an embodiment of the present invention. As an embodiment of the present invention, Figure 1 As shown, the main steps of the cache hit rate determination method may include steps S101 to S103.

[0039] Step S101: receiving a request for determining a cache hit rate, and querying a target call cache code from a system code corresponding to a target system according to the request.

[0040] Among them, the request to determine the cache hit rate refers to the need to perform cache hit rate statistics in the system. Obviously, the target system is a system that needs to perform cache hit rate statistics. For a system, there are multiple cache calls. According to the received request, it can be obtained which cache calls of the target system need to perform hit rate statistics. After receiving the request, the target call cache code can be queried from the system code corresponding to the target system, that is, the code corresponding to the cache call that needs to be counted for the cache hit rate can be queried from all the codes corresponding to the target system. Figure 2 This is a code example of a system that obtains payment rules online. Figure 2 In the figure, the code in the box is the cache calling code, and the code does not implement the statistics of cache hit rate.

[0041] Step S102: Generate a pointcut expression corresponding to the target call cache code, configure the pointcut expression corresponding to the target call cache code, and obtain configuration data corresponding to the request.

[0042] After the target cache call code is found, a pointcut expression corresponding to the target cache call code can be generated. The pointcut expression is equivalent to navigation software, and the location of the target cache call code can be located through the pointcut expression.

[0043] Furthermore, generating a pointcut expression corresponding to the target call cache code may include: extracting the target call cache code according to the package name, class name, and method name based on the expression rule of Spring AOP, and generating a pointcut expression corresponding to the target call cache code. Among them, Spring is an open source design-level framework that solves the problem of loose coupling between the business logic layer and other layers, and it can apply interface-oriented programming ideas throughout the entire system application. AOP provides another angle for thinking about the structure of the program for aspect-oriented programming, which makes up for the shortcomings of object-oriented programming. Spring AOP is an important component of Spring, which can be used to implement log monitoring, transaction management, permission control, etc. In other words, Spring AOP is a programming technology that can cut into specified classes and methods during program compilation and runtime, and can dynamically add some additional functions.

[0044] The expression rule of Spring AOP can be: execution(<modifier pattern>?<return type pattern><method name pattern>(<parameter pattern>)<exception pattern>?). Among them, execution() is the expression body, and the part with "?" can be omitted, that is, the modifier pattern and exception pattern can be omitted, that is, the return type pattern, method name pattern and parameter pattern are necessary. Figure 2 Take the target cache call code in as an example, the package name is: com.jd.jmi.pay.cache, the class name is: JmiPayRuleCache, the method name is: getRuleFromCache, and the final cut-off expression is: execution(*com.jd.jmi.pay.cache.JmiPayRuleCache.getRuleFromCache(..)). The first * in the cut-off expression indicates the return type, and the * indicates all types; the last bracket (..) indicates the method parameters, and two periods indicate any parameters.

[0045] After obtaining the pointcut expression corresponding to the target call cache code, the obtained pointcut expression can be configured to obtain the configuration data corresponding to the request. It should be noted that the obtained configuration data can be in a configuration file or a database.

[0046] Further, configuring the pointcut expression corresponding to the target call cache code to obtain configuration data corresponding to the request may include: configuring the pointcut expression corresponding to the target call cache code in the form of key-value to obtain configuration data corresponding to the target call cache code, wherein key is the unique identifier of the pointcut expression and value is the pointcut expression; adding the configuration data corresponding to the target call cache code to the configuration data corresponding to the request.

[0047] It is worth noting that the number of target call cache codes is one or more. Therefore, it is necessary to query one or more target call cache codes; then extract and analyze each target call cache code to generate the pointcut expression corresponding to each target call cache code; then configure the pointcut expression corresponding to each target call cache code to obtain the configuration data corresponding to each target call cache code; finally, through the configuration data corresponding to each target call cache code, the configuration data corresponding to the request is obtained.

[0048] On the other hand, before analyzing each target call cache code and obtaining the configuration data corresponding to the target call cache code, it is necessary to determine whether the configuration data corresponding to the request includes the configuration data corresponding to the target call cache code. If so, there is no need to analyze the target call cache code; if not, analyze the target call cache code to obtain the configuration data corresponding to the target call cache code, and then add the configuration data to the configuration data corresponding to the request. In addition, it should be noted that if the configuration data corresponding to the request includes configuration data corresponding to other cache call codes (i.e., cache call codes other than the target cache call code), then the configuration data corresponding to the other cache call codes need to be deleted from the configuration data corresponding to the request.

[0049] Step S103: During the running of the system code, Spring AOP is used to intercept according to the configuration data, and then the cache hit rate corresponding to the request is determined based on the preset cache hit implementation logic.

[0050] As explained in step S102, Spring AOP is a programming technology that can cut into specified classes and methods during program compilation and operation, and can dynamically add some additional functions. In addition, the pointcut expression corresponding to the target cache call code can be obtained through the configuration data. Therefore, during the operation of the system code, Spring AOP can be used to intercept in combination with the configuration data, that is, to intercept the operation of the target cache call code.

[0051] Therefore, as another embodiment of the present invention, during the running of the system code, intercepting using Spring AOP according to the configuration data may include: during the running of the system code, reading the configuration data, obtaining the pointcut expression corresponding to the target call cache code in the configuration data; intercepting the target call cache code according to the pointcut expression corresponding to the target call cache code using Spring AOP.

[0052] Specifically, the pointcut expression corresponding to the target call cache code in the configuration data is read, and the target call cache code is intercepted using SpringAOP, so that during the system code running process, it can dynamically cut in and trace back to the location of the target call cache code corresponding to the pointcut expression. Then, the preset cache hit implementation logic can be dynamically added before and after the target call cache code is executed to achieve the purpose of enhancing the code function.

[0053] On the other hand, the preset cache hit implementation logic is a specific logic for counting the cache hit rate corresponding to the request. Specifically, based on the preset cache hit implementation logic, determining the cache hit rate corresponding to the request may include:

[0054] (1) Get the cache identifier based on the input parameters corresponding to the target call cache code. After using Spring AOP to intercept the target call cache code, you can get the cache identifier based on the input parameters in the target call cache code, such as Figure 2 The target cache calls the key in the code.

[0055] (2) Assemble the application name, class name, method name and cache identifier corresponding to the target call cache code to obtain the statistical identifier corresponding to the target call cache code. The keys in different cache call codes may be the same. For example, if you need to obtain data in order table B, the payment process and warehousing process in the system both need to call order table B, and the keys in the corresponding cache call codes are all order table identifiers of order table B. Therefore, in order to prevent duplication, it is necessary to assemble the application name, class name, method name and cache identifier corresponding to the target call cache code to obtain a new key, named the statistical identifier, so that the cache hit rate can be counted according to the statistical identifier. On the other hand, when analyzing the target call cache code, some coupled codes are separated. If the key in the cache call code is used, it will take a long time to locate the target cache call code corresponding to the key. However, the statistical identifier contains the application name, class name, and method name, so the target cache call code can be directly located, reducing the location time and further improving the efficiency of determining the cache hit rate.

[0056] (3) Run the target call cache code, obtain the call time and call result, and store the statistical identifier, call time and call result. If the call result is empty, it can be recorded as false, confirming that the required data cannot be obtained directly through the cache; if the call result is not empty, it can be recorded as true, confirming that the required data can be obtained directly through the cache. Then, the statistical identifier, call time, and call result (true / false) can be assembled into the following data: {Statistical identifier: [call time, true / false]}, and the assembled data can be stored.

[0057] (4) Perform statistics on the stored data according to the request to determine the cache hit rate corresponding to the request. In addition, the received request may include the specific statistical time and the display format of the cache hit rate. Therefore, after storing the statistical identifier, call time and call result corresponding to the target call cache code, the cache hit rate can be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days. Figure 3 is a schematic diagram of the cache hit rate corresponding to a certain key obtained according to an embodiment of the present invention. It should be noted that the certain key here refers to a statistical identifier. Figure 3 It can be seen that the cache hit rate is counted with the data granularity of hours. Figure 3 The figure shows the cache hit rate corresponding to a key from September 2 to September 5, and the highest cache hit rate is: [2020-09-02 21:00:00, 98.2%], and the lowest cache hit rate is: [2020-09-01 01:00:00, 89.2%].

[0058] In addition, as an embodiment of the present invention, before generating the pointcut expression corresponding to the target call cache code, the cache hit rate determination method may further include: determining whether the target call cache code includes code for counting the number of calls; if so, reconstructing the target call cache code and then generating a pointcut expression corresponding to the reconstructed code; if not, generating a pointcut expression corresponding to the target call cache code. The target call cache code may include the following two scenarios:

[0059] Scenario 1: The target call cache code has been modified in a coded way. That is, in order to count the total number of calls using the cache and the number of database queries after cache breakdown, the call cache code has been manually modified, so that the cache hit rate can be calculated as 1-breakdown times / total number of calls. However, the method of calculating the cache hit rate by coding is not conducive to viewing the cache hit situation within a certain continuous period of time, and also has the problems of poor maintainability and poor scalability. Therefore, it is necessary to reconstruct the manually modified call cache code, that is, if the target call cache code includes code for counting the number of calls, then the target call cache code needs to be reconstructed, and then the reconstructed code is analyzed to generate its corresponding point-cut expression.

[0060] Scenario 2: The target call cache code is not modified. In this scenario, if the cache hit rate corresponding to the target call cache code needs to be counted, it can be regarded as a new requirement, so the target call cache code can be directly analyzed to generate its corresponding cut-off expression.

[0061] According to the cache hit rate determination method of the embodiment of the present invention, the target call cache code for which the cache hit rate needs to be counted can be analyzed, the cut-off expression corresponding to the target call cache code can be obtained and configured, and then in the process of code running, Spring AOP is used to intercept in combination with the configuration data, and finally the cache hit rate can be determined. Therefore, the cache hit rate determination method of the embodiment of the present invention is not only used in the development and testing environment, but also in the production environment, avoiding the danger of using the cache's own operation and maintenance tools to perform cache hit rate statistics, and can also view the usage of each specific cache, and avoid repeated development, reduce costs, and improve the efficiency of determining the cache hit rate. In addition, the cache hit rate can also be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days, which is convenient for users to view and has a good user experience.

[0062] The technical solution for determining the cache hit rate in the embodiment of the present invention mainly includes obtaining the configuration data corresponding to the request and using Spring AOP to intercept to obtain the cache hit rate. Figure 4 and Figure 5These two parts are explained in detail.

[0063] Figure 4 FIG. 1 is a schematic diagram of the main process of obtaining configuration data corresponding to a request according to an embodiment of the present invention. Figure 4 As shown, the main process of obtaining the configuration data corresponding to the request may include:

[0064] Step S401, receiving a request for determining a cache hit rate, and querying one or more target call cache codes from the system code corresponding to the target system according to the request;

[0065] Step S402, selecting a target calling code from the one or more target calling cache codes found;

[0066] Step S403, determining whether the selected target call cache code includes a code for counting the number of calls, if so, executing step S404, if not, executing step S405;

[0067] Step S404, reconstructing the selected target call cache code, and updating the reconstructed code to be the selected target call cache code;

[0068] Step S405, determining whether the configuration data corresponding to the request includes the configuration data corresponding to the selected target call cache code, if so, executing step S409, if not, executing step S406;

[0069] Step S406, based on the expression rules of Spring AOP, extract the selected target call cache code according to the package name, class name, and method name, and generate a pointcut expression corresponding to the selected target call cache code;

[0070] Step S407, configuring the pointcut expression corresponding to the selected target call cache code in the form of key-value, to obtain configuration data corresponding to the selected target call cache code, wherein key is the unique identifier of the pointcut expression, and value is the pointcut expression;

[0071] Step S408, adding the configuration data corresponding to the selected target call cache code to the configuration data corresponding to the request;

[0072] Step S409, determining whether the configuration data corresponding to each target calling code queried is obtained, if so, executing step S410, if not, executing step S402;

[0073] Step S410, deleting configuration data corresponding to other calling cache codes from the configuration data corresponding to the request, and finally obtaining the configuration data corresponding to the request.

[0074] It is worth noting that the selection of a target call code from one or more target call cache codes queried in step S402 may be performed in accordance with the execution order of the code, and of course may also be performed in other orders, which is not limited in the embodiment of the present invention. In addition, the other call cache codes in step 410 refer to cache call codes other than the target cache call code. In addition, the execution order of deleting the configuration data corresponding to the other call cache codes from the configuration data corresponding to the request in step 410 may be adjusted according to actual conditions, as long as it is executed before the configuration data corresponding to the request is finally obtained. In addition, in the process of generating the configuration data corresponding to each target cache call code, if the target call cache code includes a code for counting the number of calls, it can be explained that the target call cache code has not been analyzed, that is, the configuration data corresponding to the request does not include the configuration data corresponding to the target call cache code.

[0075] Figure 5 FIG. 1 is a schematic diagram of the main process of using Spring AOP to intercept and obtain cache hit rate according to an embodiment of the present invention. Figure 5 As shown, the main process of using Spring AOP to intercept and obtain cache hit rate can include:

[0076] Step S501, during the execution of the system code, read the configuration data corresponding to the request, and obtain the pointcut expression corresponding to the target call cache code in the configuration data;

[0077] Step S502, using Spring AOP to intercept the target call cache code according to the pointcut expression corresponding to the target call cache code;

[0078] Step S503, obtaining a cache identifier according to the input parameter corresponding to the target calling cache code;

[0079] Step S504, assembling the application name, class name, method name and the acquired cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code;

[0080] Step S505, running the target call cache code, obtaining the call time and the call result, and storing the statistical identifier, the call time and the call result corresponding to the target call cache code;

[0081] Step S506: statistics are collected on the stored data according to the request to determine the cache hit rate corresponding to the request.

[0082] The request may include specific statistical time and cache hit rate display format. Therefore, after storing the statistical identifier, call time and call result corresponding to the target call cache code, the cache hit rate can be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days.

[0083] Figure 6 Schematic diagram of main modules of a cache hit rate determination device according to an embodiment of the present invention. Figure 6 As shown, the cache hit rate determination device 600 according to the embodiment of the present invention may include: a query module 601 , a generation module 602 , and a determination module 603 .

[0084] Among them, the query module 601 can be used to: receive a request for determining a cache hit rate, and query the target call cache code from the system code corresponding to the target system according to the request; the generation module 602 can be used to: generate a pointcut expression corresponding to the target call cache code, configure the pointcut expression corresponding to the target call cache code, and obtain the configuration data corresponding to the request; the determination module 603 can be used to: during the running process of the system code, intercept using Spring AOP according to the configuration data, and then determine the cache hit rate corresponding to the request based on the preset cache hit implementation logic.

[0085] As an embodiment of the present invention, the generation module 602 can also be used to extract the target call cache code according to the package name, class name, and method name based on the expression rules of Spring AOP, and generate a pointcut expression corresponding to the target call cache code.

[0086] As an embodiment of the present invention, the generation module 602 can also be used to: determine whether the target call cache code includes code for counting the number of calls; if so, reconstruct the target call cache code and then generate a pointcut expression corresponding to the reconstructed code; if not, generate a pointcut expression corresponding to the target call cache code.

[0087] As an embodiment of the present invention, the generation module 602 can also be used to: configure the pointcut expression corresponding to the target call cache code in the form of Key-value to obtain the configuration data corresponding to the target call cache code, wherein the Key is the unique identifier of the pointcut expression and the value is the pointcut expression; and add the configuration data corresponding to the target call cache code to the configuration data corresponding to the request.

[0088] As an embodiment of the present invention, the determination module 603 can also be used to: during the running process of the system code, read the configuration data to obtain the pointcut expression corresponding to the target call cache code in the configuration data; according to the pointcut expression corresponding to the target call cache code, use Spring AOP to intercept the target call cache code.

[0089] As an embodiment of the present invention, the determination module 603 can also be used to: obtain a cache identifier according to the input parameters corresponding to the target call cache code; assemble the application name, class name, method name and the obtained cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code; run the target call cache code to obtain the call time and call result, and store the statistical identifier, call time and call result as data; perform statistics on the stored data according to the request to determine the cache hit rate corresponding to the request.

[0090] According to the cache hit rate determination device of the embodiment of the present invention, it is possible to analyze the target call cache code for which the cache hit rate needs to be counted, obtain the pointcut expression corresponding to the target call cache code and configure it, and then in the process of code running, combine the configuration data, use Spring AOP to intercept, and finally determine the cache hit rate. Therefore, the cache hit rate determination method of the embodiment of the present invention is not only used in the development and testing environment, but also in the production environment, avoiding the danger of using the cache's own operation and maintenance tools to perform cache hit rate statistics, and can also view the usage of each specific cache, and avoid repeated development, reduce costs, and improve the efficiency of determining the cache hit rate. In addition, the cache hit rate can also be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days, which is convenient for users to view and has a good user experience.

[0091] Figure 7 An exemplary system architecture 700 is shown to which the cache hit rate determination method or cache hit rate determination apparatus according to the embodiment of the present invention can be applied.

[0092] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0093] Users can use terminal devices 701, 702, 703 to interact with server 705 through network 704 to receive or send messages, etc. Terminal devices 701, 702, 703 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, etc.

[0094] Server 705 may be a server that provides various services, such as a background management server that provides support when a user uses terminal devices 701, 702, and 703 to determine a cache hit rate (only as an example); for another example, server 705 may complete the cache hit rate determination of an embodiment of the present invention.

[0095] It should be noted that the cache hit rate determination method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the cache hit rate determination device is generally disposed in the server 705 .

[0096] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0097] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0098] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0099] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0100] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.

[0101] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0102] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0103] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, they may be described as: a processor includes a query module, a generation module and a determination module. The names of these modules do not constitute a limitation on the modules themselves in some cases. For example, the query module may also be described as "receiving a request to determine a cache hit rate, and querying a module for a target calling cache code from the system code corresponding to the target system according to the request".

[0104] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving a request to determine a cache hit rate, and querying the target call cache code from the system code corresponding to the target system according to the request; generating a pointcut expression corresponding to the target call cache code, configuring the pointcut expression corresponding to the target call cache code, and obtaining configuration data corresponding to the request; in the process of running the system code, intercepting using Spring AOP according to the configuration data, and then determining the cache hit rate corresponding to the request based on the preset cache hit implementation logic.

[0105] According to the technical solution of the embodiment of the present invention, it is possible to analyze the target call cache code that needs to count the cache hit rate, obtain the pointcut expression corresponding to the target call cache code and configure it, and then in the process of code running, combine the configuration data, use Spring AOP to intercept, and finally determine the cache hit rate. Therefore, the cache hit rate determination method of the embodiment of the present invention is not only used in the development and testing environment, but also in the production environment, avoiding the danger of using the cache's own operation and maintenance tools to perform cache hit rate statistics, and can also view the usage of each specific cache, and avoid repeated development, reduce costs, and improve the efficiency of determining the cache hit rate. In addition, the cache hit rate can also be displayed in the form of a chart according to the time dimension of seconds, minutes, hours or days, which is convenient for users to view and has a good user experience.

[0106] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for determining a cache hit rate, characterized in that: include: receiving a request to determine a cache hit rate, and querying a target call cache code from a system code corresponding to a target system according to the request; Generate a pointcut expression corresponding to the target call cache code, configure the pointcut expression corresponding to the target call cache code, and obtain configuration data corresponding to the request; During the running process of the system code, Spring AOP is used to intercept according to the configuration data, and then the cache hit rate corresponding to the request is determined based on the preset cache hit implementation logic, including: obtaining a cache identifier according to the input parameter corresponding to the target call cache code; assembling the application name, class name, method name and the obtained cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code; running the target call cache code to obtain the call time and call result, and storing the statistical identifier, the call time and the call result in data; and performing statistics on the stored data according to the request to determine the cache hit rate corresponding to the request.

2. The method according to claim 1, characterized in that: The generating of the pointcut expression corresponding to the target call cache code includes: Based on the expression rules of Spring AOP, the target call cache code is extracted according to the package name, class name, and method name, and a pointcut expression corresponding to the target call cache code is generated.

3. The method according to claim 1 or 2, characterized in that: Before generating the pointcut expression corresponding to the target call cache code, the method further includes: Determine whether the target call cache code includes a code for counting the number of calls; If yes, reconstruct the target call cache code, and then generate a pointcut expression corresponding to the reconstructed code; If not, a pointcut expression corresponding to the target call cache code is generated.

4. The method according to claim 3, characterized in that The configuring the pointcut expression corresponding to the target call cache code to obtain configuration data corresponding to the request includes: The pointcut expression corresponding to the target call cache code is configured in the form of key-value to obtain configuration data corresponding to the target call cache code, wherein the key is the unique identifier of the pointcut expression and the value is the pointcut expression; The configuration data corresponding to the target call cache code is added to the configuration data corresponding to the request.

5. The method according to claim 1, characterized in that During the operation of the system code, interception is performed using Spring AOP according to the configuration data, including: During the running of the system code, the configuration data is read to obtain a pointcut expression corresponding to the target call cache code in the configuration data; According to the pointcut expression corresponding to the target calling cache code, Spring AOP is used to intercept the target calling cache code.

6. A cache hit rate determination device, characterized in that: include: A query module, configured to receive a request for determining a cache hit rate, and query a target call cache code from a system code corresponding to a target system according to the request; A generation module, used to generate a pointcut expression corresponding to the target call cache code, configure the pointcut expression corresponding to the target call cache code, and obtain configuration data corresponding to the request; A determination module is used to intercept using Spring AOP according to the configuration data during the running of the system code, and then determine the cache hit rate corresponding to the request based on the preset cache hit implementation logic, including: obtaining a cache identifier according to the input parameter corresponding to the target call cache code; assembling the application name, class name, method name and the obtained cache identifier corresponding to the target call cache code to obtain a statistical identifier corresponding to the target call cache code; running the target call cache code to obtain the call time and call result, and storing the statistical identifier, the call time and the call result as data; and performing statistics on the stored data according to the request to determine the cache hit rate corresponding to the request.

7. The device according to claim 6, characterized in that The generation module is also used for: Based on the expression rules of Spring AOP, the target call cache code is extracted according to the package name, class name, and method name, and a pointcut expression corresponding to the target call cache code is generated.

8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Annotation-based local cache realization method, storage device and electronic device

    CN107463378A

  • Cache hit ratio determination method, apparatus, device, and readable storage medium

    CN109388550A

  • Simulation test method, client, server, system and readable storage medium

    CN111708702A

  • Detecting vulnerabilities associated with a software application build

    US10691810B1