Cache dynamic closing method and system, electronic equipment and medium

By dynamically intervening in cached data, instead of reading cached data under specified conditions, the interface logic is directly executed, which solves the problem of inefficient testing caused by untimely update of cached data and improves testing efficiency.

CN120029932APending Publication Date: 2025-05-23CHINA UNITED NETWORK COMM GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510125564.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-26
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

In daily testing, cached data cannot be updated in time, resulting in inefficient testing, especially when there are many test cases in query classes, query tests can only be performed once every half hour.

Method used

Provides a dynamic cache shutdown method and system, which performs conditional configuration of methods that require the cache intervention function to be enabled, and performs cache intervention when the specified conditions meet, and does not read cache data, but executes the logic of the interface method.

Benefits of technology

This makes the data saved in the memory-based cache only read when the specified conditions meet, and dynamically interferes with the cache reading, thereby improving testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120029932A_ABST
    Figure CN120029932A_ABST
Patent Text Reader

Abstract

The invention provides a cache dynamic closing method and system, electronic equipment and a storage medium, and aims to solve the problem of low test efficiency caused by the fact that cache data is not updated in time. The method comprises the following steps: determining a to-be-tested target application and a corresponding method thereof; condition configuration is carried out on the method needing to start the cache intervention function, and whether the cache intervention function is started or not is determined; monitoring is mounted on the target application to monitor all methods in the application, and a cache intervention function is started for the methods needing cache intervention; and testing the target application, and executing monitoring logic when calling a certain corresponding method, namely judging whether cache intervention is started or not, if so, judging whether a corresponding condition meets all conditions in the condition configuration or not, and if so, executing cache intervention and not reading cache data. According to the method and the device, the cached data can be read only when the specified condition is met, so that the test efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the technical field of data cache, and in particular to a cache dynamic closing method, a cache dynamic closing system, an electronic device and a computer-readable storage medium. Background Art

[0002] In enterprise development, caching technology is often used to improve program processing performance. Caching refers to temporarily storing data in memory so that when an application reads a certain data, the data is read from memory, so the reading speed is very fast, thereby improving the processing performance of the application. Caching technology is usually used when the query interface is called. When the query interface is executed, it will first try to read the data from the cache. If it cannot be read, the actual logic of the interface will be executed to obtain the data. An example of a scenario where caching technology is used, such as Figure 1 As shown, the user initiates a query request from the client to the application. The application calls the interface method and executes the query logic. At this time, it attempts to read the queried data from the cache. If the data exists in the cache, it is directly returned to the application (the logic of the interface will not be executed). If there is no data in the cache, the logic of the interface is then executed, and the relevant data is read from the database. After business processing, the final result is returned to the application and saved in the cache for use in the next query.

[0003] Caching technology is usually divided into two categories. One is distributed cache (such as redis). This type of cache generally provides a visual operation interface to view and modify the data in the cache. The other is memory-based cache (such as Ehcache, Caffeine). This type of cache can only be read and modified in the code (that is, when the application is running), and cannot be viewed and modified in real time through the operation interface. The use of cache may cause data lag. That is, if the data in the cache cannot be updated in time, the user will get the wrong content every time he queries. In daily testing, if the cached data cannot be updated in time, it will also bring difficulties to the testing work. Figure 1 For example, assuming that the expiration time of the cached data is half an hour, then within this half hour, if the data in the database changes (causing the data returned after the interface logic processing to change), the tester will have to wait for half an hour if he wants to get the correct interface return content during the test. This makes the test efficiency very low, especially when there are many query test cases, and only one query test can be performed every half an hour, so the test efficiency is very poor. Summary of the invention

[0004] In order to at least solve the problem in the prior art that cache data cannot be updated in time during daily testing and needs to wait, resulting in low test efficiency, the present disclosure provides a cache dynamic closing method, a cache dynamic closing system, an electronic device, and a computer-readable storage medium; the data stored in the memory-based cache is read only when the specified conditions are met, thereby helping testers improve test efficiency.

[0005] In a first aspect, the present disclosure provides a method for dynamically closing a cache, the method comprising:

[0006] Determine the target application to be tested and its corresponding method;

[0007] Conditionally configure the method that needs to enable the cache intervention function, and determine whether to enable the cache intervention function;

[0008] Mount a monitor on the target application to monitor all methods in the application and enable cache intervention for methods that require cache intervention.

[0009] Test the target application and execute the monitoring logic when calling a corresponding method, including: judging whether the cache intervention function is enabled. If it is enabled, judging whether the conditions corresponding to the method meet all the conditions in the condition configuration. If so, cache intervention is performed without reading cache data, but executing the logic of the interface method and returning the processed content.

