WO2020211554A1 - 缓存处理方法、装置、设备及计算机可读存储介质 - Google Patents

缓存处理方法、装置、设备及计算机可读存储介质 Download PDF

Info

Publication number
WO2020211554A1
WO2020211554A1 PCT/CN2020/077614 CN2020077614W WO2020211554A1 WO 2020211554 A1 WO2020211554 A1 WO 2020211554A1 CN 2020077614 W CN2020077614 W CN 2020077614W WO 2020211554 A1 WO2020211554 A1 WO 2020211554A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
thread
definition
hash table
data
Prior art date
Application number
PCT/CN2020/077614
Other languages
English (en)
French (fr)
Inventor
刘建波
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2020211554A1 publication Critical patent/WO2020211554A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application

Definitions

  • This application relates to the technical field of financial technology (Fintech), and in particular to a cache processing method, apparatus, device, and computer-readable storage medium.
  • the main purpose of this application is to propose a cache processing method, device, device, and computer-readable storage medium, which aim to improve the flexibility of the JVM local thread-level cache solution.
  • the present application provides a cache processing method, the cache processing method includes the following steps:
  • 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 incoming parameters.
  • the present application also provides a cache processing device, and the cache processing device includes:
  • the obtaining module is used to obtain the class name, method name, and incoming parameters of the currently called database access interface when an instruction to call the database access interface is detected in the preset thread of the application program;
  • the first judgment module is configured 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;
  • the second determining module is configured to determine whether the thread-level cache 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 Features;
  • the execution module is configured to, if the thread-level cache function corresponding to the library table cache definition is currently enabled, execute the corresponding thread-level cache data read and write operation according to the method name and the incoming parameters.
  • the present application also provides a cache processing device, the cache processing device includes: a memory, a processor, and a cache processing stored on the memory and running on the processor A program, when the cache processing program is executed by the processor, the steps of the cache processing method described above are implemented.
  • the present application also provides a computer-readable storage medium having a cache processing program stored on the computer-readable storage medium, and when the cache processing program is executed by a processor, the above The steps of the cache processing method.
  • the application detects the instruction to call the database access interface in the preset thread of the application, the current The class name, method name, and incoming parameters of the previously called database access interface; query a preset cache definition hash table according to the class name, and determine whether there is a library corresponding to the class name in the cache definition hash table Table cache definition; if it exists, determine 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, then according to the method The name and the incoming parameters perform corresponding thread-level cache data read and write operations.
  • this method realizes the fine-grained control of thread-level caching, that is, only when the preset cache definition hash table exists and the currently called When the library table cache definition corresponding to the class name of the database access interface, 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 operations will be executed, so this application improves The flexibility of JVM local thread-level caching scheme.
  • FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in a solution of an embodiment of the present application
  • FIG. 2 is a schematic flowchart of a first embodiment of a cache processing method of this application.
  • FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in a solution of an embodiment of the present application.
  • the cache processing device in this embodiment of the application may be a PC or a server device, on which a Java virtual machine runs
  • 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.
  • the communication bus 1002 is used to implement 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, Line 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
  • the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
  • FIG. 1 does not constitute a limitation on the device, and may include more or less components than shown in the figure, or combine certain components, or different component arrangements .
  • a 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.
  • the network interface 1004 is mainly used to connect to a background server and perform data communication with the background server;
  • the user interface 1003 is mainly used to connect to a client (user side) and perform data communication with the client;
  • the processor 1001 may be used to call a cache processing program stored in the memory 1005, and perform operations in the following cache processing method.
  • FIG. 2 is a schematic flowchart of a first embodiment of a cache processing method of this application, and the method includes
  • Step S10 when an instruction to call a database access interface is detected in the preset thread of the application program, obtain the class name, method name, and incoming parameters of the currently called database access interface;
  • the cache processing method of this embodiment is applied to a cache processing device, and a JVM (J ava Virtual Machine) (J ava Virtual Machine) (J ava Virtual Machine) (J ava Virtual Machine)
  • JVM Java virtual machine
  • JVM uses a Java programming language-based data persistence framework such as Mybatis or Hibernate to implement operations on the database.
  • Java programming language-based data persistence framework such as Mybatis or Hibernate
  • financial database tables such as accounting information tables, account opening information tables, financial transaction information tables, etc.
  • caching technology will be used to meet the concurrency and access speed of financial services. Claim.
  • the operation of the database using Mybatis is taken as an example for description.
  • the interface of Mybatis to access the database is called Mapper.
  • Mapper The interface of Mybatis to access the database.
  • Mapper When the JVM detects an instruction to call the database access interface Mapper in the preset thread of the application, it obtains the currently called Mapper class name, Mapper method name and incoming parameters, among which, incoming parameters Used to represent the domain object to be read and written, a domain object Corresponds to a database table record.
  • interceptors can be defined on all Mappers in advance, such as:
  • 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 its methods, thereby ensuring that the interceptor can intercept access Database code;
  • the Mybatis code generator may not be used, as long as the Mybatis Mapper naming and its method naming rules are unified, the interceptor can also intercept it
  • Step S20 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;
  • the preset cache definition hash table is queried according to the obtained Mapper class name, and it is determined whether there is a library table cache definition corresponding to the Mapper class name in the cache definition hash table.
  • a JVM-level cache definition area can be set in the system in advance.
  • the cache definition area is used to store a cache definition hash table.
  • the cache definition hash table is represented as a HashMap, and the HashMap implements "Key -Value key-value pair" interface, the structure is as follows:
  • Key is the mapperName (Mapper class name) of the SysTransCacheDef domain object, and value is the SysTransCacheDef domain object itself.
  • step S30 is executed to determine whether the thread-level cache function corresponding to the library table cache definition is currently enabled;
  • a cache function enable bit enable d in the SysTransCacheDef domain object can be used to control whether to enable the thread-level cache function corresponding to the SysTransCacheDef domain object.
  • step S40 is executed, and corresponding thread-level cache data read and write operations are performed according to the method name and the incoming parameters.
  • the corresponding thread-level cache data read and write operations are performed according to the Mapper method name and the incoming parameters, where the Mapper method name is used for Identifies the type of thread-level cache data read and write operations performed, including operations such as data query, data insertion, data update, and data deletion.
  • the Mapper method name identifies a data query operation
  • the data is first queried from the cache data area of the current thread according to the incoming parameters. If the corresponding data exists in the cache data area, the query result is returned.
  • the corresponding data is then queried from the database, and the query result is returned, and the query result is saved 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 according to the transmission The input parameter saves the inserted data in the cache data area of the current thread; when the Mapper method name identifies the data update operation, the corresponding data in the database is updated first, and then the updated data is saved in the current according to the input parameters In the cache data area of the thread.
  • the caches in the cache data area mentioned in this embodiment are all thread-level caches.
  • 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 level of caching is especially suitable for library tables that require multiple operations on the same record in the same thread.
  • the class name, method name, and incoming parameters of the currently called database access interface are acquired; and the preset is queried according to the class name Determine whether there is a library table cache definition corresponding to the class name in the cache definition hash table; if it exists, determine whether the thread level corresponding to the library table cache definition is currently enabled Cache function; if the thread-level cache function corresponding to the library table cache definition is currently enabled, execute the corresponding thread-level cache data read and write operation according to the method name and the incoming parameters.
  • this method realizes the fine-grained control of thread-level caching, that is, only when the preset cache definition hash table exists and the currently called When the library table cache definition corresponding to the class name of the database access interface, 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 operations will be executed, so this embodiment improves The flexibility of the JVM local thread-level caching scheme is improved.
  • step S10 it may further include: when the application is started, reading a preset cache configuration table, where the cache configuration table records class names based on different database access interfaces Set cache configuration information; generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table in a preset java virtual machine-level cache definition area.
  • the cache definition needs to be loaded into the JVM memory when the application is started.
  • the cache configuration table records cache configuration information set based on the class names of different database access interfaces, and the cache configuration information may include the class name of the interface through which Mybatis accesses the database. , Mybatis access to the database Domain domain name, primary key attribute field in the Domain, cache function enable bit and description information.
  • the structure of the cache configuration table sys_trans_cache_def is shown in the following table:
  • mapper_name CaAcctMastMapper
  • the above method provides a prerequisite guarantee for the subsequent query of the preset cache definition hash table according to the class name of the currently called database access interface by loading the cache definition into the JVM memory when the application is started.
  • the cache processing method may further include: receiving a modification instruction based on the cache configuration table Command: modify 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; store the java virtual machine-level cache definition area The cache definition hash table is updated to the new cache definition hash table.
  • the user can trigger a modification instruction to modify the above-mentioned cache configuration table.
  • the system receives a modification instruction based on the cache configuration table, it modifies the cache configuration information in the cache configuration table according to the modification instruction, and the modification includes addition, deletion, and modification.
  • the modification includes addition, deletion, and modification.
  • 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.
  • the user can manually trigger an update instruction to update the cache definition hash table; in another embodiment, the user can also use A polling thread is created, and the polling thread is triggered periodically (for example, every 30 seconds) to read all the data in the cache configuration table, and update the cache definition hash table according to the read data.
  • this embodiment does not need to modify code or configuration files, does not need to redeploy, and does not need to restart the system. It only needs to add, delete, or modify the cache configuration table. To achieve the purpose of enabling and disabling the cache, the degree of flexibility is very high.
  • the above 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 incoming parameter , Obtain the first query result; determine whether the first query result is empty; if the first query result is empty, perform the operation of calling the database access interface, and save the corresponding calling result to the first thread Level cache data in the hash table.
  • the Mapper method name identifies a data query operation without a record lock
  • 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: [] [table 3]
  • Key is domain name + primary key name
  • value is domain object
  • one domain object corresponds to a record in the database table.
  • the first query result is not empty, it means that there is corresponding data in the first thread-level cache data area, and the query result is returned at this time; if the first query result is empty, it means the first thread-level cache There is no corresponding data in the data area.
  • the operation of calling the database access interface is executed to query the corresponding data from the database, and the corresponding calling result is saved in the first thread-level cache data hash table for download Read the same data directly from the cache when querying the same data each time.
  • step S40 may further include: when the method name identifies the data query operation of adding a record lock, query a preset second thread-level cache data hash table according to the incoming parameters to obtain the first 2. Query result; determine whether the second query result is empty; if the second query result is empty, perform the operation of calling the database access interface, and save the corresponding calling result to the first thread-level cache data
  • the hash table and the second thread-level cache data hash table when the method name identifies the data query operation of adding a record lock, query a preset second thread-level cache data hash table according to the incoming parameters to obtain the first 2.
  • Query result determine whether the second query result is empty; if the second query result is empty, perform the operation of calling the database access interface, and save the corresponding calling result to the first thread-level cache data
  • the hash table and the second thread-level cache data hash table when the method name identifies the data query operation of adding a record lock, query a preset second thread-level cache data hash table
  • the record lock means that when a process is reading or modifying a certain part of a file, it can prevent other processes from modifying the same file area.
  • the Mapper method name identifies the data query operation with record lock (usually used when updating data)
  • the second thread-level cache data hash table is stored in a preset second thread-level cache data area, and its structure is similar to the above-mentioned first thread-level cache data hash table, and will not be repeated here.
  • the second query result is not empty, it means that there is corresponding data in the second thread-level cache data area, and the query result is returned at this time; if the second query result is empty, it means the second thread-level cache Data area There is no corresponding data, the operation of calling the database access interface is executed at this time to lock and query the corresponding data from the database, and save the corresponding call result to the first thread-level cache data hash table and the second thread-level cache In the data hash table, it can be directly read from the cache when the same data is queried next time.
  • the purpose of setting the first thread-level cache data hash table and the second thread-level cache data hash table is to distinguish data query operations without record locks and data query operations with record locks.
  • you first perform data query operations without record locks, and then perform data query operations with record locks on the same records you still need to operate the database. If you perform data query operations with record locks first, then perform the same data query operations. The record performs a data query operation without a record lock, and there is no need to query the database again, thereby improving the efficiency of data query.
  • step S40 may also include: when the method name identifies a data update operation, performing an operation of invoking a database access interface to update the corresponding data in the database, and save the incoming parameters to In the first thread-level cache data hash table; judging whether there is an update object corresponding to the incoming parameter in the second thread-level cache data hash table, and if so, according to the incoming parameter pair The update object is updated.
  • the Mapper method name identifies the data update operation
  • the operation of calling the database access interface is performed 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 judged 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 What is saved is the latest data; if it does not exist, no processing is done.
  • step S40 may further include: when the method name identifies the data insertion operation, performing an operation of invoking the database access interface to insert the corresponding data in the database, and save the incoming parameters to The first thread-level cache data hash table.
  • Mapper method name identifies when the method name identifies a data insertion operation, an operation of calling a database access interface is performed to insert corresponding data in the database, and the incoming parameters are saved in the first thread Level cache data hash table, so that the data in the first thread level cache data hash table is consistent with the database.
  • step S40 may further include: when the method name identifies a data deletion operation, performing an operation of invoking a database access interface to delete the corresponding data in the database; The parameter deletes corresponding data in the first thread-level cache data hash table and the second thread-level cache data hash table.
  • the Mapper method name identifies when the method name identifies a data deletion operation
  • the operation of calling the database access interface is performed to delete the corresponding data in the database; then, the data is cached at the first thread level according to the incoming parameters.
  • Corresponding data is deleted from the Hashtable and the second thread-level cache data hash table, so that the data in the first thread-level cache data hash table and the second thread-level cache data hash table are consistent with the database.
  • the data query, insert, and update operations are cached.
  • the data query operations can be cached, which improves the comprehensiveness of the JVM cache function, thereby helping to improve Corresponding data read and write efficiency;
  • the thread-level read-write cache mechanism is completely decoupled from the business logic, and business layer developers do not need to perceive the existence of the cache, but only need to call the database access interface to read and write the database, which is compared with the current situation.
  • the cache processing device includes:
  • the obtaining module is used to obtain the class name, method name and incoming parameters of the currently called database access interface when an instruction to call the database access interface is detected in the preset thread of the application;
  • the first judgment module is configured 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;
  • the second determining module is configured to determine whether the thread-level cache 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 Function; [0084] The execution module is used to execute the corresponding thread-level cache data read and write operation according to the method name and the incoming parameters if the thread-level cache function corresponding to the library table cache definition is currently enabled.
  • the cache processing device further includes:
  • the reading module is configured to read a preset cache configuration table when the application is started, and the cache configuration table records cache configuration information set based on the class names of different database access interfaces;
  • the generating module is configured to generate a cache definition hash table according to the cache configuration information, and save the cache definition hash table in a preset java virtual machine-level cache definition area.
  • the cache processing device further includes: [0089] 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 configured to generate a new cache definition hash table according to the modified cache configuration information
  • An update module configured to update the cache definition hash table stored in the java virtual machine-level cache definition area to the new cache definition hash table.
  • execution module is also used for:
  • execution module is also used for:
  • execution module is also used for:
  • execution module is also used for:
  • execution module is also used for:
  • This application also provides a computer-readable storage medium.
  • the computer-readable storage medium of the present application 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.
  • the method implemented when the cache processing program running on the processor is executed can refer to each embodiment of the application cache processing method, which will not be repeated here.
  • the technical solution of the present application essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium as described above (such as ROM/RAM , Magnetic disks, and optical disks), including several instructions to enable a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the method described in each embodiment of the present application.
  • a terminal device which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.

