Cache processing method, device, equipment and computer-readable storage medium

By detecting the class name, method name and parameters of the database access interface in the JVM, querying the cache definition hash table and enabling thread-level caching, the problem of insufficient flexibility of the caching solution in the existing technology is solved, and fine-grained control and performance improvement are achieved. .

CN110109958BActive Publication Date: 2024-09-03WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910321455.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-04-19
Publication Date
2024-09-03
Estimated Expiration
2039-04-19

AI Technical Summary

Technical Problem

The existing JVM local thread-level caching solution is not flexible enough in the financial field, causing query results of all database tables to be cached, occupying too much memory space and affecting system performance.

Method used

By detecting when the application calls the database access interface, it obtains the class name, method name and incoming parameters, queries the preset cache definition hash table, determines whether there is a library table cache definition and enables the thread-level cache function, and only executes it when necessary. Thread-level cache data read and write operations.

Benefits of technology

It realizes fine-grained control of thread-level cache, improves the flexibility of JVM local thread-level cache solution, reduces memory usage, and improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110109958B
    Figure CN110109958B
Patent Text Reader

Abstract

The present invention discloses a cache processing method, which includes: when an instruction to call a database access interface is detected in a preset thread of an application, the class name, method name and input parameters of the currently called database access interface are obtained; according to the class name, a preset cache definition hash table is queried to determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table; if there is a library table cache definition corresponding to the class name in the cache definition hash table, it is determined whether the thread-level cache function corresponding to the library table cache definition is currently enabled; if the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation is performed according to the method name and the input parameters. The present invention also discloses a cache processing device, an apparatus and a computer-readable storage medium. The present invention improves the flexibility of the JVM local thread-level cache scheme.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a cache processing method, device, equipment and computer-readable storage medium. Background Art

[0002] In recent years, with the rapid development of Internet technology, especially Internet financial technology (Fintech), more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are applied in the financial field, and financial data is also growing exponentially. For example, large commercial banks usually have hundreds of business systems and massive data of hundreds of millions of users. In this case, higher requirements are put forward for the amount of data storage, concurrency and response speed. At present, in the financial field, caching technology is used when using JVM (Java Virtual Machine) to access financial database tables, that is, the database table records to be operated are loaded into the local JVM memory to increase the speed of program access to data and reduce database pressure.

[0003] In existing Java-based data persistence frameworks (such as Mybatis and Hibernate), thread-level cache cannot be controlled in a fine-grained manner. Once the cache is enabled, query results of all libraries and tables will be cached, which will occupy too much memory space and affect system performance. Therefore, the flexibility of existing JVM local thread-level cache solutions needs to be improved. Summary of the invention

[0004] The main purpose of the present invention is to propose a cache processing method, device, equipment and computer-readable storage medium, aiming to improve the flexibility of the JVM local thread-level cache solution.

[0005] To achieve the above object, the present invention provides a cache processing method, which comprises the following steps:

[0006] When an instruction of the application calling the database access interface is detected, the class name, method name and input parameters of the currently called database access interface are obtained;

[0007] Query a preset cache definition hash table according to the class name, and determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0008] If there is a library table cache definition corresponding to the class name in the cache definition hash table, determining whether a thread-level cache function corresponding to the library table cache definition is currently enabled;

[0009] If the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operations are performed according to the method name and the input parameters.

[0010] Preferably, when the instruction of the application calling the database access interface is detected, before the step of obtaining the class name, method name and input parameters of the currently called database access interface, the method further includes:

[0011] When the application is started, a preset cache configuration table is read, wherein the cache configuration information set based on the class names of different database access interfaces is recorded in the cache configuration table;

[0012] A cache definition hash table is generated according to the cache configuration information, and the cache definition hash table is saved in a preset Java virtual machine level cache definition area.

[0013] Preferably, the cache processing method further includes:

[0014] receiving a modification instruction based on the cache configuration table, and modifying the cache configuration information in the cache configuration table according to the modification instruction;

[0015] Generate a new cache definition hash table according to the modified cache configuration information;

[0016] The cache definition hash table stored in the Java virtual machine level cache definition area is updated to the new cache definition hash table.