[0010] Furthermore, the method further comprises:

[0011] After the test is completed, delete the conditional configuration of the method or turn off the cache intervention function and change the status of the conditional configuration to closed to remove the cache intervention.

[0012] Furthermore, the method further comprises:

[0013] Enter the target application name to be tested and its corresponding method name information on the first page. After entering the information, a list is generated on the second page to display all the input target application names and corresponding method names. The second page also displays whether the cache intervention function is enabled for each method, and the edit button on the second page allows you to edit the conditional configuration information of each method on the third page.

[0014] Furthermore, the determination of whether the cache intervention function is enabled, if enabled, then determining whether the conditions corresponding to the method meet all conditions in the condition configuration, includes:

[0015] Determine whether the current method is a method in the list on the second page and whether the cache intervention function is enabled;

[0016] If yes, set a variable flag with an initial value of true, read the condition configuration of the method, traverse each line of the condition configuration, obtain the parameter value of the method parameter position configured by the current condition, compare the parameter value with the value configured by the current condition, and if they are inconsistent, assign the variable flag to false;

[0017] Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal;

[0018] After the traversal is completed, it is determined whether the value of flag is true. If it is true, it is determined that the condition corresponding to the method meets all the conditions in the condition configuration.

[0019] Furthermore, the cache intervention is performed without reading cache data, but the logic of the interface method is executed and the processed content is returned, including:

[0020] Use reflection to get the Method object of the current method;

[0021] Execute the method object to determine whether there is this annotation method on the judgment class to determine whether the current method is annotated with @Cacheable;

[0022] If so, use reflection to invalidate cached reads, including:

[0023] Get the @Cacheable annotation object that applies to the current method through the Method object;

[0024] Then get the class object of the annotation object;

[0025] Get the Field object of the condition attribute of the Cacheable object through this class object;

[0026] Execute the set method of the Field object to assign a value of false to the condition property, thereby turning off the cache reading function of the method so that each time the method is called, the data stored in the cache will not be read, and the logic of the interface method will be executed.

[0027] In a second aspect, the present disclosure provides a cache dynamic closing system, the system comprising:

[0028] A determination module configured to determine a target application to be tested and a corresponding method thereof;

[0029] A configuration module, which is configured to conditionally configure the method that needs to enable the cache intervention function and determine whether to enable the cache intervention function;

[0030] A monitoring module is configured to mount a monitor on the target application to monitor all methods in the application and enable cache intervention for methods that require cache intervention;

[0031] The cache intervention module is configured to test the target application and execute the monitoring logic when calling a corresponding method, including: determining whether the cache intervention function is enabled; if enabled, determining whether the conditions corresponding to the method meet all the conditions in the condition configuration; if satisfied, executing cache intervention without reading cache data, executing the logic of the interface method and returning the processed content.

[0032] Furthermore, the system also includes:

[0033] The release module is configured to release cache intervention by deleting the conditional configuration of the method or turning off the cache intervention function after the test is completed, and changing the state of the conditional configuration to off.

[0034] Furthermore, the system also includes a display module;

[0035] The display module is configured to input the target application name to be tested and its corresponding method name information through the first page. After the information is input, a list is generated on the second page to display all the input target application names and corresponding method names, and whether the cache intervention function is enabled for each method is displayed on the second page, and the conditional configuration information of each method can be edited on the third page through the edit button on the second page.

[0036] In a third aspect, the present disclosure provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor runs the computer program stored in the memory, the processor executes the cache dynamic closing method as described in any one of the first aspects.

[0037] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the cache dynamic closing method described in any one of the above-mentioned first aspects is implemented.

[0038] Beneficial effects:

[0039] The present invention provides a cache dynamic closing method, a cache dynamic closing system, an electronic device and a storage medium. By conditionally configuring the method that needs to enable the cache intervention function, each method is monitored so that the data stored in the memory-based cache is only read when the specified conditions are met, and the cache reading is dynamically intervened, thereby helping testers improve test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1A schematic diagram showing an example scenario of using caching technology;

[0041] Figure 2 A schematic diagram of a process flow of a cache dynamic closing method provided in Embodiment 1 of the present disclosure;

[0042] Figure 3 A schematic diagram of a first page provided in an embodiment of the present disclosure;

[0043] Figure 4 A schematic diagram of a second page provided in an embodiment of the present disclosure;

[0044] Figure 5 A schematic diagram of a third page provided in an embodiment of the present disclosure;

[0045] Figure 6 A schematic diagram of a code of a monitoring processing logic provided in the second embodiment of the present disclosure;