Abstract

一种缓存处理方法、缓存处理装置、设备和计算机可读存储介质,提高了JVM本地线程级缓存方案的灵活性。该方法包括:当检测到应用程序调用数据库访问接口的指令时,获取当前调用的数据库访问接口的类名、方法名和传入参数(S10);根据所述类名查询预设的缓存定义哈希表,判断所述缓存定义哈希表中是否存在与所述类名对应的库表缓存定义(S20);是,则判断当前是否已启用与所述库表缓存定义对应的线程级缓存功能(S30);是,则根据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作(S40)。

Description

发明名称: 缓存处理方法、 装置、 设备及计算机可读存储介质
[0001] 本申请要求于 2019年 4月 19日提交中国专利局、 申请号为 201910321455. 6、 发 明名称为“缓存处理方法、 装置、 设备及计算机可读存储介质” 的中国专利申 请的优先权, 其全部内容通过引用结合在申请中。
技术领域
[0002] 本申请涉及金融科技 (Fintech) 技术领域, 尤其涉及缓存处理方法、 装置、 设备及计算机可读存储介质。
背景技术
[0003] 近年来, 随着互联网技术, 尤其是互联网金融科技 (Fintech) 的飞速发展, 越来越多的技术 (大数据、 分布式、 区块链 Blockchain、 人工智能等) 应用在 金融领域, 金融数据也呈几何级增长, 以大型商业银行为例, 通常它们拥有成 百上千个业务系统以及上亿用户的海量数据, 这种情况下, 对数据存储的数据 量, 并发性和响应速度都提出了更高要求。 目前在金融领域, 在使用 JVM(Java Virtual Machine, Java虚拟机) 访问金融数据库表时会用到缓存技术, 即, 将 要操作的数据库表记录加载到本地 JVM内存, 以提高程序访问数据的速度, 并降 低数据库压力。
[0004] 在现有的基于 Java程序语言的数据持久化框架 (如 Mybatis 、 Hibernate) 中 , 线程级缓存无法做到细粒度控制, 即一旦缓存启用之后, 会对所有库表的查 询结果做缓存, 这会导致占用过多的内存空间, 影响系统性能。 因而, 现有的 J VM本地线程级缓存方案的灵活性还有待提高。
发明概述
技术问题
问题的解决方案
技术解决方案
[0005] 本申请的主要目的在于提出一种缓存处理方法、 装置、 设备及计算机可读存储 介质, 旨在提高 JVM本地线程级缓存方案的灵活性。 [0006] 为实现上述目的, 本申请提供一种缓存处理方法, 所述缓存处理方法包括如下 步骤:
[0007] 当检测到应用程序调用数据库访问接口的指令时, 获取当前调用的数据库访问 接口的类名、 方法名和传入参数;
[0008] 根据所述类名查询预设的缓存定义哈希表, 判断所述缓存定义哈希表中是否存 在与所述类名对应的库表缓存定义;
[0009] 若所述缓存定义哈希表中存在与所述类名对应的库表缓存定义, 则判断当前是 否已启用与所述库表缓存定义对应的线程级缓存功能;
[0010] 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根据所述方法名 和所述传入参数执行对应的线程级缓存数据读写操作。
[0011] 此外, 为实现上述目的, 本申请还提供一种缓存处理装置, 所述缓存处理装置 包括:
[0012] 获取模块, 用于当在应用程序的预设线程中检测到调用数据库访问接口的指令 时, 获取当前调用的数据库访问接口的类名、 方法名和传入参数;
[0013] 第一判断模块, 用于根据所述类名查询预设的缓存定义哈希表, 判断所述缓存 定义哈希表中是否存在与所述类名对应的库表缓存定义;
[0014] 第二判断模块, 用于若所述缓存定义哈希表中存在与所述类名对应的库表缓存 定义, 则判断当前是否已启用与所述库表缓存定义对应的线程级缓存功能;
[0015] 执行模块, 用于若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则 根据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[0016] 此外, 为实现上述目的, 本申请还提供一种缓存处理设备, 所述缓存处理设备 包括: 存储器、 处理器及存储在所述存储器上并可在所述处理器上运行的缓存 处理程序, 所述缓存处理程序被所述处理器执行时实现如上所述的缓存处理方 法的步骤。
[0017] 此外, 为实现上述目的, 本申请还提供一种计算机可读存储介质, 所述计算机 可读存储介质上存储有缓存处理程序, 所述缓存处理程序被处理器执行时实现 如上所述的缓存处理方法的步骤。
[0018] 本申请在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获取当 前调用的数据库访问接口的类名、 方法名和传入参数; 根据所述类名查询预设 的缓存定义哈希表, 判断所述缓存定义哈希表中是否存在与所述类名对应的库 表缓存定义; 若存在, 则判断当前是否已启用与所述库表缓存定义对应的线程 级缓存功能; 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根 据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作。 这种方式 相比于现有技术中对所有库表的查询结果做缓存的方式, 实现了线程级缓存的 细粒度控制, 即, 只有当预设的缓存定义哈希表中存在与当前调用的数据库访 问接口的类名对应的库表缓存定义, 且当前已启用与所述库表缓存定义对应的 线程级缓存功能时, 才会执行对应的线程级缓存数据读写操作, 从而本申请提 高了 JVM本地线程级缓存方案的灵活性。
发明的有益效果
对附图的简要说明
附图说明
[0019] 图 1是本申请实施例方案涉及的硬件运行环境的设备结构示意图;
[0020] 图 2为本申请缓存处理方法第一实施例的流程示意图。
[0021] 本申请目的的实现、 功能特点及优点将结合实施例, 参照附图做进一步说明。
发明实施例
本发明的实施方式
[0022] 应当理解, 此处所描述的具体实施例仅仅用以解释本申请, 并不用于限定本申 请。
[0023] 如图 1所示, 图 1是本申请实施例方案涉及的硬件运行环境的设备结构示意图。
[0024] 本申请实施例缓存处理设备可以是 PC机或服务器设备, 其上运行有 Java虚拟机
[0025] 如图 1所示, 该缓存处理设备可以包括: 处理器 1001, 例如 CPU, 网络接口 1004 , 用户接口 1003, 存储器 1005, 通信总线 1002。 其中, 通信总线 1002用于实现 这些组件之间的连接通信。 用户接口 1003可以包括显示屏 (Display) 、 输入单 元比如键盘 (Keyboard) , 可选用户接口 1003还可以包括标准的有线接口、 无 线接口。 网络接口 1004可选的可以包括标准的有线接口、 无线接口 (如 WI-FI接 口) 。 存储器 1005可以是高速 RAM存储器, 也可以是稳定的存储器 (non-volati le
memory) , 例如磁盘存储器。 存储器 1005可选的还可以是独立于前述处理器 100 1的存储装置。
[0026] 本领域技术人员可以理解, 图 1中示出的设备结构并不构成对设备的限定, 可 以包括比图示更多或更少的部件, 或者组合某些部件, 或者不同的部件布置。
[0027] 如图 1所示, 作为一种计算机存储介质的存储器 1005中可以包括操作系统、 网 络通信模块、 用户接口模块以及缓存处理程序。
[0028] 在图 1所示的设备中, 网络接口 1004主要用于连接后台服务器, 与后台服务器 进行数据通信; 用户接口 1003主要用于连接客户端 (用户端) , 与客户端进行 数据通信; 而处理器 1001可以用于调用存储器 1005中存储的缓存处理程序, 并 执行下述缓存处理方法中的操作。
[0029] 基于上述硬件结构, 提出本申请缓存处理方法实施例。
[0030] 参照图 2, 图 2为本申请缓存处理方法第一实施例的流程示意图, 所述方法包括
[0031] 步骤 S10, 当在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获取当前调用的数据库访问接口的类名、 方法名和传入参数;
[0032] 本实施例缓存处理方法应用于缓存处理设备, 该缓存处理设备上运行有 JVM(J ava Virtual
Machine, Java虚拟机) , JVM采用 Mybatis或 Hibernate等基于 Java程序语言的 数据持久化框架实现对数据库进行操作。 比如在金融领域中, 经常需要使用 JVM 访问金融数据库表, 如账务信息表, 开户信息表, 金融交易信息表等, 这一过 程中会用到缓存技术以满足金融业务的并发性和访问速度要求。
[0033] 在本实施例中, 以采用 Mybatis对数据库进行操作为例进行说明。 Mybatis访 问数据库的接口称为 Mapper, 当 JVM在应用程序的预设线程中检测到调用数据库 访问接口 Mapper的指令时, 获取当前调用的 Mapper类名、 Mapper方法名和传入 参数, 其中, 传入参数用于表示要进行读写的域 (Domain) 对象, 一个域对象 对应于一条数据库表记录。
[0034] 具体地, 可以预先在所有 Mapper上定义拦截器, 比如:
[0035] iAround (^execution (public 氺 com. xxx. . mapper. . *. * (. . ) ) &&
bean (*Mapper)〃), 表示对所有 Mapper中的所有方法都执行拦截。 系统运行时, 每次对 Mapper的调用, 都会被拦截器拦截, 拦截器获取到当次调用的 Mapper类 名、 Mapper方法名和传入参数。
[0036] 需要说明的是, 在本实施例中, 可以采用 Mybatis代码生成器生成访问数据库 的代码, 以提高开发效率, 并使得所有 Mapper和其方法的命名规则统一, 从而 保证拦截器能够拦截访问数据库的代码; 此外也可以不采用 Mybatis代码生成器 , 只要 Mybatis Mapper命名和其方法命名规则统一, 拦截器也可对其进行拦截
[0037] 步骤 S20, 根据所述类名查询预设的缓存定义哈希表, 判断所述缓存定义哈希 表中是否存在与所述类名对应的库表缓存定义;
[0038] 该步骤中, 根据上述获取到的 Mapper类名查询预设的缓存定义哈希表, 判断该 缓存定义哈希表中是否存在与 Mapper类名对应的库表缓存定义。
[0039] 具体地, 可以预先在系统中设置一个 JVM级的缓存定义区, 该缓存定义区用于 保存缓存定义哈希表, 该缓存定义哈希表表现为一个 HashMap, 该 HashMap实现 了 “Key-Value键值对”接口, 结构如下:
[] [表 1]
Figure imgf000007_0001
[0040] 其中, Key为 SysTransCacheDef域对象的 mapperName (Mapper类名) , value为 SysTransCacheDef域对象本身。
[0041] 如果缓存定义哈希表中存在当前调用的 Mapper类名, 则可以判定该缓存定义哈 希表中存在与该 Mapper类名对应的库表缓存定义, 反之, 则判定该缓存定义哈 希表中不存在与该 Mapper类名对应的库表缓存定义。
[0042] 若所述缓存定义哈希表中存在与所述类名对应的库表缓存定义, 则执行步骤 S3 0, 判断当前是否已启用与所述库表缓存定义对应的线程级缓存功能;
[0043] 该步骤中, 若缓存定义哈希表中存在与当前调用的 Mapper类名对应的库表缓存 定义, 则进一步判断当前是否启用与该库表缓存定义对应的线程级缓存功能。
[0044] 具体实施时, 可以在 SysTransCacheDef域对象中用一个缓存功能使能位 enable d来控制是否启用与该 SysTransCacheDef域对象对应的线程级缓存功能, 通过获 取 enabled值, 即可判断当前是否启用与该库表缓存定义对应的线程级缓存功能 , 比如, 若检测到 enabled=l, 则判定当前已启用与库表缓存定义对应的线程级 缓存功能, 若检测到 enabled=0, 则判定当前未启用与库表缓存定义对应的线程 级缓存功能。
[0045] 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则执行步骤 S40, 根据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[0046] 该步骤中, 若当前已启用与库表缓存定义对应的线程级缓存功能, 则根据 Mapp er方法名和传入参数执行对应的线程级缓存数据读写操作, 其中, Mapper方法 名用于标识所执行的线程级缓存数据读写操作的类型, 其包括数据查询、 数据 插入、 数据更新、 数据删除等操作。 比如, 当 Mapper方法名标识数据查询操作 时, 先根据传入参数从当前线程的缓存数据区中查询数据, 若缓存数据区中存 在对应的数据, 则返回查询结果, 若缓存数据区中不存在对应的数据, 则再从 数据库中查询, 并返回查询结果, 并将查询结果保存在缓存数据区中; 当 Mappe r方法名标识数据插入操作时, 先在数据库中插入对应的数据, 然后根据传入参 数将插入的数据保存在当前线程的缓存数据区中; 当 Mapper方法名标识数据更 新操作时, 先对数据库中的对应的数据进行更新, 然后根据传入参数将更新后 的数据保存在当前线程的缓存数据区中。 由此, 实现了对缓存数据进行不同类 型的读写操作。
[0047] 需要说明的是, 本实施例中所提及的缓存数据区的缓存均为线程级的缓存, 缓 存数据区中的缓存数据仅对当前线程可用, 线程结束后缓存自动销毁, 该线程 级的缓存尤其适用于在同一个线程中需要对相同记录做多次操作的库表。 [0048] 本实施例当在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获 取当前调用的数据库访问接口的类名、 方法名和传入参数; 根据所述类名查询 预设的缓存定义哈希表, 判断所述缓存定义哈希表中是否存在与所述类名对应 的库表缓存定义; 若存在, 则判断当前是否已启用与所述库表缓存定义对应的 线程级缓存功能; 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作。 这种 方式相比于现有技术中对所有库表的查询结果做缓存的方式, 实现了线程级缓 存的细粒度控制, 即, 只有当预设的缓存定义哈希表中存在与当前调用的数据 库访问接口的类名对应的库表缓存定义, 且当前已启用与所述库表缓存定义对 应的线程级缓存功能时, 才会执行对应的线程级缓存数据读写操作, 从而本实 施例提高了 JVM本地线程级缓存方案的灵活性。
[0049] 进一步地, 基于本申请缓存处理方法第一实施例, 提出本申请缓存处理方法第 二实施例。
[0050] 在本实施例中, 上述步骤 S10之前, 还可以包括: 在应用程序启动时, 读取预 设的缓存配置表, 所述缓存配置表中记录有基于不同的数据库访问接口的类名 设置的缓存配置信息; 根据所述缓存配置信息生成一个缓存定义哈希表, 将所 述缓存定义哈希表保存至预设的 java虚拟机级缓存定义区中。
[0051] 在本实施例中, 在应用程序启动时需加载缓存定义到 JVM内存中。 具体实施时 , 首先读取预设的缓存配置表, 该缓存配置表中记录有基于不同的数据库访问 接口的类名设置的缓存配置信息, 该缓存配置信息可以包括 Mybatis访问数据库 的接口的类名、 Mybatis访问数据库的 Domain域名、 Domain中的主键属性字段、 缓存功能使能位以及描述信息。 具体地, 缓存配置表 sys_trans_cache_def的结 构如下表所示:
[] [表 2]
Figure imgf000010_0002
[0052] 比如, 有一个银行客户账信息主表, 表名为 ca_acct_mast, 其主键为
entity_code + acct_no, 需要将其配置为线程级缓存, 则做配置如下:
[0053] mapper— name : CaAcctMastMapper
[0054] domain— name : CaAcctMast
[0055] primary— Key : entityCode, acctNo
[0056] enabled :
Figure imgf000010_0001
[0057] description : 客户账信息主表
[0058] 在读取到缓存配置表后, 获取该缓存配置表中的所有记录, 得到一个由 SysTra nsCacheDef域对象组成的链表, 将该链表重新组装为一个缓存定义哈希表 HashM ap; 在该缓存定义哈希表中, Key为 SysTransCacheDef域对象的 mapperName (Ma pper类名) , value为 SysTransCacheDef域对象本身; 之后, 将该 HashMap保存 至预设的 JVM级的缓存定义区中, 以供后续查询。
[0059] 上述方式通过将在应用程序启动时加载缓存定义到 JVM内存中, 为后续根据当 前调用的数据库访问接口的类名查询预设的缓存定义哈希表提供了前提保证。
[0060] 进一步地, 所述缓存处理方法还可以包括: 接收基于所述缓存配置表的修改指 令, 根据所述修改指令修改所述缓存配置表中的缓存配置信息; 根据修改后的 所述缓存配置信息生成一个新的缓存定义哈希表; 将所述 java虚拟机级缓存定 义区中保存的所述缓存定义哈希表更新为所述新的缓存定义哈希表。
[0061] 在本实施例中, 用户可以触发修改指令以修改上述缓存配置表。 当系统接收到 基于缓存配置表的修改指令时, 即根据该修改指令修改缓存配置表中的缓存配 置信息, 其中修改包括增加、 删除和改动。 比如, 当用户想要新增缓存定义时 , 只需在缓存配置表中插入一条记录; 当用户想要禁用某一条缓存时, 只需将 缓存配置表中对应的记录删除, 或将 enabled位改为 0。 之后, 系统根据修改后 的缓存配置信息生成一个新的缓存定义哈希表, 并将 java虚拟机级缓存定义区 中保存的缓存定义哈希表更新为新的缓存定义哈希表。
[0062] 需要说明的是, 在一实施方式中, 用户在修改缓存配置表中的缓存配置信息后 , 可以手动触发更新指令以更新缓存定义哈希表; 在另一实施方式中, 也可以 通过创建一个轮询线程, 通过该轮询线程定时触发 (比如每隔 30秒) 读取缓存 配置表中的全部数据, 并根据读取到的数据对缓存定义哈希表进行更新。
[0063] 本实施例通过提供对缓存配置表的修改功能, 不需要修改代码或配置文件, 不 需要重新部署, 也不需要重启系统, 只需要对缓存配置表做增、 删、 改, 即可 达到启用缓存、 禁用缓存的目的, 灵活程度非常高。
[0064] 进一步地, 基于本申请缓存处理方法第一实施例, 提出本申请缓存处理方法第 三实施例。
[0065] 在本实施例中, 上述步骤 S40可以包括: 当所述方法名标识未加记录锁的数据 查询操作时, 根据所述传入参数查询预设的第一线程级缓存数据哈希表, 得到 第一查询结果; 判断所述第一查询结果是否为空; 若所述第一查询结果为空, 则执行调用数据库访问接口的操作, 并将对应的调用结果保存至所述第一线程 级缓存数据哈希表中。
[0066] 当 Mapper方法名标识未加记录锁的数据查询操作时, 先根据传入参数获得访问 数据库的域名 domain_name, 再根据 domain_name和传入参数从预设的第一线程 级缓存数据哈希表中查询, 得到第一查询结果。 该第一线程级缓存数据哈希表 保存在预设的第一线程级缓存数据区中, 其结构如下表所示: [] [表 3]
Figure imgf000012_0001
[0067] 其中, Key为域名 +主键名, value为域对象, 一个域对象对应数据库表中的一 条记录。
[0068] 若该第一查询结果不为空, 说明第一线程级缓存数据区中存在对应的数据, 此 时返回查询结果即可; 若该第一查询结果为空, 说明第一线程级缓存数据区中 不存在对应的数据, 此时执行调用数据库访问接口的操作, 以从数据库中查询 对应的数据, 并将对应的调用结果保存至第一线程级缓存数据哈希表中, 以供 下次查询相同的数据时直接从缓存中读取。
[0069] 进一步地, 上述步骤 S40还可以包括: 当所述方法名标识加记录锁的数据查询 操作时, 根据所述传入参数查询预设的第二线程级缓存数据哈希表, 得到第二 查询结果; 判断所述第二查询结果是否为空; 若所述第二查询结果为空, 则执 行调用数据库访问接口的操作, 并将对应的调用结果保存至所述第一线程级缓 存数据哈希表和所述第二线程级缓存数据哈希表中。
[0070] 在本实施例中, 记录锁即当一个进程正在读或修改文件的某个部分时, 它可以 阻止其他进程修改同一文件区。 当 Mapper方法名标识加记录锁的数据查询操作 (一般在更新数据时用到) 时, 先根据传入参数获得访问数据库的域名 domain_ name, 再根据 domain_name和传入参数从预设的第二线程级缓存数据哈希表中查 询, 得到第二查询结果。 其中, 第二线程级缓存数据哈希表保存在预设的第二 线程级缓存数据区中, 其结构与上述第一线程级缓存数据哈希表类似, 此处不 作赘述。
[0071] 若该第二查询结果不为空, 说明第二线程级缓存数据区中存在对应的数据, 此 时返回查询结果即可; 若该第二查询结果为空, 说明第二线程级缓存数据区中 不存在对应的数据, 此时执行调用数据库访问接口的操作, 以从数据库中加锁 查询对应的数据, 并将对应的调用结果保存至第一线程级缓存数据哈希表和第 二线程级缓存数据哈希表中, 以供下次查询相同的数据时直接从缓存中读取。
[0072] 需要说明的是, 设置第一线程级缓存数据哈希表和第二线程级缓存数据哈希表 的目的在于区分不加记录锁的数据查询操作和加记录锁的数据查询操作, 通过 这种设置, 如果先执行不加记录锁的数据查询操作, 再对相同的记录执行加记 录锁的数据查询操作, 仍然需要操作数据库, 如果先执行加记录锁的数据查询 操作, 再对相同的记录执行不加记录锁的数据查询操作, 则不需要再查询数据 库, 从而提高了数据查询效率。
[0073] 进一步地, 上述步骤 S40还可以包括: 当所述方法名标识数据更新操作时, 执 行调用数据库访问接口的操作, 以在数据库中更新对应的数据, 并将所述传入 参数保存至所述第一线程级缓存数据哈希表中; 判断所述第二线程级缓存数据 哈希表中是否存在与所述传入参数对应的更新对象, 若存在, 则根据所述传入 参数对所述更新对象进行更新。
[0074] 当 Mapper方法名标识数据更新操作时, 执行调用数据库访问接口的操作, 以在 数据库中更新对应的数据, 并将传入参数保存至第一线程级缓存数据哈希表中 , 然后判断第二线程级缓存数据哈希表中是否存在与该传入参数对应的更新对 象, 若存在, 则根据该传入参数对该更新对象进行更新, 以保证第二线程级缓 存数据哈希表中保存的是最新的数据; 若不存在, 则不作任何处理。
[0075] 进一步地, 上述步骤 S40还可以包括: 当所述方法名标识数据插入操作时, 执 行调用数据库访问接口的操作, 以在数据库中插入对应的数据, 并将所述传入 参数保存至所述第一线程级缓存数据哈希表中。
[0076] 当 Mapper方法名标识当所述方法名标识数据插入操作时, 执行调用数据库访问 接口的操作, 以在数据库中插入对应的数据, 并将所述传入参数保存至所述第 一线程级缓存数据哈希表中, 以使第一线程级缓存数据哈希表中的数据和数据 库保持一致性。
[0077] 进一步地, 上述步骤 S40还可以包括: 当所述方法名标识数据删除操作时, 执 行调用数据库访问接口的操作, 以在数据库中删除对应的数据; 根据所述传入 参数在所述第一线程级缓存数据哈希表和所述第二线程级缓存数据哈希表中删 除对应的数据。
[0078] 当 Mapper方法名标识当所述方法名标识数据删除操作时, 执行调用数据库访问 接口的操作, 以在数据库中删除对应的数据; 然后, 根据传入参数在第一线程 级缓存数据哈希表和第二线程级缓存数据哈希表中删除对应的数据, 以使第一 线程级缓存数据哈希表和第二线程级缓存数据哈希表中的数据和数据库保持一 致性。
[0079] 通过上述方式, 实现了对数据查询、 插入和更新操作进行缓存处理, 相比于现 有技术仅能对数据查询操作做缓存处理, 提高了 JVM缓存功能的全面性, 从而有 利于提高相应的数据读写效率; 此外, 上述线程级读写缓存的机制与业务逻辑 完全解耦, 业务层开发人员无需感知缓存的存在, 只需要调用数据库访问接口 读写数据库即可, 相比于现有的在业务逻辑处理的工程中执行缓存读写的机制 , 降低了编码复杂度, 提高了编码效率, 且具有较高的灵活性。
[0080] 本申请还提供一种缓存处理装置。 所述缓存处理装置包括:
[0081] 获取模块, 用于当在应用程序的预设线程中检测到调用数据库访问接口的指令 时, 获取当前调用的数据库访问接口的类名、 方法名和传入参数;
[0082] 第一判断模块, 用于根据所述类名查询预设的缓存定义哈希表, 判断所述缓存 定义哈希表中是否存在与所述类名对应的库表缓存定义;
[0083] 第二判断模块, 用于若所述缓存定义哈希表中存在与所述类名对应的库表缓存 定义, 则判断当前是否已启用与所述库表缓存定义对应的线程级缓存功能; [0084] 执行模块, 用于若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则 根据所述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[0085] 进一步地, 所述缓存处理装置还包括:
[0086] 读取模块, 用于在应用程序启动时, 读取预设的缓存配置表, 所述缓存配置表 中记录有基于不同的数据库访问接口的类名设置的缓存配置信息;
[0087] 生成模块, 用于根据所述缓存配置信息生成一个缓存定义哈希表, 将所述缓存 定义哈希表保存至预设的 java虚拟机级缓存定义区中。
[0088] 进一步地, 所述缓存处理装置还包括: [0089] 修改模块, 用于接收基于所述缓存配置表的修改指令, 根据所述修改指令修改 所述缓存配置表中的缓存配置信息;
[0090] 所述生成模块, 还用于根据修改后的所述缓存配置信息生成一个新的缓存定义 哈希表;
[0091] 更新模块, 用于将所述 java虚拟机级缓存定义区中保存的所述缓存定义哈希表 更新为所述新的缓存定义哈希表。
[0092] 进一步地, 所述执行模块还用于:
[0093] 当所述方法名标识未加记录锁的数据查询操作时, 根据所述传入参数查询预设 的第一线程级缓存数据哈希表, 得到第一查询结果;
[0094] 判断所述第一查询结果是否为空;
[0095] 若所述第一查询结果为空, 则执行调用数据库访问接口的操作, 并将对应的调 用结果保存至所述第一线程级缓存数据哈希表中。
[0096] 进一步地, 所述执行模块还用于:
[0097] 当所述方法名标识加记录锁的数据查询操作时, 根据所述传入参数查询预设的 第二线程级缓存数据哈希表, 得到第二查询结果;
[0098] 判断所述第二查询结果是否为空;
[0099] 若所述第二查询结果为空, 则执行调用数据库访问接口的操作, 并将对应的调 用结果保存至所述第一线程级缓存数据哈希表和所述第二线程级缓存数据哈希 表中。
[0100] 进一步地, 所述执行模块还用于:
[0101] 当所述方法名标识数据更新操作时, 执行调用数据库访问接口的操作, 以在数 据库中更新对应的数据, 并将所述传入参数保存至所述第一线程级缓存数据哈 希表中;
[0102] 判断所述第二线程级缓存数据哈希表中是否存在与所述传入参数对应的更新对 象, 若存在, 则根据所述传入参数对所述更新对象进行更新。
[0103] 进一步地, 所述执行模块还用于:
[0104] 当所述方法名标识数据插入操作时, 执行调用数据库访问接口的操作, 以在数 据库中插入对应的数据, 并将所述传入参数保存至所述第一线程级缓存数据哈 希表中。
[0105] 进一步地, 所述执行模块还用于:
[0106] 当所述方法名标识数据删除操作时, 执行调用数据库访问接口的操作, 以在数 据库中删除对应的数据;
[0107] 根据所述传入参数在所述第一线程级缓存数据哈希表和所述第二线程级缓存数 据哈希表中删除对应的数据。
[0108] 上述各程序模块所执行的方法可参照本申请缓存处理方法各个实施例, 此处不 再赘述。
[0109] 本申请还提供一种计算机可读存储介质。
[0110] 本申请计算机可读存储介质上存储有缓存处理程序, 所述缓存处理程序被处理 器执行时实现如上所述的缓存处理方法的步骤。
[0111] 其中, 在所述处理器上运行的缓存处理程序被执行时所实现的方法可参照本申 请缓存处理方法各个实施例, 此处不再赘述。
[0112] 需要说明的是, 在本文中, 术语“包括” 、 “包含”或者其任何其他变体意在 涵盖非排他性的包含, 从而使得包括一系列要素的过程、 方法、 物品或者系统 不仅包括那些要素, 而且还包括没有明确列出的其他要素, 或者是还包括为这 种过程、 方法、 物品或者系统所固有的要素。 在没有更多限制的情况下, 由语 句“包括一个 ” 限定的要素, 并不排除在包括该要素的过程、 方法、 物品 或者系统中还存在另外的相同要素。
[0113] 上述本申请实施例序号仅仅为了描述, 不代表实施例的优劣。
[0114] 通过以上的实施方式的描述, 本领域的技术人员可以清楚地了解到上述实施例 方法可借助软件加必需的通用硬件平台的方式来实现, 当然也可以通过硬件, 但很多情况下前者是更佳的实施方式。 基于这样的理解, 本申请的技术方案本 质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来, 该计 算机软件产品存储在如上所述的一个存储介质(如 R0M/RAM、 磁碟、 光盘)中, 包 括若干指令用以使得一台终端设备(可以是手机, 计算机, 服务器, 空调器, 或 者网络设备等)执行本申请各个实施例所述的方法。
[0115] 以上仅为本申请的优选实施例, 并非因此限制本申请的专利范围, 凡是利用本 申请说明书及附图内容所作的等效结构或等效流程变换, 或直接或间接运用在 其他相关的技术领域, 均同理包括在本申请的专利保护范围内。