[0017] Preferably, the step of performing corresponding thread-level cache data read and write operations according to the method name and the input parameters includes:

[0018] When the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameter to obtain a first query result;

[0019] Determine whether the first query result is empty;

[0020] If the first query result is empty, an operation of calling a database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table.

[0021] Preferably, the step of performing corresponding thread-level cache data read and write operations according to the method name and the input parameters includes:

[0022] When the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result;

[0023] Determine whether the second query result is empty;

[0024] If the second query result is empty, an operation of calling the database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table.

[0025] Preferably, the step of performing corresponding thread-level cache data read and write operations according to the method name and the input parameters includes:

[0026] When the method name identifies a data update operation, executing an operation of calling a database access interface to update corresponding data in the database, and saving the input parameters into the first thread-level cache data hash table;

[0027] It is determined whether there is an update object corresponding to the input parameter in the second thread-level cache data hash table; if so, the update object is updated according to the input parameter.

[0028] Preferably, the step of performing corresponding thread-level cache data read and write operations according to the method name and the input parameters includes:

[0029] When the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data into the database, and the input parameters are saved in the first thread-level cache data hash table.

[0030] Preferably, the step of performing corresponding thread-level cache data read and write operations according to the method name and the input parameters includes:

[0031] When the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database;

[0032] Corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the input parameters.

[0033] In addition, to achieve the above object, the present invention further provides a cache processing device, the cache processing device comprising:

[0034] The acquisition module is used to acquire the class name, method name and input parameters of the currently called database access interface when an instruction to call the database access interface is detected in a preset thread of the application program;

[0035] A first judgment module is used to query a preset cache definition hash table according to the class name, and judge whether there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0036] A second judgment module is used to judge whether the thread-level cache function corresponding to the library table cache definition is currently enabled if there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0037] The execution module is used to execute the corresponding thread-level cache data read and write operation according to the method name and the input parameters if the thread-level cache function corresponding to the library table cache definition is currently enabled.

[0038] Preferably, the cache processing device further includes:

[0039] A reading module, used to read a preset cache configuration table when the application is started, wherein the cache configuration table records cache configuration information set based on class names of different database access interfaces;

[0040] The generation module is used to generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table to a preset Java virtual machine level cache definition area.

[0041] Preferably, the cache processing device further includes:

[0042] A modification module, configured to receive a modification instruction based on the cache configuration table, and modify the cache configuration information in the cache configuration table according to the modification instruction;

[0043] The generating module is further used to generate a new cache definition hash table according to the modified cache configuration information;

[0044] An update module is used to update the cache definition hash table stored in the Java virtual machine level cache definition area to the new cache definition hash table.

[0045] Preferably, the execution module is also used for:

[0046] When the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameter to obtain a first query result;

[0047] Determine whether the first query result is empty;

[0048] If the first query result is empty, an operation of calling a database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table.

[0049] Preferably, the execution module is also used for:

[0050] When the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result;

[0051] Determine whether the second query result is empty;

[0052] If the second query result is empty, an operation of calling the database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table.

[0053] Preferably, the execution module is also used for:

[0054] When the method name identifies a data update operation, executing an operation of calling a database access interface to update corresponding data in the database, and saving the input parameters into the first thread-level cache data hash table;

[0055] It is determined whether there is an update object corresponding to the input parameter in the second thread-level cache data hash table; if so, the update object is updated according to the input parameter.

[0056] Preferably, the execution module is also used for:

[0057] When the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data into the database, and the input parameters are saved in the first thread-level cache data hash table.

[0058] Preferably, the execution module is also used for:

[0059] When the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database;

[0060] Corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the input parameters.

[0061] In addition, to achieve the above-mentioned purpose, the present invention also provides a cache processing device, which includes: a memory, a processor, and a cache processing program stored on the memory and executable on the processor, and the cache processing program implements the steps of the cache processing method described above when executed by the processor.

[0062] In addition, to achieve the above-mentioned purpose, the present invention further provides a computer-readable storage medium, on which a cache processing program is stored, and when the cache processing program is executed by a processor, the steps of the cache processing method described above are implemented.