[0046] Figure 7 This is an architecture diagram of a cache dynamic shutdown system provided in Embodiment 3 of the present disclosure;

[0047] Figure 8 This is an architecture diagram of an electronic device provided in Embodiment 4 of the present disclosure. DETAILED DESCRIPTION

[0048] In order to enable those skilled in the art to better understand the technical solution of the present disclosure, the present disclosure is further described in detail below in conjunction with the drawings and embodiments. It should be understood that the specific embodiments and drawings described herein are only used to explain the present invention, rather than to limit the present invention.

[0049] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence; and, in the absence of conflict, the embodiments in the present disclosure and the features in the embodiments can be arbitrarily combined with each other.

[0050] The terms used in the embodiments of the present disclosure are only for the purpose of describing specific embodiments and are not intended to limit the present disclosure. The singular forms of "a", "said" and "the" used in the embodiments of the present disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings.

[0051] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present disclosure, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.

[0052] If the data in the database changes (which causes the returned data after the interface logic processing to change), the tester will have to wait half an hour to get the correct interface return content during the test, resulting in very low test efficiency, especially when there are many query test cases, and only one query test can be performed every half an hour, which makes the test efficiency very poor. For this problem, if the cache technology uses a distributed cache (such as redis), the tester can delete the cached data in the cache client (such as the redis client) to avoid it, but if the cache technology uses a memory cache, the tester cannot delete the cache.

[0053] The technical solution of the present invention and how the technical solution of the present invention solves the technical problems existing in the prior art are described in detail below with specific embodiments. It is understandable that in the embodiments of the present application, the execution subject can perform some or all of the steps in the embodiments of the present application, and these steps or operations are only examples. The embodiments of the present application can also perform other operations or deformations of various operations. In addition, each step can be performed in a different order presented in the embodiments of the present application, and it is possible not to perform all the operations in the embodiments of the present application. And, the following several specific embodiments can be combined with each other, and may not be repeated in some embodiments for the same or similar concepts or processes.

[0054] Figure 2 A schematic diagram of a process for dynamically closing a cache provided in the first embodiment of the present disclosure, such as Figure 2 As shown, the method includes:

[0055] Step S101: Determine the target application to be tested and its corresponding method;

[0056] Step S102: Conditionally configure the method that needs to enable the cache intervention function, and determine whether to enable the cache intervention function;

[0057] Step S103: Mount a monitor on the target application to monitor all methods in the application, and enable a cache intervention function for methods that require cache intervention;

[0058] Step S104: Test the target application and execute the monitoring logic when calling a corresponding method, including: determining whether the cache intervention function is enabled. If enabled, determining whether the conditions corresponding to the method meet all the conditions in the condition configuration. If so, cache intervention is executed without reading the cached data. Instead, the logic of the interface method is executed and the processed content is returned.

[0059] The embodiments of the present disclosure are directed to a memory-based caching method. Since this type of cache can only be read and modified in the code (i.e., when the application is running), and cannot be viewed and modified in real time through the operation interface, when the cached data cannot be updated in time, the cache function is generally removed at the code level; in daily testing, in order to test the code, the code needs to be kept unchanged. Therefore, the purpose of the embodiments of the present disclosure is to keep the code in its original state so that the data stored in the memory-based cache will only be read when the specified conditions are met, thereby helping testers improve testing efficiency.

[0060] Specifically, first determine the target application to be tested and its corresponding method; the target application refers to the application to which the interface under test belongs, and the method corresponding to the target application refers to the method that triggers the read-write cache during the execution of the interface under test when the tester initiates a request to the interface under test; it should be noted that the interface method under test itself does not necessarily trigger the read-write cache, and usually a sub-method (usually the query function method) in its execution process will trigger the read-write cache. For the methods that need to enable the cache intervention function, conditional configuration is performed, and it is determined whether to enable the cache intervention function. For the newly added configuration, its status is closed by default; only the method represented by the configuration with the status turned on will trigger the intervention of the cache function when it is called; mount a monitor on the target application to monitor all methods in the application. Specifically, when the tester starts testing, a request will be triggered to service A (provided in this embodiment), and service A will execute the following logic:

[0061] 1. Execute remote commands to mount and monitor the target application (i.e., the application filled in the current configuration, such as kcard-xxx). The command is . / sandbox.sh-p 7-d'service-monitor / cacheMonit', where 7 is the application process, which is obtained by executing the command ps-ef|grep-i kcard-xxx|awk'{print$2}' (for example, the target application is kcard-xxx); sandbox.sh is the mount monitoring execution script of the jvm-sandbox installed in advance on the server where the application is located; jvm-sandbox is a process monitoring tool based on the jvm environment, which can monitor the java process (i.e., the application process) in the jvm. Similar tools include trace, arthas, etc. Therefore, if jvm-sandbox is not used, other monitoring tools can also be used to achieve the purpose; service-monitor / cacheMonit is the name of the monitoring logic implementation package provided in this embodiment.