Claims

权利要求书
[权利要求 1] 一种缓存处理方法, 其中, 所述缓存处理方法包括如下步骤:
当在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获 取当前调用的数据库访问接口的类名、 方法名和传入参数; 根据所述类名查询预设的缓存定义哈希表, 判断所述缓存定义哈希表 中是否存在与所述类名对应的库表缓存定义;
若所述缓存定义哈希表中存在与所述类名对应的库表缓存定义, 则判 断当前是否已启用与所述库表缓存定义对应的线程级缓存功能; 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根据所 述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[权利要求 2] 如权利要求 1所述的缓存处理方法, 其中, 所述当在应用程序的预设 线程中检测到调用数据库访问接口的指令时, 获取当前调用的数据库 访问接口的类名、 方法名和传入参数的步骤之前, 还包括: 在应用程序启动时, 读取预设的缓存配置表, 所述缓存配置表中记录 有基于不同的数据库访问接口的类名设置的缓存配置信息; 根据所述缓存配置信息生成一个缓存定义哈希表, 将所述缓存定义哈 希表保存至预设的 java虚拟机级缓存定义区中。
[权利要求 3] 如权利要求 2所述的缓存处理方法, 其中, 所述缓存处理方法还包括 接收基于所述缓存配置表的修改指令, 根据所述修改指令修改所述缓 存配置表中的缓存配置信息;
根据修改后的所述缓存配置信息生成一个新的缓存定义哈希表; 将所述 java虚拟机级缓存定义区中保存的所述缓存定义哈希表更新为 所述新的缓存定义哈希表。
[权利要求 4] 如权利要求 1所述的缓存处理方法, 其中, 所述根据所述方法名和所 述传入参数执行对应的线程级缓存数据读写操作的步骤包括: 当所述方法名标识未加记录锁的数据查询操作时, 根据所述传入参数 查询预设的第一线程级缓存数据哈希表, 得到第一查询结果; 判断所述第一查询结果是否为空;
若所述第一查询结果为空, 则执行调用数据库访问接口的操作, 并将 对应的调用结果保存至所述第一线程级缓存数据哈希表中。
[权利要求 5] 如权利要求 4所述的缓存处理方法, 其中, 所述根据所述方法名和所 述传入参数执行对应的线程级缓存数据读写操作的步骤包括: 当所述方法名标识加记录锁的数据查询操作时, 根据所述传入参数查 询预设的第二线程级缓存数据哈希表, 得到第二查询结果; 判断所述第二查询结果是否为空;
若所述第二查询结果为空, 则执行调用数据库访问接口的操作, 并将 对应的调用结果保存至所述第一线程级缓存数据哈希表和所述第二线 程级缓存数据哈希表中。
[权利要求 6] 如权利要求 5所述的缓存处理方法, 其中, 所述根据所述方法名和所 述传入参数执行对应的线程级缓存数据读写操作的步骤包括: 当所述方法名标识数据更新操作时, 执行调用数据库访问接口的操作 , 以在数据库中更新对应的数据, 并将所述传入参数保存至所述第一 线程级缓存数据哈希表中;
判断所述第二线程级缓存数据哈希表中是否存在与所述传入参数对应 的更新对象, 若存在, 则根据所述传入参数对所述更新对象进行更新
[权利要求 7] 如权利要求 6所述的缓存处理方法, 其中, 所述根据所述方法名和所 述传入参数执行对应的线程级缓存数据读写操作的步骤包括: 当所述方法名标识数据插入操作时, 执行调用数据库访问接口的操作 , 以在数据库中插入对应的数据, 并将所述传入参数保存至所述第一 线程级缓存数据哈希表中。
[权利要求 8] 如权利要求 7所述的缓存处理方法, 其中, 所述根据所述方法名和所 述传入参数执行对应的线程级缓存数据读写操作的步骤包括: 当所述方法名标识数据删除操作时, 执行调用数据库访问接口的操作 , 以在数据库中删除对应的数据; 根据所述传入参数在所述第一线程级缓存数据哈希表和所述第二线程 级缓存数据哈希表中删除对应的数据。
[权利要求 9] 一种缓存处理装置, 其中, 所述缓存处理装置包括:
获取模块, 用于当在应用程序的预设线程中检测到调用数据库访问接 口的指令时, 获取当前调用的数据库访问接口的类名、 方法名和传入 参数;
第一判断模块, 用于根据所述类名查询预设的缓存定义哈希表, 判断 所述缓存定义哈希表中是否存在与所述类名对应的库表缓存定义; 第二判断模块, 用于若所述缓存定义哈希表中存在与所述类名对应的 库表缓存定义, 则判断当前是否已启用与所述库表缓存定义对应的线 程级缓存功能;
执行模块, 用于若当前已启用与所述库表缓存定义对应的线程级缓存 功能, 则根据所述方法名和所述传入参数执行对应的线程级缓存数据 读写操作。
[权利要求 10] 如权利要求 9所述的缓存处理装置, 其中, 所述缓存处理装置还包括 读取模块, 用于在应用程序启动时, 读取预设的缓存配置表, 所述缓 存配置表中记录有基于不同的数据库访问接口的类名设置的缓存配置 信息;
生成模块, 用于根据所述缓存配置信息生成一个缓存定义哈希表, 将 所述缓存定义哈希表保存至预设的 java虚拟机级缓存定义区中。
[权利要求 11] 如权利要求 10所述的缓存处理装置, 其中, 所述缓存处理装置还包括 修改模块, 用于接收基于所述缓存配置表的修改指令, 根据所述修改 指令修改所述缓存配置表中的缓存配置信息;
所述生成模块, 还用于根据修改后的所述缓存配置信息生成一个新的 缓存定义哈希表;
更新模块, 用于将所述 java虚拟机级缓存定义区中保存的所述缓存定 义哈希表更新为所述新的缓存定义哈希表。
[权利要求 12] 如权利要求 9所述的缓存处理装置, 其中, 所述执行模块还用于: 当所述方法名标识未加记录锁的数据查询操作时, 根据所述传入参数 查询预设的第一线程级缓存数据哈希表, 得到第一查询结果; 判断所述第一查询结果是否为空;
若所述第一查询结果为空, 则执行调用数据库访问接口的操作, 并将 对应的调用结果保存至所述第一线程级缓存数据哈希表中。
[权利要求 13] 如权利要求 12所述的缓存处理装置, 其中, 所述执行模块还用于: 当所述方法名标识加记录锁的数据查询操作时, 根据所述传入参数查 询预设的第二线程级缓存数据哈希表, 得到第二查询结果; 判断所述第二查询结果是否为空;
若所述第二查询结果为空, 则执行调用数据库访问接口的操作, 并将 对应的调用结果保存至所述第一线程级缓存数据哈希表和所述第二线 程级缓存数据哈希表中。
[权利要求 14] 如权利要求 13所述的缓存处理装置, 其中, 所述执行模块还用于: 当所述方法名标识数据更新操作时, 执行调用数据库访问接口的操作 , 以在数据库中更新对应的数据, 并将所述传入参数保存至所述第一 线程级缓存数据哈希表中;
判断所述第二线程级缓存数据哈希表中是否存在与所述传入参数对应 的更新对象, 若存在, 则根据所述传入参数对所述更新对象进行更新
[权利要求 15] 如权利要求 14所述的缓存处理装置, 其中, 所述执行模块还用于: 当所述方法名标识数据插入操作时, 执行调用数据库访问接口的操作 , 以在数据库中插入对应的数据, 并将所述传入参数保存至所述第一 线程级缓存数据哈希表中。
[权利要求 16] 如权利要求 15所述的缓存处理装置, 其中, 所述执行模块还用于: 当所述方法名标识数据删除操作时, 执行调用数据库访问接口的操作 , 以在数据库中删除对应的数据; 根据所述传入参数在所述第一线程级缓存数据哈希表和所述第二线程 级缓存数据哈希表中删除对应的数据。
[权利要求 17] —种缓存处理设备, 其中, 所述缓存处理设备包括: 存储器、 处理器 及存储在所述存储器上并可在所述处理器上运行的缓存处理程序, 所 述缓存处理程序被所述处理器执行时实现如下步骤:
当在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获 取当前调用的数据库访问接口的类名、 方法名和传入参数; 根据所述类名查询预设的缓存定义哈希表, 判断所述缓存定义哈希表 中是否存在与所述类名对应的库表缓存定义;
若所述缓存定义哈希表中存在与所述类名对应的库表缓存定义, 则判 断当前是否已启用与所述库表缓存定义对应的线程级缓存功能; 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根据所 述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[权利要求 18] 如权利要求 17所述的缓存处理设备, 其中, 所述缓存处理程序被所述 处理器执行时还实现如下步骤:
在应用程序启动时, 读取预设的缓存配置表, 所述缓存配置表中记录 有基于不同的数据库访问接口的类名设置的缓存配置信息; 根据所述缓存配置信息生成一个缓存定义哈希表, 将所述缓存定义哈 希表保存至预设的 java虚拟机级缓存定义区中。
[权利要求 19] 一种计算机可读存储介质, 其中, 所述计算机可读存储介质上存储有 缓存处理程序, 所述缓存处理程序被处理器执行时实现如下步骤: 当在应用程序的预设线程中检测到调用数据库访问接口的指令时, 获 取当前调用的数据库访问接口的类名、 方法名和传入参数; 根据所述类名查询预设的缓存定义哈希表, 判断所述缓存定义哈希表 中是否存在与所述类名对应的库表缓存定义;
若所述缓存定义哈希表中存在与所述类名对应的库表缓存定义, 则判 断当前是否已启用与所述库表缓存定义对应的线程级缓存功能; 若当前已启用与所述库表缓存定义对应的线程级缓存功能, 则根据所 述方法名和所述传入参数执行对应的线程级缓存数据读写操作。
[权利要求 20] 如权利要求 19所述的计算机可读存储介质, 其中, 所述缓存处理程序 被处理器执行时还实现如下步骤:
在应用程序启动时, 读取预设的缓存配置表, 所述缓存配置表中记录 有基于不同的数据库访问接口的类名设置的缓存配置信息; 根据所述缓存配置信息生成一个缓存定义哈希表, 将所述缓存定义哈 希表保存至预设的 java虚拟机级缓存定义区中。
PCT/CN2020/077614 2019-04-19 2020-03-03 缓存处理方法、装置、设备及计算机可读存储介质 WO2020211554A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910321455.6A CN110109958A (zh) 2019-04-19 2019-04-19 缓存处理方法、装置、设备及计算机可读存储介质
CN201910321455.6 2019-04-19