[0063] When the present invention detects an instruction to call a database access interface in a preset thread of an application, the class name, method name and input parameters of the currently called database access interface are obtained; the preset cache definition hash table is queried according to the class name to determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table; if so, it is determined whether the thread-level cache function corresponding to the library table cache definition is currently enabled; if the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation is performed according to the method name and the input parameters. Compared with the method of caching the query results of all library tables in the prior art, this method realizes fine-grained control of thread-level cache, that is, only when there is a library table cache definition corresponding to the class name of the currently called database access interface in the preset cache definition hash table, and the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation will be performed, thereby improving the flexibility of the JVM local thread-level cache scheme. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;

[0065] Figure 2 FIG. 4 is a flow chart of a first embodiment of a cache processing method according to the present invention.

[0066] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0067] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0068] like Figure 1 As shown, Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.

[0069] The cache processing device in the embodiment of the present invention may be a PC or a server device, on which a Java virtual machine runs.

[0070] like Figure 1As shown, the cache processing device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0071] Those skilled in the art will understand that Figure 1 The device structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0072] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a cache processing program.

[0073] exist Figure 1 In the device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the cache processing program stored in the memory 1005 and perform the operations in the following cache processing method.

[0074] Based on the above hardware structure, an embodiment of the cache processing method of the present invention is proposed.

[0075] Reference Figure 2 , Figure 2 This is a flow chart of a first embodiment of a cache processing method of the present invention, the method comprising:

[0076] Step S10, when an instruction to call a database access interface is detected in a preset thread of the application, the class name, method name and input parameters of the currently called database access interface are obtained;

[0077] The cache processing method of this embodiment is applied to a cache processing device, on which a JVM (Java Virtual Machine) is running, and the JVM uses a data persistence framework based on the Java programming language such as Mybatis or Hibernate to operate the database. For example, in the financial field, it is often necessary to use JVM to access financial database tables, such as account information tables, account opening information tables, financial transaction information tables, etc. In this process, cache technology is used to meet the concurrency and access speed requirements of financial services.

[0078] In this embodiment, the operation of the database using Mybatis is described as an example. The interface of Mybatis to access the database is called Mapper. When the JVM detects an instruction to call the database access interface Mapper in the preset thread of the application, it obtains the Mapper class name, Mapper method name and incoming parameters of the current call, where the incoming parameters are used to represent the domain object to be read and written, and one domain object corresponds to a database table record.

[0079] Specifically, interceptors can be defined on all Mappers in advance, such as:

[0080] @Around("execution(public*com.xxx..mapper..*.*(..))&&bean(*Mapper)") means to intercept all methods in all Mappers. When the system is running, each call to Mapper will be intercepted by the interceptor, and the interceptor will obtain the Mapper class name, Mapper method name and incoming parameters of the call.

[0081] It should be noted that, in this embodiment, the Mybatis code generator can be used to generate the code for accessing the database to improve development efficiency and unify the naming rules of all Mappers and their methods, thereby ensuring that the interceptor can intercept the code for accessing the database; in addition, the Mybatis code generator can also be not used, as long as the Mybatis Mapper naming and its method naming rules are unified, the interceptor can also intercept it.

[0082] Step S20, querying a preset cache definition hash table according to the class name, and determining whether there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0083] In this step, the preset cache definition hash table is queried according to the Mapper class name obtained above to determine whether there is a library table cache definition corresponding to the Mapper class name in the cache definition hash table.

[0084] Specifically, a JVM-level cache definition area can be pre-set in the system. The cache definition area is used to store a cache definition hash table. The cache definition hash table is represented by a HashMap. The HashMap implements the "Key-Value key-value pair" interface, and the structure is as follows:

[0085] Key Value mapperName1 sysTransCacheDef1 mapperName2 sysTransCacheDef2 …… ……

[0086] Among them, the Key is the mapperName (Mapper class name) of the SysTransCacheDef domain object, and the value is the SysTransCacheDef domain object itself.

[0087] If the currently called Mapper class name exists in the cache definition hash table, it can be determined that the cache definition hash table contains a library table cache definition corresponding to the Mapper class name. Otherwise, it is determined that the cache definition hash table does not contain a library table cache definition corresponding to the Mapper class name.