[0062] After the target application is successfully mounted and monitored, the current condition configuration status is changed to enabled, and the cache intervention function is enabled for the method that requires cache intervention. All methods in the monitoring application are monitored. When a method is called, before it is executed, the monitoring logic is executed: determine whether the cache intervention function is enabled. If it is enabled, determine whether the conditions corresponding to the method meet all the conditions in the condition configuration. If they are satisfied, cache intervention is executed, and the cache data is not read. Instead, the logic of the interface method is executed and the processed content is returned. Cache intervention can be implemented through the reflection technology in Java to invalidate the annotation of the specified cache location, such as obtaining the Field object of the condition attribute of the @Cacheable annotation (specifying the cache location) object of the method under test, and then executing the set method of the Field object to assign the condition attribute to false. It should be noted that when @Cacheable acts on a method, if the value of its condition attribute is true, it means that the cache reading function of the method is enabled. If the value is false, it means that the cache reading function of the method is disabled, so that each call to the method will not read the data stored in the cache, so as to ensure that the logic of the method is truly executed each time. Get the condition attribute of the @Cacheable annotation object without modifying the code, and complete the dynamic closure of the cache. This does not affect the target application itself. By setting different condition configurations in different test scenarios, the condition configuration is judged in each test. Only when the conditions are met will the cache be intervened, which will not affect other test scenarios.

[0063] The disclosed embodiment configures conditions for methods that require the cache intervention function to be enabled, monitors each method, and ensures that data stored in the memory-based cache is read only when the specified conditions are met, dynamically intervenes in the cache reading, and thus helps testers improve testing efficiency.

[0064] Furthermore, the method further comprises:

[0065] After the test is completed, delete the conditional configuration of the method or turn off the cache intervention function and change the status of the conditional configuration to closed to remove the cache intervention.

[0066] After the test is finished, the cache intervention can be removed by deleting the relevant configuration or changing the status of the configuration information to closed, so that it can return to normal without affecting other tests.

[0067] Furthermore, the method further comprises:

[0068] Enter the target application name to be tested and its corresponding method name information on the first page. After entering the information, a list is generated on the second page to display all the input target application names and corresponding method names. The second page also displays whether the cache intervention function is enabled for each method, and the edit button on the second page allows you to edit the conditional configuration information of each method on the third page.

[0069] The application name refers to the name of the application to which the interface under test belongs, such as kcard-xxx. The method name refers to the name of the method that triggers the read-write cache during the execution of the interface under test when the tester initiates a request to the interface under test. Here, you need to fill in the full path name of the method, such as com.kcard.controller.UserController.fullInfo, which means the fullInfo method under the class com.kcard.controller.UserController.

[0070] In order to manage the test, the present disclosure embodiment provides three pages. First,

[0071] 1. Testers Figure 3 On the first page shown (provided by this disclosure), fill in the application name and method name, and click the Add button;

[0072] 2. After clicking the Add button, you will jump to Figure 4 The second page shown (provided by the present disclosure) displays all configured information; for the newly added configuration information, its status is "off", and the tester can click the "on" button to change the status to "on", so that when the configured method is called, the cache function will be intervened;

[0073] 3. For configurations that require caching intervention, testers need to click the "Edit" button to configure the conditions, such as Figure 5 As shown in the figure; on the third page, the tester can add multiple lines of conditions. When the method is called, the intervention of the cache function will be triggered only when all the conditions are met. The intervention here means to disable the cache function, so that each query request (i.e. method call) initiated by the tester will not read the cached data, but execute the logic of the interface method and return the processed content;

[0074] 4. After the test is completed, the tester can click the delete button ( Figure 4 or Figure 5 ) to delete the relevant configuration, or click the "Close" button to change the status of the configuration information to closed, thereby releasing the cache intervention and restoring it to normal.

[0075] Adding, managing, and editing applications and methods through multiple pages can better display the status of all target applications and methods, thereby ensuring accurate information and achieving convenient management.

[0076] Furthermore, the determination of whether the cache intervention function is enabled, if enabled, then determining whether the conditions corresponding to the method meet all conditions in the condition configuration, includes:

[0077] Determine whether the current method is a method in the list on the second page and whether the cache intervention function is enabled;