Publications (1)

Publication Number Publication Date
WO2020211554A1 true WO2020211554A1 (zh) 2020-10-22

Family

ID=67485964

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/077614 WO2020211554A1 (zh) 2019-04-19 2020-03-03 缓存处理方法、装置、设备及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN110109958A (zh)
WO (1) WO2020211554A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110096334A (zh) * 2019-04-19 2019-08-06 深圳前海微众银行股份有限公司 缓存处理方法、装置、设备及计算机可读存储介质
CN110109958A (zh) * 2019-04-19 2019-08-09 深圳前海微众银行股份有限公司 缓存处理方法、装置、设备及计算机可读存储介质
CN110968603B (zh) * 2019-11-29 2023-07-04 中国银行股份有限公司 一种数据访问方法及装置
CN110990439A (zh) * 2019-12-13 2020-04-10 深圳前海环融联易信息科技服务有限公司 基于缓存的快速查询方法、装置、计算机设备及存储介质
CN111506499B (zh) * 2020-04-08 2023-06-02 百度在线网络技术(北京)有限公司 一种小程序中参数可用性检测方法、装置以及电子设备
CN112199391B (zh) * 2020-09-30 2024-02-23 深圳前海微众银行股份有限公司 一种数据加锁检测方法、设备及计算机可读存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101075241A (zh) * 2006-12-26 2007-11-21 腾讯科技(深圳)有限公司 缓存处理方法以及缓存处理系统
CN104750720A (zh) * 2013-12-30 2015-07-01 中国银联股份有限公司 多线程并发访问环境下高性能数据处理的实现
CN105426238A (zh) * 2016-01-17 2016-03-23 浙江维融电子科技股份有限公司 一种基于内存的设备后台指令管理系统的控制方法
US20160364315A1 (en) * 2015-06-12 2016-12-15 Arizona Board Of Regents On Behalf Of Arizona State University Fast data race detection for multicore systems
CN110109958A (zh) * 2019-04-19 2019-08-09 深圳前海微众银行股份有限公司 缓存处理方法、装置、设备及计算机可读存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101075241A (zh) * 2006-12-26 2007-11-21 腾讯科技(深圳)有限公司 缓存处理方法以及缓存处理系统
CN104750720A (zh) * 2013-12-30 2015-07-01 中国银联股份有限公司 多线程并发访问环境下高性能数据处理的实现
US20160364315A1 (en) * 2015-06-12 2016-12-15 Arizona Board Of Regents On Behalf Of Arizona State University Fast data race detection for multicore systems
CN105426238A (zh) * 2016-01-17 2016-03-23 浙江维融电子科技股份有限公司 一种基于内存的设备后台指令管理系统的控制方法
CN110109958A (zh) * 2019-04-19 2019-08-09 深圳前海微众银行股份有限公司 缓存处理方法、装置、设备及计算机可读存储介质