[0088] If the cache definition hash table contains a library table cache definition corresponding to the class name, executing step S30 to determine whether a thread-level cache function corresponding to the library table cache definition is currently enabled;

[0089] In this step, if there is a library table cache definition corresponding to the currently called Mapper class name in the cache definition hash table, it is further determined whether the thread-level cache function corresponding to the library table cache definition is currently enabled.

[0090] In specific implementation, a cache function enable bit enabled can be used in the SysTransCacheDef domain object to control whether the thread-level cache function corresponding to the SysTransCacheDef domain object is enabled. By obtaining the enabled value, it can be determined whether the thread-level cache function corresponding to the library table cache definition is currently enabled. For example, if enabled=1 is detected, it is determined that the thread-level cache function corresponding to the library table cache definition is currently enabled. If enabled=0 is detected, it is determined that the thread-level cache function corresponding to the library table cache definition is not currently enabled.

[0091] If the thread-level cache function corresponding to the library table cache definition is currently enabled, step S40 is executed to perform corresponding thread-level cache data read and write operations according to the method name and the input parameters.

[0092] In this step, if the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation is performed according to the Mapper method name and the input parameters, wherein the Mapper method name is used to identify the type of thread-level cache data read and write operation performed, which includes data query, data insertion, data update, data deletion and other operations. For example, when the Mapper method name identifies the data query operation, first query the data from the cache data area of ​​the current thread according to the input parameters, if the corresponding data exists in the cache data area, then return the query result, if the corresponding data does not exist in the cache data area, then query from the database again, return the query result, and save the query result in the cache data area; when the Mapper method name identifies the data insertion operation, first insert the corresponding data in the database, and then save the inserted data in the cache data area of ​​the current thread according to the input parameters; when the Mapper method name identifies the data update operation, first update the corresponding data in the database, and then save the updated data in the cache data area of ​​the current thread according to the input parameters. In this way, different types of read and write operations on cache data are realized.

[0093] It should be noted that the cache in the cache data area mentioned in this embodiment is a thread-level cache. The cache data in the cache data area is only available to the current thread. The cache is automatically destroyed after the thread ends. The thread-level cache is particularly suitable for library tables that need to perform multiple operations on the same record in the same thread.

[0094] In this embodiment, when an instruction to call a database access interface is detected in a preset thread of an application, the class name, method name and input parameters of the currently called database access interface are obtained; the preset cache definition hash table is queried according to the class name to determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table; if so, it is determined whether the thread-level cache function corresponding to the library table cache definition is currently enabled; if the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation is performed according to the method name and the input parameters. Compared with the method of caching the query results of all library tables in the prior art, this method realizes fine-grained control of thread-level cache, that is, only when there is a library table cache definition corresponding to the class name of the currently called database access interface in the preset cache definition hash table, and the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operation will be performed, so that this embodiment improves the flexibility of the JVM local thread-level cache scheme.

[0095] Furthermore, based on the first embodiment of the cache processing method of the present invention, a second embodiment of the cache processing method of the present invention is proposed.

[0096] In this embodiment, before the above step S10, it may also include: when the application starts, reading a preset cache configuration table, wherein the cache configuration table records cache configuration information set based on the class names of different database access interfaces; generating a cache definition hash table according to the cache configuration information, and saving the cache definition hash table to a preset Java virtual machine level cache definition area.

[0097] In this embodiment, the cache definition needs to be loaded into the JVM memory when the application starts. In the specific implementation, the preset cache configuration table is first read, and the cache configuration information set based on the class name of different database access interfaces is recorded in the cache configuration table. The cache configuration information may include the class name of the interface for Mybatis to access the database, the Domain domain name for Mybatis to access the database, the primary key attribute field in the Domain, the cache function enable bit and description information. Specifically, the structure of the cache configuration table sys_trans_cache_def is shown in the following table:

[0098]

[0099] For example, there is a bank customer account information master table named ca_acct_mast, whose primary key is entity_code+acct_no. If it needs to be configured as a thread-level cache, the configuration is as follows:

