Caching methods, electronic devices, and storage media
By introducing an annotation to automatically clear the cache in the target code and building a mapping relationship between data tables and methods, the problem of inconsistency between data tables and cached data is solved, improving development efficiency and application performance.
Patent Information
- Application Number
- CN202410101767.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-23
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2044-01-23
AI Technical Summary
During application development, business code often forgets to delete or update data in the database tables, leading to inconsistencies between the data in the tables and the data in the cache, which affects application performance.
By introducing an automatic cache clearing annotation into the target code, a data table method mapping relationship is built, and the corresponding data in the cache is automatically cleared, ensuring the consistency between the data table and the cached data.
It enables automatic cache clearing during target operations, improving development efficiency and ensuring consistency between the data table and the cached data.
Smart Images

Figure CN117909367B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, specifically to a caching method, electronic device, and storage medium. Background Technology
[0002] Caching is a common technique for improving application performance. For example, if an application needs to query a large amount of data from a table in a database, and due to the limitations of computer hardware, disk access is much slower than memory access, caching can be used to store the data in the table in memory to achieve fast access.
[0003] However, during application development, business code often needs to access the database and also needs to cache the data tables in the database. However, problems may arise where data is deleted from the data table but the corresponding data in the cache is not deleted, or data in the data table is updated but the corresponding data in the cache is not updated. This leads to inconsistencies between the data in the data table and the data in the cache, affecting the use of the application. Summary of the Invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, this application aims to provide a caching processing method, electronic device, and storage medium to automatically clear the cache when performing target operations on the target table by automatically clearing cache annotations, thereby improving development efficiency.
[0005] This application provides a caching method, the method comprising:
[0006] Based on the automatic cache clearing annotation in the target code, a data table method mapping relationship is constructed; wherein, the data table method mapping relationship is a mapping relationship between data table names and cached methods; the cached methods are the methods marked with the automatic cache clearing annotation;
[0007] When a target operation is detected to be performed on a target data table, each target method corresponding to the target data table is determined according to the target data table and the data table method mapping relationship, and target key information corresponding to each target method is constructed; wherein, the method corresponding to the target operation is a cached method, and the target operation is at least one of the following: add operation, update operation, and delete operation;
[0008] Based on the target key information, the target value information corresponding to the target key information is deleted from the cache.
[0009] Optionally, the construction of target key information corresponding to each target method includes:
[0010] For each target method, obtain the target class name and target method name corresponding to the target method;
[0011] Based on the target class name and the target method name, construct the target key information corresponding to the target method.
[0012] Optionally, before determining the target methods corresponding to the target data table based on the target data table and the data table method mapping relationship when a target operation is detected to be performed on the target data table, the method further includes:
[0013] When executing the target statement in the target code, determine the target data table corresponding to the target statement, and determine whether the target data table is in the data table method mapping relationship;
[0014] If the target data table is in the data table method mapping relationship, the method corresponding to the target data table is determined to be a cache method;
[0015] If the method corresponding to the target data table is a caching method, it is determined that a target operation corresponding to the target statement is detected being executed on the target data table;
[0016] The target statement is at least one of the following: a new statement, an update statement, and a delete statement.
[0017] Optionally, before determining the target methods corresponding to the target data table based on the target data table and the data table method mapping relationship when a target operation is detected to be performed on the target data table, the method further includes:
[0018] Obtain the data table operation log, parse the data table operation log, and determine the data table operations in the data table operation log;
[0019] For each of the data table operations, determine whether the target data table corresponding to the data table operation is in the data table method mapping relationship;
[0020] If the target data table corresponding to the data table operation is in the data table method mapping relationship, the data table operation is identified as the target operation, and it is determined that the target operation is detected to be performed on the target data table.
[0021] Optionally, the method further includes:
[0022] When executing a query statement and the method corresponding to the query statement is a cached method, the method corresponding to the query statement is identified as the method to be processed, and the class name to be processed, the method name to be processed, and the query parameters are determined according to the query statement and the method to be processed.
[0023] Based on the class name to be processed, the method name to be processed, and the query parameters, construct the first key information, and based on the class name to be processed and the method name to be processed, construct the second key information;
[0024] Based on the first key information, the cached value corresponding to the query statement is returned, and the cached value is stored in the cache. A correspondence between the first key information and the cached value and a correspondence between the cached value and the second key information are established in the cache, wherein the target key information belongs to the second key information.
[0025] Optionally, the step of returning the cached value corresponding to the query statement based on the first key information and storing the cached value in the cache, and establishing a correspondence between the first key information and the cached value and a correspondence between the cached value and the second key information in the cache, includes:
[0026] If a first value corresponding to the first key information exists in the cache, the first value information is used as the cached value corresponding to the query statement;
[0027] If the first value information corresponding to the first key information does not exist in the cache, the query statement corresponding to the first key information is executed, the cached value corresponding to the query statement is returned, the cached value is used as the first value information corresponding to the first key information, and the correspondence between the cached value and the second key information is constructed.
[0028] Optionally, deleting the target value information corresponding to the target key information in the cache according to the target key information includes:
[0029] Based on the target operation, determine the operation data in the target data table;
[0030] From the target value information corresponding to the target key information, determine the information to be deleted that is related to the operation data, and delete the information to be deleted from the cache.
[0031] Optionally, the step of constructing the data table method mapping relationship based on the automatic cache clearing annotation in the target code includes:
[0032] Based on the target code, determine the various repository classes within the target code;
[0033] For each warehouse class, determine the data table name corresponding to the warehouse class, as well as the warehouse class methods corresponding to the warehouse class;
[0034] For each repository class method, determine whether the repository class method is marked with an annotation to automatically clear the cache;
[0035] If the repository class method is marked with the automatic cache clearing annotation, the repository class method is identified as a cache method, and the mapping relationship between the repository class method and the corresponding data table name is added to the data table method mapping relationship.
[0036] This application also provides an electronic device, the electronic device comprising:
[0037] Processor and memory;
[0038] The processor executes the steps of the cache processing method as described in any embodiment by invoking programs or instructions stored in the memory.
[0039] This application also provides a computer-readable storage medium that stores a program or instructions that cause a computer to perform the steps of the caching method as described in any embodiment.
[0040] In summary, this application proposes a caching method. By constructing a data table-method mapping relationship based on the automatic cache clearing annotation in the target code, it facilitates the rapid identification of the cached method using the data table. Furthermore, when a target operation is detected on the target data table, the method corresponding to the target data table is determined based on the target data table and the data table-method mapping relationship. Target key information is constructed for each target method. This allows for the construction of target key information during CRUD operations on the data table. Based on the target key information, the target value information corresponding to the target key information in the cache is deleted, enabling the retrieval of data affected by changes in the data table. This achieves the effect of automatically clearing the cache when a target operation is performed on the target table by automatically clearing the cache annotation, thereby improving development efficiency. Attached Figure Description
[0041] Figure 1 This is a flowchart of a caching method provided in an embodiment of this application;
[0042] Figure 2 This is a schematic diagram illustrating the mapping relationship of a method for constructing a data table provided in an embodiment of this application;
[0043] Figure 3 This is a schematic diagram of a cache deletion process provided in an embodiment of this application;
[0044] Figure 4 This is a flowchart of another caching method provided in an embodiment of this application;
[0045] Figure 5 This is a schematic diagram of a cache storage process provided in an embodiment of this application;
[0046] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0047] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0048] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0049] Figure 1 This is a flowchart of a caching method provided in an embodiment of this application. See also... Figure 1 The caching method specifically includes:
[0050] S110. Based on the auto-clear cache annotation in the target code, construct the data table method mapping relationship.
[0051] The target code is the application code. The `@AutoClearCache` annotation enables the corresponding cached methods to automatically clear caches; it doesn't execute but simply annotates the code. The table-method mapping is the mapping between table names and cached methods, which can be stored using a Map interface for quick retrieval of the corresponding value using the key. The key is the table name, and the value is a list of cached methods. The cached methods are those marked with the `@AutoClearCache` annotation. When a cached method is executed for the first time, it accesses the database table. Subsequent executions will access the cached data as long as the cache hasn't expired. Specifically, applying the `@AutoClearCache` annotation to the CRUD (Create, Retrieve, Update, Delete) methods in the `Repository` class enables these methods to have caching and automatic cache clearing capabilities.
[0052] Specifically, before executing the target code, the mapping relationship between table names and cached methods in the target code is parsed and constructed, i.e., the table-method mapping relationship. Each cached method marked with the automatic caching annotation is obtained, and a mapping relationship is established between the cached method and its corresponding table name.
[0053] Based on the above example, the data table method mapping relationship can be constructed according to the automatic cache clearing annotation in the target code in the following way:
[0054] Based on the target code, identify the various repository classes within the target code;
[0055] For each warehouse class, determine the corresponding data table name and the corresponding warehouse class methods;
[0056] For each repository class method, determine whether the repository class method is marked with the automatic cache clearing annotation;
[0057] When a repository class method is marked with the "Auto-clear cache" annotation, the repository class method is identified as a cached method, and the mapping relationship between the repository class method and the corresponding data table name is added to the data table method mapping relationship.
[0058] The repository class is the `Repository` class, which is an interface provided by the JPA (Java Persistence API) framework for developers to manipulate database tables. Since the `Repository` class implements the `Repository` interface, its methods have CRUD (Create, Read, Update, Delete) functionality. The repository class methods are the methods defined within the `Repository` class.
[0059] Specifically, the target code is read and parsed to obtain the repository classes. Each repository class is processed iteratively; specifically, for each repository class, the corresponding data table name is determined, and all methods under that repository class are identified as repository class methods. Each repository class method is then processed iteratively; if a method is marked with an `@AutoClearCache` annotation, it is considered a cached method; otherwise, it is not. The mapping relationship between data table names and cached methods is added to the data table method mapping relationship to achieve the purpose of constructing the data table method mapping relationship. Upon completion of the loop, the data table method mapping relationship is obtained. A diagram illustrating the construction of the data table method mapping relationship is shown below. Figure 2 As shown.
[0060] For example, before the application starts, it is necessary to parse out the mapping relationship Map between the data table names and cached methods in the target code. This way, after adding, deleting, or updating data in the database, the corresponding cached method can be found by the data table name. Then, the cached value corresponding to each cached method can be processed. This will achieve the effect of automatically deleting the corresponding cached value after deleting data in the data table in the database.
[0061] S120. When a target operation is detected to be performed on the target data table, the target methods corresponding to the target data table are determined according to the target data table and the data table method mapping relationship, and the target key information corresponding to each target method is constructed.
[0062] The target operation corresponds to a cached method, and the target operation is at least one of an add, update, and delete operation. The target data table is the data table affected by the execution of the target operation. The target method is any cached method in the data table method mapping relationship that has a mapping relationship with the target data table. The target key information is the key information constructed based on the target method and the target data table to locate the cached values affected by the target data table.
[0063] Specifically, continuous analysis and detection are performed to identify the existence of target operations. If a target operation is found, the data table corresponding to the target operation is designated as the target data table, confirming that a target operation has been performed on the target data table. In this case, the target data table is compared against the data table method mapping relationship to identify the cached methods corresponding to the target data table as target methods. Furthermore, for each target method, target key information is constructed based on the relevant information of the target method to facilitate the subsequent identification and processing of the cached values corresponding to the target key information.
[0064] Based on the above example, the target key information corresponding to each target method can be constructed in the following way:
[0065] For each target method, obtain the target class name and target method name corresponding to the target method;
[0066] Based on the target class name and the target method name, construct the target key information corresponding to the target method.
[0067] In this context, the target class name is the name of the class containing the target method, i.e., `className`. The target method name is the name of the target method, i.e., `methodName`. The target key information contains the target class name and the target method name; for example, the target key information is obtained by concatenating the target class name and the target method name.
[0068] Specifically, for each target method, the target key information corresponding to the target method can be constructed in the same way. Taking one target method as an example, the target method is parsed to obtain the target class name and target method name corresponding to the target method. The target class name and target method name are then concatenated as strings to obtain the target key information corresponding to that target method.
[0069] Building upon the example above, if a target operation is detected on the target data table, before determining the corresponding target methods based on the target data table and its method mapping relationship, it is also possible to determine whether a target operation on the target data table has been detected by checking the execution statement, as follows:
[0070] When executing the target statement in the target code, determine the target data table corresponding to the target statement, and determine whether the target data table is in the data table method mapping relationship;
[0071] When the target data table is in the data table method mapping relationship, the method corresponding to the target data table is determined to be the cached method;
[0072] If the method corresponding to the target data table is a cached method, it is determined that the target operation corresponding to the target statement was detected to be executed on the target data table.
[0073] The target statement is a statement that adds, deletes, or modifies data in a data table in the database. The target statement can be at least one of the following: add statement, update statement, and delete statement.
[0074] Specifically, during the execution of the target code, each statement is analyzed to determine if it is a target statement, specifically whether it is at least one of the following: an add statement, an update statement, or a delete statement. If it is a target statement, the corresponding data table is obtained through analysis and designated as the target data table. Further, the target data table is searched in the data table method mapping relationship to determine if it exists. If the target data table is found in the data table method mapping relationship, it indicates that the methods corresponding to that target data table are cached methods, allowing for subsequent parsing and processing. If the methods corresponding to the target data table are cached methods, it can be confirmed that the target operation corresponding to the target statement has been detected on the target data table.
[0075] Building upon the example above, before determining the target methods corresponding to the target data table based on the target data table and its method mapping relationship, it is possible to analyze the data table operation logs to determine whether a target operation has been detected. Specifically:
[0076] Obtain the data table operation log, parse the data table operation log, and determine the data table operations in the data table operation log;
[0077] For each data table operation, determine whether the target data table corresponding to the data table operation is in the data table method mapping relationship;
[0078] If the target data table corresponding to the data table operation is in the data table method mapping relationship, the data table operation is identified as the target operation, and it is determined that the target operation is detected to be performed on the target data table.
[0079] The data table operation log is a binlog (logical log), which records all structural changes and data modifications (inserts, deletes, updates, etc.) to the data tables in the database. Data table operations are the operations that modify data in the data tables, as recorded in the data table operation log.
[0080] Specifically, the data table operation logs are retrieved and parsed to identify each data table operation. For each data table operation, the following steps are performed: the target data table corresponding to the operation is identified, and it is determined whether the target data table is in the data table method mapping relationship. If it is, it indicates that the data table operation affects cached content. Therefore, the data table operation is identified as the target operation, and it is confirmed that the target operation was detected.
[0081] S130. Based on the target key information, delete the target value information corresponding to the target key information in the cache.
[0082] The target value information is the cached value corresponding to the target key information in the cache.
[0083] Specifically, the cache is matched based on the target key information to determine the target value information for each cached value corresponding to the target key information. The target value information is then deleted to process the cache.
[0084] Based on the above example, the target value information corresponding to the target key information in the cache can be deleted in the following way:
[0085] Based on the target operation, determine the operation data in the target data table;
[0086] From the target value information corresponding to the target key information, identify the information to be deleted that is related to the operation data, and delete the information to be deleted from the cache.
[0087] The operation data refers to the data in the target data table that the target operation modifies. The information to be deleted is the part of the target value information related to the operation data.
[0088] Specifically, the target operation is analyzed to determine the data in the target data table that is changed by the target operation. Further, the target value information corresponding to the target key information is searched according to the operation data to identify the target value information related to the operation data as the information to be deleted. Then, the information to be deleted from the cache is removed.
[0089] For example, after executing the target code, it's necessary to intercept the SQL (Structured Query Language) statement, then parse its type. If the SQL statement is an insert, update, or delete statement, it's identified as the target statement, and the data table within it is identified as the target data table. Then, using the previously constructed data table method mapping relationship, the list of cached methods corresponding to the target data table can be obtained by its name. These cached methods are the target methods. Each target method is processed iteratively. Based on the target method, target key information is generated, i.e., the target key information is constructed based on the target class name and the target method name. Using this target key information, all cached values corresponding to that key can be retrieved, i.e., the target value information. Subsequently, all cached values can be deleted. A diagram illustrating the cache deletion process is shown below. Figure 3 As shown.
[0090] The caching method provided in this application constructs a data table method mapping relationship based on the automatic cache clearing annotation in the target code. This facilitates the rapid determination of the cached method using the data table. Furthermore, when a target operation is detected on the target data table, the method corresponding to the target data table is determined based on the target data table and the data table method mapping relationship. Target key information corresponding to each target method is constructed. This allows for the construction of target key information when adding, deleting, or modifying data on the data table. Based on the target key information, the target value information corresponding to the target key information in the cache is deleted. This enables the retrieval of data affected by changes in the data table within the cache. This achieves the effect of automatically clearing the cache when a target operation is performed on the target table by automatically clearing the cache annotation, thereby improving development efficiency.
[0091] Figure 4 This is a flowchart of another caching method provided in an embodiment of this application. Based on the above embodiments, a process for constructing first key information and second key information, and a process for constructing the correspondence between the first key information and the second key information while returning the cached value during the execution of a query statement, are added. The above processes are illustrated by example. See [link to documentation]. Figure 4 The caching method specifically includes:
[0092] S210. Based on the auto-clear cache annotation in the target code, construct the data table method mapping relationship.
[0093] S220. When executing a query statement and the method corresponding to the query statement is a cached method, the method corresponding to the query statement is identified as the method to be processed, and the class name to be processed, the method name to be processed, and the query parameters are determined according to the query statement and the method to be processed.
[0094] The query statement retrieves data from tables in the database. The method to be processed is the cached method involved in the query statement. The class name to be processed is the name of the class containing the method to be processed. The method name to be processed is the method name of the method to be processed. The query parameters are the parameters used to execute the method to be processed, i.e., params.
[0095] Specifically, when executing the target code, each statement is analyzed to determine if it is a query statement. If it is a query statement, it is determined whether the method corresponding to the query statement is a cached method. If so, the cached value corresponding to the query statement can be retrieved from the cache, or a new cached value corresponding to the query statement can be added to the cache. Further, the method corresponding to the query statement is identified as the method to be processed, and the query statement is analyzed to determine the name of the method to be processed and the query parameters. The method to be processed is then analyzed to determine the class name to be processed.
[0096] S230. Based on the class name to be processed, the method name to be processed, and the query parameters, construct the first key information, and based on the class name to be processed and the method name to be processed, construct the second key information.
[0097] The first key information consists of the class name to be processed, the method name to be processed, and the query parameters, which are concatenated together. The second key information consists of the class name to be processed and the method name to be processed, which are concatenated together. The target key information belongs to the second key information and is used to find and delete the cached values corresponding to the second key information.
[0098] Specifically, the class name to be processed, the method name to be processed, and the query parameters are concatenated to obtain the first key information corresponding to the query statement. The class name to be processed and the method name to be processed are concatenated to obtain the second key information corresponding to the query statement.
[0099] S240. Based on the first key information, return the cached value corresponding to the query statement and store the cached value in the cache. Establish the correspondence between the first key information and the cached value and the correspondence between the cached value and the second key information in the cache.
[0100] Specifically, based on the first key information, the cached value corresponding to the first key information can be retrieved from the cache and used as the cached value for the query statement. If the cached value does not exist in the cache, the query statement can be executed to retrieve the cached value corresponding to the query statement from the database. Furthermore, a mapping relationship can be established between the cached value and the first key information, as well as between the cached value and the second key information, in the cache.
[0101] Therefore, the first key information corresponds to the cached value of the specific query parameter in the caching method, and the second key information corresponds to the cached value of each query parameter in the caching method.
[0102] Based on the above example, the cached value corresponding to the query statement can be returned according to the first key information in the following way, and the cached value can be stored in the cache. In the cache, the correspondence between the first key information and the cached value and the correspondence between the cached value and the second key information can be established:
[0103] If a first value corresponding to the first key information exists in the cache, the first value information will be used as the cached value corresponding to the query statement.
[0104] If the first value information corresponding to the first key information does not exist in the cache, execute the query statement corresponding to the first key information, return the cached value corresponding to the query statement, use the cached value as the first value information corresponding to the first key information, and construct the correspondence between the cached value and the second key information.
[0105] Among them, the first value information is the value information stored corresponding to the first key information of the cached value, that is, the cached value corresponding to the query statement, which is the query result.
[0106] Specifically, the system searches the cache based on the first key information. If a first value corresponding to the first key information exists, this first value is used as the cached value for the query statement, and the cached value can be returned as the query result. If no first value corresponding to the first key information exists, it means that there is no query result in the cache, i.e., this is the first time the query statement is executed. Therefore, the query statement corresponding to the first key information is executed, the cached value corresponding to the query statement is obtained, and this cached value can be returned as the query result. This cached value is then stored in the cache as the first value corresponding to the first key information, establishing a correspondence between this cached value and the second key information.
[0107] For example, when a query is executed for the first time, since there is no cache, the internal logic of the method is executed directly, which means querying the data table in the database as the query result. After obtaining the query result, it is cached in Redis (a distributed caching middleware). Subsequent executions of the same query will use the returned value (first value information) stored in Redis as the return value of the query, without executing the time-consuming database query. There are two caching processes here: First, the cached value returned by the caching method corresponding to the query statement under a certain parameter (query parameter) is used as the value information corresponding to the first key information, i.e., the first value information. This first value information and the first key information are stored in Redis, and subsequent executions can directly retrieve the cached value from Redis. Second, all cached values corresponding to the caching method are stored along with the caching method itself, i.e., the second key information corresponds to the first value information under each query parameter. This is used to delete the first value information when the target operation is executed later. A diagram illustrating the caching storage process is shown below. Figure 5 As shown.
[0108] S250. When a target operation is detected to be performed on a target data table, the target methods corresponding to the target data table are determined according to the target data table and the data table method mapping relationship, and target key information corresponding to each target method is constructed.
[0109] S260. Based on the target key information, delete the target value information corresponding to the target key information in the cache.
[0110] The caching method provided in this application, when executing a query statement and the method corresponding to the query statement is a cached method, determines the method corresponding to the query statement as the method to be processed, and determines the class name, method name, and query parameters to be processed based on the query statement and the method to be processed. A first key is constructed based on the class name, method name, and query parameters, and a second key is constructed based on the class name and method name to be processed. This facilitates the subsequent storage and retrieval of corresponding cached values using the first key information. All relevant cached values are determined using the second key information. Based on the first key information, the cached value corresponding to the query statement is returned and stored in the cache. A correspondence is established between the first key information and the cached value, and between the cached value and the second key information in the cache. This achieves automated writing of cached data during the query process and establishes two key-value correspondences, facilitating automatic clearing of cache annotations and improving development efficiency.
[0111] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 6As shown, the electronic device 600 includes one or more processors 601 and memory 602.
[0112] The processor 601 may be a central processing unit (CPU) or other form of processing unit with data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 600 to perform desired functions.
[0113] The memory 602 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 601 may execute the program instructions to implement the cache processing method of any embodiment of this application described above and / or other desired functions. Various contents such as initial extrinsic parameters and thresholds may also be stored in the computer-readable storage medium.
[0114] In one example, electronic device 600 may further include an input device 603 and an output device 604, these components being interconnected via a bus system and / or other forms of connection mechanisms (not shown). The input device 603 may include, for example, a keyboard, a mouse, etc. The output device 604 may output various information to the outside, including warning messages, braking force, etc. The output device 604 may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.
[0115] Of course, for the sake of simplicity, Figure 6 Only some of the components of the electronic device 600 relevant to this application are shown in this illustration; components such as buses, input / output interfaces, etc., are omitted. In addition, the electronic device 600 may include any other suitable components depending on the specific application.
[0116] In addition to the methods and devices described above, embodiments of this application may also be computer program products, which include computer program instructions that, when executed by a processor, cause the processor to perform the steps of the cache processing method provided in any embodiment of this application.
[0117] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this application. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0118] Furthermore, embodiments of this application may also be computer-readable storage media storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps of the cache processing method provided in any embodiment of this application.
[0119] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0120] It should be noted that the terminology used in this application is for the purpose of describing specific embodiments only and is not intended to limit the scope of this application. As shown in the specification and claims of this application, unless the context clearly indicates otherwise, words such as "a," "an," "an," and / or "the" do not specifically refer to the singular and may also include the plural. The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, or apparatus. Without further limitations, an element defined by the phrase "comprising an..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element.
[0121] It should also be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation on this application. Unless otherwise expressly specified and limited, the terms "installed," "connected," "linked," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication between two elements. For those skilled in the art, the specific meaning of the above terms in this application can be understood according to the specific circumstances.
[0122] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. The above descriptions are only preferred embodiments of this application. It should be noted that due to the limitations of written expression, while there are objectively infinite specific structures, those skilled in the art can make several improvements, modifications, or changes without departing from the principles of this invention, and can also combine the above technical features in an appropriate manner. These improvements, modifications, changes, or combinations, or the direct application of the inventive concept and technical solution to other situations without modification, should all be considered within the scope of protection of this application.
Claims
1. A caching method, characterized in that, include: Based on the automatic cache clearing annotation in the target code, a data table method mapping relationship is constructed; wherein, the data table method mapping relationship is a mapping relationship between data table names and cached methods; the cached methods are the methods marked with the automatic cache clearing annotation; When a target operation is detected to be performed on a target data table, each target method corresponding to the target data table is determined according to the target data table and the data table method mapping relationship, and target key information corresponding to each target method is constructed; wherein, the method corresponding to the target operation is a cached method, and the target operation is at least one of the following: add operation, update operation, and delete operation; Based on the target key information, delete the target value information corresponding to the target key information in the cache; The step of constructing the data table method mapping relationship based on the automatic cache clearing annotation in the target code includes: Based on the target code, determine the various repository classes within the target code; For each warehouse class, determine the data table name corresponding to the warehouse class, as well as the warehouse class methods corresponding to the warehouse class; For each repository class method, determine whether the repository class method is marked with an annotation to automatically clear the cache; If the repository class method is marked with the automatic cache clearing annotation, the repository class method is identified as a cache method, and the mapping relationship between the repository class method and the corresponding data table name is added to the data table method mapping relationship.
2. The method according to claim 1, characterized in that, The construction of target key information corresponding to each target method includes: For each target method, obtain the target class name and target method name corresponding to the target method; Based on the target class name and the target method name, construct the target key information corresponding to the target method.
3. The method according to claim 1, characterized in that, Before determining the target methods corresponding to the target data table based on the target data table and the data table method mapping relationship, upon detecting that a target operation is performed on the target data table, the method further includes: When executing the target statement in the target code, determine the target data table corresponding to the target statement, and determine whether the target data table is in the data table method mapping relationship; If the target data table is in the data table method mapping relationship, the method corresponding to the target data table is determined to be a cache method; If the method corresponding to the target data table is a caching method, it is determined that a target operation corresponding to the target statement is detected being executed on the target data table; The target statement is at least one of the following: a new statement, an update statement, and a delete statement.
4. The method according to claim 1, characterized in that, Before determining the target methods corresponding to the target data table based on the target data table and the data table method mapping relationship, upon detecting that a target operation is performed on the target data table, the method further includes: Obtain the data table operation log, parse the data table operation log, and determine the data table operations in the data table operation log; For each of the data table operations, determine whether the target data table corresponding to the data table operation is in the data table method mapping relationship; If the target data table corresponding to the data table operation is in the data table method mapping relationship, the data table operation is identified as the target operation, and it is determined that the target operation is detected to be performed on the target data table.
5. The method according to claim 1, characterized in that, Also includes: When executing a query statement and the method corresponding to the query statement is a cached method, the method corresponding to the query statement is identified as the method to be processed, and the class name to be processed, the method name to be processed, and the query parameters are determined according to the query statement and the method to be processed. Based on the class name to be processed, the method name to be processed, and the query parameters, construct the first key information, and based on the class name to be processed and the method name to be processed, construct the second key information; Based on the first key information, the cached value corresponding to the query statement is returned, and the cached value is stored in the cache. In the cache, a correspondence is established between the first key information and the cached value, and a correspondence is established between the cached value and the second key information.
6. The method according to claim 5, characterized in that, The step of returning the cached value corresponding to the query statement based on the first key information and storing the cached value in the cache, and establishing a correspondence between the first key information and the cached value and a correspondence between the cached value and the second key information in the cache, includes: If a first value corresponding to the first key information exists in the cache, the first value information is used as the cached value corresponding to the query statement; If the first value information corresponding to the first key information does not exist in the cache, the query statement corresponding to the first key information is executed, the cached value corresponding to the query statement is returned, the cached value is used as the first value information corresponding to the first key information, and the correspondence between the cached value and the second key information is constructed, wherein the target key information belongs to the second key information.
7. The method according to claim 1, characterized in that, The step of deleting the target value information corresponding to the target key information in the cache according to the target key information includes: Based on the target operation, determine the operation data in the target data table; From the target value information corresponding to the target key information, determine the information to be deleted that is related to the operation data, and delete the information to be deleted from the cache.
8. An electronic device, characterized in that, The electronic device includes: Processor and memory; The processor executes the steps of the cache processing method as described in any one of claims 1 to 7 by invoking the program or instructions stored in the memory.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a program or instructions that cause a computer to perform the steps of the caching method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Cache data updating method
CN111611287A
Cache dependency relationship management method and system, electronic equipment and medium
CN115878666A