Also Published As

Publication number Publication date
CN110109958A (zh) 2019-08-09

Similar Documents

Publication Publication Date Title
WO2020211554A1 (zh) 缓存处理方法、装置、设备及计算机可读存储介质
WO2020211570A1 (zh) 缓存处理方法、装置、设备及计算机可读存储介质
KR101643022B1 (ko) 카탈로그-기반 소프트웨어 컴포넌트 관리
US7096213B2 (en) Persistent key-value repository with a pluggable architecture to abstract physical storage
US9424266B2 (en) Efficient file hash identifier computation
US7062516B2 (en) Methods, systems, and articles of manufacture for implementing a runtime logging service storage infrastructure
US8316120B2 (en) Applicability detection using third party target state
WO2005052762A2 (en) System and method for executing an application on a secured run-time environment
KR20110128846A (ko) 장치와 웹 서비스 간에 브라우저 캐시를 동기화하는 프로그래밍 모델
JP2010129080A (ja) ソフトウェア実行システムおよびソフトウェアの実行方法
US9110940B2 (en) Supporting transactions in distributed environments using a local copy of remote transaction data and optimistic locking
CN107463378A (zh) 一种基于注解的本地缓存实现方法、存储设备及电子设备
US20140047222A1 (en) Method and device for recombining runtime instruction
WO2008054989A1 (en) Virtual deletion in merged registry keys
WO2021139431A1 (zh) 微服务的数据同步方法、装置、电子设备及存储介质
US20230401241A1 (en) System for lightweight objects
JP2023512247A (ja) 複数のチェーンを使用した共有キャッシュ内のオブジェクトの管理
JP2012530297A (ja) ソフトウェアコンポーネント状態に対するアクセスコントロール
US9009731B2 (en) Conversion of lightweight object to a heavyweight object
CN114153354B (zh) 菜单显示方法和电子设备
JP3110185B2 (ja) 計算機システム
CN111090675B (zh) 多入口数据缓存方法及存储介质
US11017032B1 (en) Document recovery utilizing serialized data
CN114860212A (zh) 一种可扩展缓存访问方法、系统、装置及存储介质
AU2003220549B2 (en) Key-value repository with a pluggable architecture

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20792188

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20792188

Country of ref document: EP

Kind code of ref document: A1