[0100] mapper_name:CaAcctMastMapper

[0101] domain_name:CaAcctMast

[0102] primary_Key:entityCode,acctNo

[0103] enabled:1

[0104] description: Customer account information main table

[0105] After reading the cache configuration table, all records in the cache configuration table are obtained to obtain a linked list composed of SysTransCacheDef domain objects, and the linked list is reassembled into a cache definition hash table HashMap; in the cache definition hash table, the Key is the mapperName (Mapper class name) of the SysTransCacheDef domain object, and the value is the SysTransCacheDef domain object itself; then, the HashMap is saved to the preset JVM-level cache definition area for subsequent queries.

[0106] The above method loads the cache definition into the JVM memory when the application starts, thereby providing a prerequisite guarantee for subsequently querying the preset cache definition hash table according to the class name of the currently called database access interface.

[0107] Furthermore, the cache processing method may also include: receiving a modification instruction based on the cache configuration table, modifying the cache configuration information in the cache configuration table according to the modification instruction; generating a new cache definition hash table according to the modified cache configuration information; and updating the cache definition hash table stored in the Java virtual machine level cache definition area to the new cache definition hash table.

[0108] In this embodiment, the user can trigger a modification instruction to modify the above-mentioned cache configuration table. When the system receives a modification instruction based on the cache configuration table, the cache configuration information in the cache configuration table is modified according to the modification instruction, wherein the modification includes addition, deletion and change. For example, when the user wants to add a new cache definition, it only needs to insert a record in the cache configuration table; when the user wants to disable a certain cache, it only needs to delete the corresponding record in the cache configuration table, or change the enabled bit to 0. After that, the system generates a new cache definition hash table according to the modified cache configuration information, and updates the cache definition hash table stored in the Java virtual machine level cache definition area to the new cache definition hash table.

[0109] It should be noted that, in one embodiment, after the user modifies the cache configuration information in the cache configuration table, the user can manually trigger an update instruction to update the cache definition hash table; in another embodiment, a polling thread can be created to periodically trigger (for example, every 30 seconds) reading of all data in the cache configuration table, and the cache definition hash table can be updated based on the read data.

[0110] This embodiment provides a function for modifying the cache configuration table. There is no need to modify the code or configuration files, redeploy, or restart the system. The purpose of enabling or disabling the cache can be achieved by simply adding, deleting, or modifying the cache configuration table. The flexibility is very high.

[0111] Furthermore, based on the first embodiment of the cache processing method of the present invention, a third embodiment of the cache processing method of the present invention is proposed.

[0112] In this embodiment, the above-mentioned step S40 may include: when the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameters to obtain a first query result; determining whether the first query result is empty; if the first query result is empty, executing an operation of calling a database access interface, and saving the corresponding call result to the first thread-level cache data hash table.

[0113] When the Mapper method name identifies a data query operation without a record lock, the domain name domain_name of the database to be accessed is first obtained according to the input parameters, and then the first query result is obtained from the preset first thread-level cache data hash table according to domain_name and the input parameters. The first thread-level cache data hash table is stored in the preset first thread-level cache data area, and its structure is shown in the following table:

[0114] Key Value domainName1+primaryKey1 domain1 domainName1+primaryKey2 domain2 domainName2+primaryKey3 domain3 …… ……

[0115] Among them, Key is the domain name + primary key name, value is the domain object, and a domain object corresponds to a record in the database table.

[0116] If the first query result is not empty, it means that the corresponding data exists in the first thread-level cache data area, and the query result can be returned at this time; if the first query result is empty, it means that the corresponding data does not exist in the first thread-level cache data area, and the operation of calling the database access interface is executed to query the corresponding data from the database, and the corresponding call result is saved in the first thread-level cache data hash table, so that the next time the same data is queried, it can be read directly from the cache.

[0117] Furthermore, the above step S40 may also include: when the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result; determining whether the second query result is empty; if the second query result is empty, executing an operation of calling a database access interface, and saving the corresponding call result to the first thread-level cache data hash table and the second thread-level cache data hash table.