[0078] If yes, set a variable flag with an initial value of true, read the condition configuration of the method, traverse each line of the condition configuration, obtain the parameter value of the method parameter position configured by the current condition, compare the parameter value with the value configured by the current condition, and if they are inconsistent, assign the variable flag to false;

[0079] Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal;

[0080] After the traversal is completed, it is determined whether the value of flag is true. If it is true, it is determined that the condition corresponding to the method meets all the conditions in the condition configuration.

[0081] When determining whether cache intervention is needed, the monitoring logic implementation process is as follows:

[0082] (1) Determine whether the current method is Figure 4 A method in the list and the status is enabled, if so, execute the following logic (2);

[0083] (2) Set a variable flag with an initial value of true; read the method in Figure 5 The condition configuration on the page traverses each row of conditions and performs the following operations:

[0084] Get the parameter value of the method parameter position configured by the current condition (for example, position 1 means getting the value of the first parameter of the current method), and compare the value with the value configured by the current condition (such as 18600000001). If they are inconsistent, the flag is assigned to false.

[0085] Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal.

[0086] (3) After the above traversal is completed, determine whether the value of flag is true. If it is true, execute the cache closing step.

[0087] Furthermore, the cache intervention is performed without reading cache data, but the logic of the interface method is executed and the processed content is returned, including:

[0088] Use reflection to get the Method object of the current method;

[0089] Execute the method object to determine whether there is this annotation method on the judgment class to determine whether the current method is annotated with @Cacheable;

[0090] If so, use reflection to invalidate cached reads, including:

[0091] Get the @Cacheable annotation object that applies to the current method through the Method object;

[0092] Then get the class object of the annotation object;

[0093] Get the Field object of the condition attribute of the Cacheable object through this class object;

[0094] Execute the set method of the Field object to assign a value of false to the condition property, thereby turning off the cache reading function of the method so that each time the method is called, the data stored in the cache will not be read, and the logic of the interface method will be executed.

[0095] The cache intervention process is implemented through reflection technology in Java, including:

[0096] (4) First use reflection to obtain the Method object of the current method. Specifically, first obtain the object that executes the current method, then obtain the class object of the object, and then execute the getDeclaredMethod method of the class object to obtain the method object (Method object) of the current method; then execute the following logic;

[0097] (5) Execute the isAnnotationPresent method of the Method object to determine whether the current method is annotated with @Cacheable. If so, execute the logic of (6). Here is an explanation: in springboot, if you need to trigger a cache read operation when a method is executed, the @Cacheable annotation will be used to modify the method.

[0098] (6) Use reflection to invalidate cache reading, specifically: execute the getDeclaredAnnotation method of the Method object (passing the parameter as Cacheable.class) to obtain the object of the @Cacheable annotation acting on the current method (name it cacheable), then obtain the class object of the annotation object (Classclazz=cacheable.class), then execute the getDeclaredField method of the class object (passing the parameter as condition) to obtain the Field object of the condition attribute of the cacheable object (the code is Fieldcondition_field=clazz.getDeclaredField("condition")), then execute the set method of the Field object to assign the condition attribute to false (the code is condition_field.set(cacheable,false)). Here is an explanation: when @Cacheable acts on a method, if the value of its condition attribute is true, it means that the cache reading function of the method is turned on, and if the value is false, it means that the cache reading function of the method is turned off, so that each time the method is called, the data stored in the cache will not be read, thereby ensuring that the logic of the method is truly executed each time.

[0099] Furthermore, the method further comprises:

[0100] The cache intervention function is automatically enabled when it is detected that the data in the database has changed and the cache data has not been updated in time.

[0101] The disclosed embodiment performs conditional configuration on the methods that need to enable the cache intervention function, monitors each method, and when the cache intervention function is enabled and the conditional configuration is met, obtains the specified cache location and annotates its properties without modifying the code, and does not read the data stored in the cache by modifying its properties, so that the data stored in the memory-based cache is only read when the specified conditions are met, dynamically intervenes in the cache reading, and thus helps testers improve testing efficiency.

[0102] The second embodiment of the present disclosure also provides a method for dynamically closing a cache. Figure 3-5 As shown, the implementation steps are as follows:

[0103] 1. Testers Figure 3 Fill in the application name and method name on the page shown (provided by the present invention), and click the Add button;

[0104] 2. After clicking the Add button, you will jump to Figure 4 The page shown (provided by the present invention) displays all configured information; for newly added configuration information, its status is "off", and the tester can click the "on" button to change the status to "on", so that when the configured method is called, the cache function will be intervened;