[0118] In this embodiment, the record lock means that when a process is reading or modifying a part of a file, it can prevent other processes from modifying the same file area. When the Mapper method name identifies a data query operation with a record lock (generally used when updating data), the domain name domain_name of the database to be accessed is first obtained according to the input parameters, and then the second query result is obtained from the preset second thread-level cache data hash table according to domain_name and the input parameters. Among them, the second thread-level cache data hash table is stored in the preset second thread-level cache data area, and its structure is similar to the above-mentioned first thread-level cache data hash table, which will not be repeated here.

[0119] If the second query result is not empty, it means that the corresponding data exists in the second thread-level cache data area, and the query result can be returned at this time; if the second query result is empty, it means that the corresponding data does not exist in the second thread-level cache data area, and the operation of calling the database access interface is executed to lock and query the corresponding data from the database, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table, so that the same data can be directly read from the cache next time it is queried.

[0120] It should be noted that the purpose of setting the first thread-level cache data hash table and the second thread-level cache data hash table is to distinguish between data query operations without record locks and data query operations with record locks. Through this setting, if a data query operation without record locks is performed first, and then a data query operation with record locks is performed on the same record, it is still necessary to operate the database. If a data query operation with record locks is performed first, and then a data query operation without record locks is performed on the same record, it is not necessary to query the database again, thereby improving data query efficiency.

[0121] Furthermore, the above step S40 may also include: when the method name identifies a data update operation, executing an operation of calling a database access interface to update the corresponding data in the database, and saving the incoming parameters to the first thread-level cache data hash table; determining whether there is an update object corresponding to the incoming parameters in the second thread-level cache data hash table, and if so, updating the update object according to the incoming parameters.

[0122] When the Mapper method name identifies a data update operation, the operation of calling the database access interface is executed to update the corresponding data in the database, and the incoming parameters are saved in the first thread-level cache data hash table, and then it is determined whether there is an update object corresponding to the incoming parameter in the second thread-level cache data hash table. If so, the update object is updated according to the incoming parameter to ensure that the second thread-level cache data hash table stores the latest data; if not, no processing is performed.

[0123] Furthermore, the above step S40 may also include: when the method name identifies a data insertion operation, executing an operation of calling a database access interface to insert corresponding data into the database, and saving the input parameters into the first thread-level cache data hash table.

[0124] When the Mapper method name identifies a data insertion operation, an operation of calling the database access interface is executed to insert corresponding data into the database, and the incoming parameters are saved in the first thread-level cache data hash table to ensure consistency between the data in the first thread-level cache data hash table and the database.

[0125] Furthermore, the above step S40 may also include: when the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database; deleting corresponding data in the first thread-level cache data hash table and the second thread-level cache data hash table according to the incoming parameters.

[0126] When the Mapper method name identifies a data deletion operation, an operation of calling the database access interface is executed to delete the corresponding data in the database; then, the corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the passed parameters, so that the data in the first thread-level cache data hash table and the second thread-level cache data hash table remain consistent with the database.

[0127] Through the above method, cache processing of data query, insertion and update operations is realized. Compared with the existing technology that can only cache data query operations, the comprehensiveness of the JVM cache function is improved, which is conducive to improving the corresponding data reading and writing efficiency; in addition, the above thread-level read and write cache mechanism is completely decoupled from the business logic. Business layer developers do not need to be aware of the existence of the cache. They only need to call the database access interface to read and write the database. Compared with the existing mechanism of executing cache reading and writing in the business logic processing project, it reduces the coding complexity, improves the coding efficiency, and has higher flexibility.

[0128] The present invention also provides a cache processing device. The cache processing device comprises:

[0129] The acquisition module is used to acquire the class name, method name and input parameters of the currently called database access interface when an instruction to call the database access interface is detected in a preset thread of the application program;

[0130] A first judgment module is used to query a preset cache definition hash table according to the class name, and judge whether there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0131] A second judgment module is used to judge whether the thread-level cache function corresponding to the library table cache definition is currently enabled if there is a library table cache definition corresponding to the class name in the cache definition hash table;

[0132] The execution module is used to execute the corresponding thread-level cache data read and write operation according to the method name and the input parameters if the thread-level cache function corresponding to the library table cache definition is currently enabled.

[0133] Furthermore, the cache processing device also includes:

[0134] A reading module, used to read a preset cache configuration table when the application is started, wherein the cache configuration table records cache configuration information set based on class names of different database access interfaces;

[0135] The generation module is used to generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table to a preset Java virtual machine level cache definition area.

[0136] Furthermore, the cache processing device also includes:

[0137] A modification module, configured to receive a modification instruction based on the cache configuration table, and modify the cache configuration information in the cache configuration table according to the modification instruction;

[0138] The generating module is further used to generate a new cache definition hash table according to the modified cache configuration information;

[0139] An update module is used to update the cache definition hash table stored in the Java virtual machine level cache definition area to the new cache definition hash table.

[0140] Furthermore, the execution module is also used for:

[0141] When the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameter to obtain a first query result;

[0142] Determine whether the first query result is empty;

[0143] If the first query result is empty, an operation of calling a database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table.

[0144] Furthermore, the execution module is also used for:

[0145] When the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result;

[0146] Determine whether the second query result is empty;

[0147] If the second query result is empty, an operation of calling the database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table.

[0148] Furthermore, the execution module is also used for:

[0149] When the method name identifies a data update operation, executing an operation of calling a database access interface to update corresponding data in the database, and saving the input parameters into the first thread-level cache data hash table;

[0150] It is determined whether there is an update object corresponding to the input parameter in the second thread-level cache data hash table; if so, the update object is updated according to the input parameter.

[0151] Furthermore, the execution module is also used for:

[0152] When the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data into the database, and the input parameters are saved in the first thread-level cache data hash table.

[0153] Furthermore, the execution module is also used for:

[0154] When the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database;

[0155] Corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the input parameters.

[0156] The methods executed by the above-mentioned program modules can refer to the various embodiments of the cache processing method of the present invention, which will not be described in detail here.

[0157] The present invention also provides a computer-readable storage medium.

[0158] The computer-readable storage medium of the present invention stores a cache processing program, and when the cache processing program is executed by a processor, the steps of the cache processing method described above are implemented.

[0159] Among them, the method implemented when the cache processing program running on the processor is executed can refer to the various embodiments of the cache processing method of the present invention, and will not be repeated here.

[0160] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0161] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0162] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0163] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A cache processing method, characterized in that: The cache processing method comprises the following steps: When the application is started, a preset cache configuration table is read, wherein the cache configuration information set based on the class names of different database access interfaces is recorded in the cache configuration table; Generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table to a preset Java virtual machine level cache definition area; the cache definition hash table is a HashMap, and the key in the HashMap is the class name; When an instruction to call a database access interface is detected in a preset thread of the application, the class name, method name and input parameters of the currently called database access interface are obtained; Query a preset cache definition hash table according to the class name, and determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table; If there is a library table cache definition corresponding to the class name in the cache definition hash table, determining whether a thread-level cache function corresponding to the library table cache definition is currently enabled; If the thread-level cache function corresponding to the library table cache definition is currently enabled, the corresponding thread-level cache data read and write operations are performed according to the method name and the input parameters.

2. The cache processing method according to claim 1, characterized in that: The cache processing method also includes: receiving a modification instruction based on the cache configuration table, and modifying the cache configuration information in the cache configuration table according to the modification instruction; Generate a new cache definition hash table according to the modified cache configuration information; The cache definition hash table stored in the Java virtual machine level cache definition area is updated to the new cache definition hash table.

3. The cache processing method according to claim 1, characterized in that: The step of executing the corresponding thread-level cache data read and write operation according to the method name and the input parameters comprises: When the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameters to obtain a first query result; the cache data hash table includes a domain name and a primary key name, and domain objects corresponding to the domain name and the primary key name; Determine whether the first query result is empty; If the first query result is empty, an operation of calling a database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table.

4. The cache processing method according to claim 3, characterized in that: The step of executing the corresponding thread-level cache data read and write operation according to the method name and the input parameters comprises: When the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result; Determine whether the second query result is empty; If the second query result is empty, an operation of calling the database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table.