[0105] 3. For configurations that require caching intervention, testers need to click the "Edit" button to configure the conditions, such as Figure 5 As shown in the figure, on this page, the tester can add multiple lines of conditions. When the method is called, the intervention of the cache function will be triggered only when all the conditions are met. The intervention here means to disable the cache function, so that each query request (i.e. method call) initiated by the tester will not read the cached data, but execute the logic of the interface method and return the processed content;

[0106] 4. After the test is completed, the tester can click the delete button ( Figure 4 or Figure 5 ) to delete the relevant configuration, or click the "Close" button to change the status of the configuration information to closed, thereby releasing the cache intervention and restoring it to normal.

[0107] The description and principles of each step are as follows:

[0108] For step 1:

[0109] Here, the application name refers to the name of the application to which the interface under test belongs, such as kcard-xxx; the method name refers to the name of the method that triggers the read-write cache during the execution of the interface under test when the tester initiates a request to the interface under test. Here, you need to fill in the full path name of the method, such as com.kcard.controller.UserController.fullInfo, which means the fullInfo method under the class com.kcard.controller.UserController. It should be noted that the interface method under test itself does not necessarily trigger the read-write cache. Usually, a sub-method (usually a query function method) in its execution process will trigger the read-write cache.

[0110] When the tester clicks the Add button, a request will be triggered to service A (the service provided by the present invention). After receiving the request, service A will save the newly added configuration information in redis. At this time, the value of the status field is saved as closed.

[0111] For step 2:

[0112] When jumping to Figure 4When the page is opened, the page will query service A for all the configuration information currently saved in redis, and then display it as Figure 4 As shown in the table, for the newly added configuration, its status is closed by default; only the methods represented by the configurations with the status turned on will trigger the intervention of the cache function when they are called; when the tester clicks the "Turn on" button, a request will be triggered to service A, and service A will execute the following logic:

[0113] 1. Execute remote commands to mount and monitor the target application (i.e., the application filled in by the current configuration, such as kcard-xxx). The command is . / sandbox.sh-p 7-d'service-monitor / cacheMonit', where 7 is the process of the application, which is obtained by executing the command ps-ef|grep-i kcard-xxx|awk'{print$2}' (for example, the target application is kcard-xxx); sandbox.sh is the mount monitoring execution script of the jvm-sandbox installed in advance on the server where the application is located; jvm-sandbox is a process monitoring tool based on the jvm environment, which can monitor the java process (i.e., the application process) in the jvm. Similar tools include trace, arthas, etc. Therefore, if jvm-sandbox is not used, other monitoring tools can also be used to achieve the purpose; service-monitor / cacheMonit is the name of the monitoring logic implementation package provided by the present invention, and the implementation logic is as follows:

[0114] Monitor all methods in the application. When a method is called, execute the following logic before it is executed.

[0115] (1) Determine whether the current method is Figure 4 A method in the list and the status is enabled. If so, execute the logic of (2);

[0116] (2) Set a variable flag with an initial value of true; read the method in Figure 5 The condition configuration on the page traverses each row of conditions and performs the following operations:

[0117] (2-1) Get the parameter value of the method parameter position configured by the current condition (for example, position 1 means getting the value of the first parameter of the current method), and compare the value with the value configured by the current condition (such as 18600000001). If they are inconsistent, the flag is assigned to false;

[0118] (2-2) Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal.

[0119] (3) After the traversal of (2) is completed, determine whether the value of flag is true. If it is true, execute the logic of (4);

[0120] (4) Use reflection to obtain the Method object of the current method. Specifically, first obtain the object that executes the current method, then obtain the class object of the object, and then execute the getDeclaredMethod method of the class object to obtain the method object (Method object) of the current method; then execute the logic of (5);

[0121] (5) Execute the isAnnotationPresent method of the Method object to determine whether the current method is annotated with @Cacheable. If so, execute the logic of (6). Here is an explanation: in springboot, if you need to trigger a cache read operation when a method is executed, the @Cacheable annotation will be used to modify the method.

[0122] (6) Use reflection to invalidate cache reading, specifically: execute the getDeclaredAnnotation method of the Method object (passing the parameter as Cacheable.class) to obtain the object of the @Cacheable annotation acting on the current method (name it cacheable), then obtain the class object of the annotation object (Classclazz=cacheable.class), then execute the getDeclaredField method of the class object (passing the parameter as condition) to obtain the Field object of the condition attribute of the cacheable object (the code is Fieldcondition_field=clazz.getDeclaredField("condition")), then execute the set method of the Field object to assign the condition attribute to false (the code is condition_field.set(cacheable,false)). Here is an explanation: when @Cacheable acts on a method, if the value of its condition attribute is true, it means that the cache reading function of the method is turned on, and if the value is false, it means that the cache reading function of the method is turned off, so that each time the method is called, the data stored in the cache will not be read, thereby ensuring that the logic of the method is truly executed each time.

[0123] 2. After the target application is successfully mounted and monitored, change the status of the current configuration to enabled.

[0124] For step 3:

[0125] Every time a conditional configuration is added or modified on a page, a request will be triggered to service A, thereby updating the configuration information saved in redis. The role and principle of conditional configuration are explained in the previous section.

[0126] For step 4:

[0127] Changing the status of the configuration information to closed, or modifying or deleting the conditional configuration can remove the cache intervention. For the specific reasons, see the explanation in step 2.

[0128] The embodiment of the present disclosure builds a test auxiliary system in a test environment, which can monitor the application under test, and deploys a container with a jvm-sandbox in the instance of the application under test, which shares the jvm-sandbox with the application under test.

[0129] The code development of the monitoring processing logic can be implemented by referring to this embodiment, as shown in Figure 6. In this example, a method cn.chinaunicom.open.nlgxptconnection.COMPConnection#excute is monitored. What needs to be done later is to change the monitoring method to monitor all methods and implement the monitoring processing logic in the monitoring event.

[0130] The third embodiment of the present disclosure also provides a cache dynamic closing system, such as Figure 7 As shown, the system comprises:

[0131] A determination module 11, which is configured to determine a target application to be tested and a corresponding method thereof;

[0132] A configuration module 12, which is configured to perform conditional configuration for a method that needs to enable a cache intervention function, and determine whether to enable the cache intervention function;

[0133] A monitoring module 13 is configured to monitor the target application so as to monitor all methods in the application and enable a cache intervention function for methods requiring cache intervention;

[0134] The cache intervention module 14 is configured to test the target application and execute the monitoring logic when calling a corresponding method, including: determining whether the cache intervention function is enabled; if enabled, determining whether the conditions corresponding to the method meet all the conditions in the condition configuration; if satisfied, executing the cache intervention without reading the cache data, executing the logic of the interface method and returning the processed content.

[0135] Furthermore, the system also includes:

[0136] The release module 15 is configured to release the cache intervention by deleting the conditional configuration of the method or turning off the cache intervention function after the test is completed, and changing the state of the conditional configuration to off.

[0137] Furthermore, the system also includes a display module 16;

[0138] The display module 16 is configured to input the target application name to be tested and its corresponding method name information through the first page. After the information is input, a list is generated on the second page to display all the input target application names and corresponding method names, and whether the cache intervention function is enabled for each method is displayed on the second page, and the conditional configuration information of each method can be edited on the third page through the edit button on the second page.

[0139] Furthermore, the cache intervention module 14 is specifically configured as follows:

[0140] Determine whether the current method is a method in the list on the second page and whether the cache intervention function is enabled;

[0141] If yes, set a variable flag with an initial value of true, read the condition configuration of the method, traverse each line of the condition configuration, obtain the parameter value of the method parameter position configured by the current condition, compare the parameter value with the value configured by the current condition, and if they are inconsistent, assign the variable flag to false;

[0142] Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal;

[0143] After the traversal is completed, it is determined whether the value of flag is true. If it is true, it is determined that the condition corresponding to the method meets all the conditions in the condition configuration.

[0144] Furthermore, the cache intervention module 14 is specifically configured as follows:

[0145] Use reflection to get the Method object of the current method;

[0146] Execute the method object to determine whether there is this annotation method on the judgment class to determine whether the current method is annotated with @Cacheable;

[0147] If so, use reflection to invalidate cached reads, including:

[0148] Get the @Cacheable annotation object that applies to the current method through the Method object;

[0149] Then get the class object of the annotation object;

[0150] Get the Field object of the condition attribute of the Cacheable object through this class object;

[0151] Execute the set method of the Field object to assign a value of false to the condition property, thereby turning off the cache reading function of the method so that each time the method is called, the data stored in the cache will not be read, and the logic of the interface method will be executed.

[0152] The cache dynamic closing system of the embodiment of the present disclosure is used to implement the cache dynamic closing method in method embodiment 1 and embodiment 2, so the description is relatively simple. For details, please refer to the relevant description in the previous method embodiment, which will not be repeated here.

[0153] In addition, if Figure 8 As shown, the fourth embodiment of the present disclosure further provides an electronic device, including a memory 100 and a processor 200, wherein the memory 100 stores a computer program, and when the processor 200 runs the computer program stored in the memory 100, the processor 200 executes the above-mentioned various possible methods.