5. The cache processing method according to claim 4, characterized in that: The step of executing the corresponding thread-level cache data read and write operation according to the method name and the input parameters comprises: When the method name identifies a data update operation, executing an operation of calling a database access interface to update corresponding data in the database, and saving the input parameters into the first thread-level cache data hash table; It is determined whether there is an update object corresponding to the input parameter in the second thread-level cache data hash table; if so, the update object is updated according to the input parameter.

6. The cache processing method according to claim 5, characterized in that: The step of executing the corresponding thread-level cache data read and write operation according to the method name and the input parameters comprises: When the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data into the database, and the input parameters are saved in the first thread-level cache data hash table.

7. The cache processing method according to claim 6, characterized in that: The step of executing the corresponding thread-level cache data read and write operation according to the method name and the input parameters comprises: When the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database; Corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the input parameters.

8. A cache processing device, characterized in that: The cache processing device comprises: A reading module, used to read a preset cache configuration table when the application is started, wherein the cache configuration table records cache configuration information set based on class names of different database access interfaces; A generation module, used to generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table to a preset Java virtual machine level cache definition area; the cache definition hash table is a HashMap, and the key in the HashMap is the class name; The acquisition module is used to acquire the class name, method name and input parameters of the currently called database access interface when an instruction to call the database access interface is detected in a preset thread of the application program; A first judgment module is used to query a preset cache definition hash table according to the class name, and judge whether there is a library table cache definition corresponding to the class name in the cache definition hash table; A second judgment module is used to judge whether the thread-level cache function corresponding to the library table cache definition is currently enabled if there is a library table cache definition corresponding to the class name in the cache definition hash table; The execution module is used to execute the corresponding thread-level cache data read and write operation according to the method name and the input parameters if the thread-level cache function corresponding to the library table cache definition is currently enabled.

9. The cache processing device according to claim 8, characterized in that: The cache processing device also includes: A modification module, configured to receive a modification instruction based on the cache configuration table, and modify the cache configuration information in the cache configuration table according to the modification instruction; The generating module is further used to generate a new cache definition hash table according to the modified cache configuration information; An update module is used to update the cache definition hash table stored in the Java virtual machine level cache definition area to the new cache definition hash table.

10. The cache processing device according to claim 8, characterized in that: The execution module is also used for: When the method name identifies a data query operation without a record lock, querying a preset first thread-level cache data hash table according to the input parameters to obtain a first query result; the cache data hash table includes a domain name and a primary key name, and domain objects corresponding to the domain name and the primary key name; Determine whether the first query result is empty; If the first query result is empty, an operation of calling a database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table.

11. The cache processing device according to claim 10, characterized in that: The execution module is also used for: When the method name identifies a data query operation with a record lock, querying a preset second thread-level cache data hash table according to the input parameters to obtain a second query result; Determine whether the second query result is empty; If the second query result is empty, an operation of calling the database access interface is executed, and the corresponding call result is saved in the first thread-level cache data hash table and the second thread-level cache data hash table.

12. The cache processing device according to claim 11, characterized in that: The execution module is also used for: When the method name identifies a data update operation, executing an operation of calling a database access interface to update corresponding data in the database, and saving the input parameters into the first thread-level cache data hash table; It is determined whether there is an update object corresponding to the input parameter in the second thread-level cache data hash table; if so, the update object is updated according to the input parameter.

13. The cache processing device according to claim 12, characterized in that: The execution module is also used for: When the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data into the database, and the input parameters are saved in the first thread-level cache data hash table.

14. The cache processing device according to claim 13, characterized in that: The execution module is also used for: When the method name identifies a data deletion operation, executing an operation of calling a database access interface to delete corresponding data in the database; Corresponding data is deleted from the first thread-level cache data hash table and the second thread-level cache data hash table according to the input parameters.

15. A cache processing device, characterized in that: The cache processing device comprises: a memory, a processor, and a cache processing program stored in the memory and executable on the processor. When the cache processing program is executed by the processor, the steps of the cache processing method according to any one of claims 1 to 7 are implemented.

16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a cache processing program, and when the cache processing program is executed by a processor, the steps of the cache processing method according to any one of claims 1 to 7 are implemented.