[0154] The memory 100 is connected to the processor 200. The memory 100 may be a flash memory, a read-only memory or other memory, and the processor 200 may be a central processing unit or a single-chip microcomputer.

[0155] In addition, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to perform the above-mentioned various possible methods.

[0156] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), Digital Video Disc (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.

[0157] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present disclosure, but the present disclosure is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and substance of the present disclosure, and these modifications and improvements are also considered to be within the scope of protection of the present disclosure.

Claims

1. A cache dynamic closing method, characterized in that: The method comprises: Determine the target application to be tested and its corresponding method; Conditionally configure the method that needs to enable the cache intervention function, and determine whether to enable the cache intervention function; Mount a monitor on the target application to monitor all methods in the application and enable cache intervention for methods that require cache intervention. Test the target application and execute the monitoring logic when calling a corresponding method, including: judging whether the cache intervention function is enabled. If it is enabled, judging whether the conditions corresponding to the method meet all the conditions in the condition configuration. If so, cache intervention is performed without reading cache data, but executing the logic of the interface method and returning the processed content.

2. The method according to claim 1, characterized in that The method further comprises: After the test is completed, delete the conditional configuration of the method or turn off the cache intervention function and change the status of the conditional configuration to closed to remove the cache intervention.

3. The method according to claim 1, characterized in that The method further comprises: Enter the target application name to be tested and its corresponding method name information on the first page. After entering the information, a list is generated on the second page to display all the input target application names and corresponding method names. The second page also displays whether the cache intervention function is enabled for each method, and the edit button on the second page allows you to edit the conditional configuration information of each method on the third page.

4. The method according to claim 3, characterized in that The step of determining whether the cache intervention function is enabled, and if enabled, determining whether the conditions corresponding to the method meet all conditions in the condition configuration, includes: Determine whether the current method is a method in the list on the second page and whether the cache intervention function is enabled; If yes, set a variable flag with an initial value of true, read the condition configuration of the method, traverse each line of the condition configuration, obtain the parameter value of the method parameter position configured by the current condition, compare the parameter value with the value configured by the current condition, and if they are inconsistent, assign the variable flag to false; Determine whether the value of flag is true. If it is true, continue to traverse the next line of conditions; if it is false, end the traversal; After the traversal is completed, it is determined whether the value of flag is true. If it is true, it is determined that the condition corresponding to the method meets all the conditions in the condition configuration.

5. The method according to claim 4, characterized in that The execution cache intervention does not read the cache data, but executes the logic of the interface method and returns the processed content, including: Use reflection to get the Method object of the current method; Execute the method object to determine whether there is this annotation method on the judgment class to determine whether the current method has the @Cacheable annotation effect at the specified cache location; If so, use reflection to invalidate cached reads, including: Get the @Cacheable annotation object that applies to the current method through the Method object; Then get the class object of the annotation object; Get the Field object of the condition attribute of the Cacheable object through this class object; Execute the set method of the Field object to assign a value of false to the condition property, thereby turning off the cache reading function of the method so that each time the method is called, the data stored in the cache will not be read, and the logic of the interface method will be executed.

6. A cache dynamic closing system, characterized in that: The system comprises: A determination module configured to determine a target application to be tested and a corresponding method thereof; A configuration module, which is configured to conditionally configure the method that needs to enable the cache intervention function and determine whether to enable the cache intervention function; A monitoring module is configured to mount a monitor on the target application to monitor all methods in the application and enable cache intervention for methods that require cache intervention; The cache intervention module is configured to test the target application and execute the monitoring logic when calling a corresponding method, including: determining whether the cache intervention function is enabled; if enabled, determining whether the conditions corresponding to the method meet all the conditions in the condition configuration; if satisfied, executing cache intervention without reading cache data, executing the logic of the interface method and returning the processed content.

7. The system according to claim 6, characterized in that The system further comprises: The release module is configured to release cache intervention by deleting the conditional configuration of the method or turning off the cache intervention function after the test is completed, and changing the state of the conditional configuration to closed.

8. The system according to claim 6, characterized in that The system also includes a display module; The display module is configured to input the target application name to be tested and its corresponding method name information through the first page. After the information is input, a list is generated on the second page to display all the input target application names and corresponding method names, and whether the cache intervention function is enabled for each method is displayed on the second page, and the conditional configuration information of each method can be edited on the third page through the edit button on the second page.

9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program stored in the memory, the processor executes the cache dynamic closing method according to any one of claims 1 to 5.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the cache dynamic closing method according to any one of claims 1 to 5 is implemented.