HK40046413B - Method and system for processing data, computer readable medium and electronic apparatus - Google Patents

Method and system for processing data, computer readable medium and electronic apparatus Download PDF

Info

Publication number
HK40046413B
HK40046413B HK42021036229.9A HK42021036229A HK40046413B HK 40046413 B HK40046413 B HK 40046413B HK 42021036229 A HK42021036229 A HK 42021036229A HK 40046413 B HK40046413 B HK 40046413B
Authority
HK
Hong Kong
Prior art keywords
data
target
time
query request
current thread
Prior art date
Application number
HK42021036229.9A
Other languages
Chinese (zh)
Other versions
HK40046413A (en
Inventor
梁振锐
Original Assignee
腾讯科技(深圳)有限公司
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Publication of HK40046413A publication Critical patent/HK40046413A/en
Publication of HK40046413B publication Critical patent/HK40046413B/en

Links

Description

数据处理方法、系统、计算机可读介质及电子设备Data processing methods, systems, computer-readable media, and electronic devices

技术领域Technical Field

本申请属于计算机技术领域,具体涉及一种数据处理方法、系统、计算机可读介质及电子设备。This application belongs to the field of computer technology, and specifically relates to a data processing method, system, computer-readable medium, and electronic device.

背景技术Background Technology

在高并发系统中,存在“缓存击穿”,即大量请求同时查询某一或某些缓存数据,当该缓存数据刚好失效时,会导致大量请求直接访问数据库,对数据库造成冲击,造成数据库和缓存的查询故障问题。In high-concurrency systems, there is a phenomenon called "cache breakdown," which occurs when a large number of requests simultaneously query one or more cached data. If the cached data happens to expire, a large number of requests will directly access the database, causing a surge in database requests and resulting in query failures in both the database and the cache.

即使大量请求同时查询一个缓存数据,缓存数据失效时仅有少量请求直接访问数据库不造成数据库的崩溃,也需要等待请求读取数据库完成并对缓存数据进行更新之后才能响应其他请求,从而造成数据查询的响应时间较长,系统响应性较差。Even if a large number of requests simultaneously query the same cached data, and only a small number of requests directly access the database when the cache expires, preventing the database from crashing, other requests still need to wait for the database to be read and the cached data to be updated before responding to other requests. This results in a long response time for data queries and poor system responsiveness.

需要说明的是,在上述背景技术部分公开的信息仅用于加强对本申请的背景的理解,因此可以包括不构成对本领域普通技术人员已知的现有技术的信息。It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this application, and therefore may include information that does not constitute prior art known to those skilled in the art.

发明内容Summary of the Invention

本申请的目的在于提供一种数据处理方法、系统、计算机可读介质及电子设备,至少在一定程度上克服相关技术中存在的缓存击穿、数据查询响应性差等技术问题。The purpose of this application is to provide a data processing method, system, computer-readable medium, and electronic device that at least to some extent overcomes the technical problems existing in related technologies, such as cache breakdown and poor data query responsiveness.

本申请的其他特性和优点将通过下面的详细描述变得显然,或部分地通过本申请的实践而习得。Other features and advantages of this application will become apparent from the following detailed description, or may be learned in part from practice of this application.

根据本申请实施例的一个方面,提供一种数据处理方法,该方法包括:According to one aspect of the embodiments of this application, a data processing method is provided, the method comprising:

响应于数据查询请求,在缓存中查找与所述数据查询请求相匹配的目标缓存数据;In response to a data query request, the target cached data that matches the data query request is retrieved from the cache;

获取所述目标缓存数据的超时时间,并确定所述超时时间是否已过期,所述超时时间小于所述目标缓存数据的失效时间;Obtain the timeout period of the target cached data and determine whether the timeout period has expired, wherein the timeout period is less than the expiration time of the target cached data;

若所述超时时间未过期,则向所述数据查询请求的请求方返回所述目标缓存数据;If the timeout period has not expired, the target cached data is returned to the requester of the data query request;

若所述超时时间已过期,则延长所述目标缓存数据的超时时间,并在数据库中查找与所述数据查询请求相匹配的目标数据库数据。If the timeout period has expired, the timeout period of the target cached data is extended, and the target database data that matches the data query request is searched in the database.

根据本申请实施例的一个方面,提供一种数据处理系统,该系统包括:According to one aspect of the embodiments of this application, a data processing system is provided, the system comprising:

缓存查找模块,被配置为响应于数据查询请求,在缓存中查找与所述数据查询请求相匹配的目标缓存数据;The cache lookup module is configured to, in response to a data query request, search the cache for target cache data that matches the data query request.

时间获取模块,被配置为获取所述目标缓存数据的超时时间,并确定所述超时时间是否已过期,所述超时时间小于所述目标缓存数据的失效时间;The time acquisition module is configured to acquire the timeout time of the target cached data and determine whether the timeout time has expired, wherein the timeout time is less than the expiration time of the target cached data;

第一执行模块,被配置为若所述超时时间未过期,则向所述数据查询请求的请求方返回所述目标缓存数据;The first execution module is configured to return the target cached data to the requester of the data query request if the timeout period has not expired.

第二执行模块,被配置为若所述超时时间已过期,则延长所述目标缓存数据的超时时间,并在数据库中查找与所述数据查询请求相匹配的目标数据库数据。The second execution module is configured to extend the timeout period of the target cached data if the timeout period has expired, and to search for target database data that matches the data query request in the database.

在本申请的一些实施例中,基于以上技术方案,所述缓存查找模块包括:In some embodiments of this application, based on the above technical solutions, the cache lookup module includes:

第一关键字获取单元,被配置为获取所述数据查询请求中携带的查询关键字;The first keyword acquisition unit is configured to acquire the query keywords carried in the data query request;

第一关键字匹配单元,被配置为在缓存中查找与所述查询关键字相匹配的目标关键字,并确定所述目标关键字的失效时间是否已过期;The first keyword matching unit is configured to search for a target keyword that matches the query keyword in the cache, and determine whether the expiration time of the target keyword has expired;

缓存数据查找单元,被配置为若所述目标关键字的失效时间未过期,则将与所述目标关键字相关联的缓存数据确定为与所述数据查询请求相匹配的目标缓存数据。The cached data lookup unit is configured to determine the cached data associated with the target keyword as the target cached data that matches the data query request if the expiration time of the target keyword has not expired.

在本申请的一些实施例中,基于以上技术方案,所述缓存查找模块还包括:In some embodiments of this application, based on the above technical solutions, the cache lookup module further includes:

执行单元,被配置为若所述目标关键字的失效时间已过期,则在数据库中查找与所述目标关键字相关联的数据库数据;The execution unit is configured to search for database data associated with the target keyword in the database if the expiration time of the target keyword has expired.

缓存更新单元,被配置为根据查找得到的数据库数据更新与所述目标关键字相关联的缓存数据;The cache update unit is configured to update the cache data associated with the target keyword based on the retrieved database data;

目标缓存数据获取单元,被配置为将更新后的缓存数据确定为与所述数据查询请求相匹配的目标缓存数据。The target cache data acquisition unit is configured to determine the updated cache data as the target cache data that matches the data query request.

在本申请的一些实施例中,基于以上技术方案,所述第二执行模块包括:In some embodiments of this application, based on the above technical solutions, the second execution module includes:

第一延时单元,被配置为根据所述数据查询请求中携带的请求时间戳确定发起所述数据查询请求的请求时间;The first delay unit is configured to determine the request time for initiating the data query request based on the request timestamp carried in the data query request;

第二延时单元,被配置为将所述目标缓存数据的超时时间延长至位于所述请求时间和所述目标缓存数据的失效时间之间的目标时间点。The second delay unit is configured to extend the timeout period of the target cached data to a target time point between the request time and the expiration time of the target cached data.

在本申请的一些实施例中,基于以上技术方案,所述第二延时单元包括:In some embodiments of this application, based on the above technical solutions, the second delay unit includes:

时间差获取子单元,被配置为获取所述请求时间与所述目标缓存数据的超时时间之间的时间差;The time difference acquisition subunit is configured to acquire the time difference between the request time and the timeout of the target cached data.

目标时间点选取子单元,被配置为根据所述时间差选取位于所述请求时间和所述目标缓存数据的失效时间之间的所述目标时间点;The target time point selection subunit is configured to select the target time point located between the request time and the expiration time of the target cached data based on the time difference;

延时子单元,被配置为将所述目标缓存数据的超时时间延长至所述目标时间点。The delay subunit is configured to extend the timeout period of the target cached data to the target time point.

在本申请的一些实施例中,基于以上技术方案,所述第二执行模块还包括:In some embodiments of this application, based on the above technical solutions, the second execution module further includes:

第二关键字获取单元,被配置为获取所述数据查询请求中携带的查询关键字;The second keyword acquisition unit is configured to acquire the query keywords carried in the data query request;

第二关键字匹配单元,被配置为在数据库中查找与所述查询关键字相匹配的目标关键字;The second keyword matching unit is configured to search the database for target keywords that match the query keywords;

数据库数据查找单元,被配置为将与所述目标关键字相关联的数据库数据确定为与所述数据查询请求相匹配的目标数据库数据。The database data lookup unit is configured to identify database data associated with the target keyword as target database data that matches the data query request.

在本申请的一些实施例中,基于以上技术方案,所述第二执行模块还包括:In some embodiments of this application, based on the above technical solutions, the second execution module further includes:

加锁单元,被配置为通过发起所述数据查询请求的当前线程发起获取线程锁的加锁请求;The locking unit is configured to initiate a locking request to acquire the thread lock through the current thread that initiated the data query request;

休眠单元,被配置为若所述当前线程加锁失败,则将所述当前线程配置为休眠状态;The sleep unit is configured to put the current thread into a sleep state if the current thread fails to acquire the lock.

运行单元,被配置为若所述当前线程加锁成功,则令所述当前线程保持运行状态。The running unit is configured to keep the current thread running if the current thread successfully acquires the lock.

在本申请的一些实施例中,基于以上技术方案,所述休眠单元包括:In some embodiments of this application, based on the above technical solutions, the sleep unit includes:

监测子单元,被配置为监测所述当前线程以确定是否满足所述当前线程的唤醒条件;The monitoring subunit is configured to monitor the current thread to determine whether the wake-up condition of the current thread is met;

唤醒子单元,被配置为当满足所述当前线程的唤醒条件时,将所述当前线程配置为运行状态,以通过所述当前线程重新发起数据查询请求。The wake-up subunit is configured to set the current thread to a running state when the wake-up condition of the current thread is met, so as to re-initiate the data query request through the current thread.

在本申请的一些实施例中,基于以上技术方案,所述监测子单元包括:In some embodiments of this application, based on the above technical solutions, the monitoring subunit includes:

时间监测子单元,被配置为监测所述当前线程的休眠时间;The time monitoring subunit is configured to monitor the sleep time of the current thread;

第一执行子单元,被配置为若所述休眠时间大于或者等于预设的时间阈值,则确定满足所述当前线程的唤醒条件;The first execution subunit is configured to determine that the wake-up condition of the current thread is met if the sleep time is greater than or equal to a preset time threshold.

第二执行子单元,被配置为若所述休眠时间小于所述时间阈值,则确定不满足所述当前线程的唤醒条件。The second execution subunit is configured to determine that the wake-up condition of the current thread is not met if the sleep time is less than the time threshold.

在本申请的一些实施例中,基于以上技术方案,所述监测子单元包括:In some embodiments of this application, based on the above technical solutions, the monitoring subunit includes:

状态监测子单元,被配置为监测所述当前线程请求获取的线程锁的当前状态;The state monitoring subunit is configured to monitor the current state of the thread lock that the current thread is requesting to acquire;

第三执行子单元,被配置为若所述线程锁处于释放状态,则确定满足所述当前线程的唤醒条件;The third execution subunit is configured to determine that the wake-up condition of the current thread is met if the thread lock is in a released state.

第四执行子单元,被配置为若所述线程锁处于锁定状态,则确定不满足所述当前线程的唤醒条件。The fourth execution subunit is configured to determine that the wake-up condition of the current thread is not met if the thread lock is in a locked state.

在本申请的一些实施例中,基于以上技术方案,所述线程锁为互斥锁。In some embodiments of this application, based on the above technical solutions, the thread lock is a mutex lock.

在本申请的一些实施例中,基于以上技术方案,所述第二执行模块还包括:In some embodiments of this application, based on the above technical solutions, the second execution module further includes:

缓存更新单元,被配置为根据所述目标数据库数据更新所述缓存中的目标缓存数据;The cache update unit is configured to update the target cache data in the cache according to the target database data;

时间重置单元,被配置为重置所述目标缓存数据的超时时间和失效时间;The time reset unit is configured to reset the timeout and expiration time of the target cached data;

数据返回单元,被配置为释放所述线程锁,并向所述数据查询请求的请求方返回更新后的目标缓存数据。The data return unit is configured to release the thread lock and return the updated target cached data to the requester of the data query request.

根据本申请实施例的一个方面,提供一种计算机可读介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如以上技术方案中的数据处理方法。According to one aspect of the embodiments of this application, a computer-readable medium is provided, on which a computer program is stored, which, when executed by a processor, implements the data processing method as described in the above technical solutions.

根据本申请实施例的一个方面,提供一种电子设备,该电子设备包括:处理器;以及存储器,用于存储所述处理器的可执行指令;其中,所述处理器被配置为经由执行所述可执行指令来执行如以上技术方案中的数据处理方法。According to one aspect of the embodiments of this application, an electronic device is provided, the electronic device comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform a data processing method as described above by executing the executable instructions.

根据本申请实施例的一个方面,提供一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行如以上技术方案中的数据处理方法。According to one aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the data processing method as described in the above technical solutions.

在本申请实施例提供的技术方案中,通过在目标缓存数据的超时时间未过期时向所述数据查询请求的请求方返回目标缓存数据,在目标缓存数据的超时时间已过期时延长所述目标缓存数据的超时时间,并在数据库中查找与所述数据查询请求相匹配的目标数据库数据,可以令超时时间已过期但失效时间未过期的目标缓存数据重新可用,并且对该超时时间已过期的目标缓存数据进行数据更新,从而能够使得查询频繁的缓存数据实现长时间持续性地不失效,以避免大量查询同时在查询一个缓存数据且当该缓存数据刚好失效时发生的缓存击穿和查询故障问题,还能够避免缓存失效后查询数据库所需的时间造成请求的等待,从而提高系统响应速度。In the technical solution provided in this application embodiment, by returning the target cached data to the requester of the data query request before the timeout period of the target cached data expires, extending the timeout period of the target cached data after the timeout period has expired, and searching for target database data that matches the data query request in the database, the target cached data whose timeout period has expired but whose expiration time has not expired can be made available again, and the target cached data whose timeout period has expired can be updated. This enables frequently queried cached data to remain valid for a long time, avoiding cache breakdown and query failure problems that occur when a large number of queries simultaneously query the same cached data and the cached data just expires. It also avoids the waiting time required for querying the database after cache expiration, thereby improving the system response speed.

应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本申请。It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application.

附图说明Attached Figure Description

此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本申请的实施例,并与说明书一起用于解释本申请的原理。显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

图1示意性地示出了应用本申请技术方案的示例性系统架构框图。Figure 1 schematically illustrates an exemplary system architecture block diagram applying the technical solution of this application.

图2示意性地示出了本申请实施例提供的数据处理方法的步骤流程。Figure 2 schematically illustrates the steps of the data processing method provided in the embodiments of this application.

图3示意性地示出了本申请技术方案的数据查询请求的在示例性架构下的示例性处理步骤流程。Figure 3 schematically illustrates the exemplary processing steps of the data query request of the technical solution of this application under the exemplary architecture.

图4示意性地示出了本申请实施例中在缓存中查找与数据查询请求相匹配的目标缓存数据的部分步骤流程。Figure 4 schematically illustrates part of the steps in an embodiment of this application for finding target cached data that matches a data query request in the cache.

图5示意性地示出了本申请实施例中在缓存中查找与数据查询请求相匹配的目标缓存数据的部分步骤流程。Figure 5 schematically illustrates part of the steps in an embodiment of this application for finding target cached data that matches a data query request in the cache.

图6示意性地示出了本申请实施例中延长目标缓存数据的超时时间的步骤流程。Figure 6 schematically illustrates the steps for extending the timeout period of the target cached data in an embodiment of this application.

图7示意性地示出了本申请实施例中将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点的步骤流程。Figure 7 schematically illustrates the steps in an embodiment of this application to extend the timeout of the target cached data to a target time point between the request time and the expiration time of the target cached data.

图8示意性地示出了本申请实施例中统计内容触发操作的步骤流程。Figure 8 schematically illustrates the steps of the statistical content triggering operation in an embodiment of this application.

图9示意性地示出了本申请实施例中在数据库中查找与数据查询请求相匹配的目标数据库数据之前的步骤流程。Figure 9 schematically illustrates the steps in an embodiment of this application before searching for target database data that matches the data query request.

图10示意性地示出了本申请实施例中将当前线程配置为休眠状态之后的步骤流程。Figure 10 schematically illustrates the steps after configuring the current thread to a sleep state in an embodiment of this application.

图11示意性地示出了本申请实施例中监测当前线程以确定是否满足当前线程的唤醒条件的步骤流程。Figure 11 schematically illustrates the steps in an embodiment of this application to monitor the current thread to determine whether the wake-up conditions of the current thread are met.

图12示意性地示出了本申请实施例中监测当前线程以确定是否满足当前线程的唤醒条件的步骤流程。Figure 12 schematically illustrates the steps in an embodiment of this application to monitor the current thread to determine whether the wake-up conditions of the current thread are met.

图13示意性地示出了本申请实施例中在数据库中查找与数据查询请求相匹配的目标数据库数据之后的步骤流程。Figure 13 schematically illustrates the steps in an embodiment of this application after searching for target database data that matches the data query request in the database.

图14示意性地示出了本申请实施例提供的数据处理系统1400的结构框图。Figure 14 schematically shows a structural block diagram of the data processing system 1400 provided in an embodiment of this application.

图15示意性示出了适于用来实现本申请实施例的电子设备的计算机系统结构框图。Figure 15 schematically illustrates a computer system architecture block diagram suitable for implementing electronic devices according to embodiments of the present application.

具体实施方式Detailed Implementation

现在将参考附图更全面地描述示例实施方式。然而,示例实施方式能够以多种形式实施,且不应被理解为限于在此阐述的范例;相反,提供这些实施方式使得本申请将更加全面和完整,并将示例实施方式的构思全面地传达给本领域的技术人员。Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.

此外,所描述的特征、结构或特性可以以任何合适的方式结合在一个或更多实施例中。在下面的描述中,提供许多具体细节从而给出对本申请的实施例的充分理解。然而,本领域技术人员将意识到,可以实践本申请的技术方案而没有特定细节中的一个或更多,或者可以采用其它的方法、组元、装置、步骤等。在其它情况下,不详细示出或描述公知方法、装置、实现或者操作以避免模糊本申请的各方面。Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.

附图中所示的方框图仅仅是功能实体,不一定必须与物理上独立的实体相对应。即,可以采用软件形式来实现这些功能实体,或在一个或多个硬件模块或集成电路中实现这些功能实体,或在不同网络和/或处理器装置和/或微控制器装置中实现这些功能实体。The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and/or processor devices and/or microcontroller devices.

附图中所示的流程图仅是示例性说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解,而有的操作/步骤可以合并或部分合并,因此实际执行的顺序有可能根据实际情况改变。The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations/steps, nor do they necessarily have to be performed in the described order. For example, some operations/steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

图1示意性地示出了应用本申请技术方案的示例性系统架构框图。Figure 1 schematically illustrates an exemplary system architecture block diagram applying the technical solution of this application.

如图1所示,系统架构100可以包括终端设备110、网络120和服务器130。终端设备110可以包括智能手机、平板电脑、笔记本电脑、台式电脑、车载设备等各种电子设备。服务器130可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云计算服务的云服务器。网络120可以是能够在终端设备110和服务器130之间提供通信链路的各种连接类型的通信介质,例如可以是有线通信链路或者无线通信链路。As shown in Figure 1, the system architecture 100 may include terminal devices 110, a network 120, and a server 130. Terminal devices 110 may include various electronic devices such as smartphones, tablets, laptops, desktop computers, and in-vehicle devices. Server 130 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. Network 120 may be a communication medium of various connection types capable of providing a communication link between terminal devices 110 and server 130, such as a wired communication link or a wireless communication link.

根据实现需要,本申请实施例中的系统架构可以具有任意数目的终端设备、网络和服务器。例如,服务器130可以是由多个服务器设备组成的服务器群组。另外,本申请实施例提供的技术方案可以应用于终端设备110,也可以应用于服务器130,或者可以由终端设备110和服务器130共同实施,本申请对此不做特殊限定。Depending on the implementation requirements, the system architecture in this application embodiment can have any number of terminal devices, networks, and servers. For example, server 130 can be a server group composed of multiple server devices. In addition, the technical solutions provided in this application embodiment can be applied to terminal device 110, or to server 130, or can be implemented jointly by terminal device 110 and server 130. This application does not impose any special limitations on this.

举例而言,服务器130上可以存储有金融支付协议以供查询,终端设备110可以发起查询请求以对服务器130上的金融支付协议进行查询。当用户委托微信支付平台进行代扣时,到了预设的代扣时间,微信支付平台会发出数据查询请求查询服务器上用户签订的金融支付协议以扣费,当同一时间大量代扣请求产生时,会产生大量数据查询请求以查询服务器上用户签订的金融支付协议,会造成高并发的查询,大量查询同时在查询一个缓存数据,当该缓存数据刚好失效时,会导致大量请求直接访问数据库,对数据库造成冲击,造成数据库和缓存的查询故障问题。为了避免对数据库造成冲击,造成数据库和缓存的查询故障问题,可以在终端设备110或者服务器130执行本申请提供的数据处理方法,通过在目标缓存数据的超时时间未过期时向所述数据查询请求的请求方返回目标缓存数据,在目标缓存数据的超时时间已过期时延长所述目标缓存数据的超时时间,并在数据库中查找与所述数据查询请求相匹配的目标数据库数据以更新缓存,可以令超时时间已过期的但失效时间未过期目标缓存数据重新可用,并且对该超时时间已过期的目标缓存数据进行数据更新,从而能够使得查询频繁的缓存数据实现长时间持续性地不失效,以避免大量查询同时在查询一个缓存数据且当该缓存数据刚好失效时发生的缓存击穿和查询故障问题,能够保证缓存的可用性,并保护数据库,提高业务的稳定性和数据库的可用性,还能够避免缓存失效后查询数据库所需的时间造成请求的等待,从而提高系统响应速度。For example, server 130 may store financial payment agreements for querying, and terminal device 110 may initiate a query request to query the financial payment agreements on server 130. When a user entrusts WeChat Pay to make a deduction, at the preset deduction time, WeChat Pay will send a data query request to query the financial payment agreement signed by the user on the server to deduct the fee. When a large number of deduction requests are generated at the same time, a large number of data query requests will be generated to query the financial payment agreement signed by the user on the server, resulting in high-concurrency queries. A large number of queries are also querying cached data. When the cached data happens to expire, a large number of requests will directly access the database, impacting the database and causing query failures in both the database and the cache. To avoid impacting the database and causing query failures in the database and cache, the data processing method provided in this application can be executed on the terminal device 110 or server 130. This method returns the target cached data to the requester of the data query request before the timeout expires, extends the timeout of the target cached data if it has expired, and searches the database for target database data matching the data query request to update the cache. This allows target cached data whose timeout has expired but whose expiration time has not yet expired to become available again, and updates the expired target cached data. This ensures that frequently queried cached data remains valid for a long time, preventing cache breakdown and query failures that occur when a large number of queries simultaneously query the same cached data and that data has just expired. This guarantees cache availability, protects the database, improves business stability and database availability, and avoids request waiting caused by the time required to query the database after cache expiration, thereby improving system response speed.

服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表、车载设备等,但并不局限于此。终端以及服务器可以通过有线或无线通信方式进行直接或间接地连接,本申请在此不做限制。The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, in-vehicle device, etc., but is not limited to these. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited herein.

云技术(Cloud technology)是基于云计算商业模式应用的网络技术、信息技术、整合技术、管理平台技术、应用技术等的总称,可以组成资源池,按需所用,灵活便利。云计算技术将变成重要支撑。技术网络系统的后台服务需要大量的计算、存储资源,如视频网站、图片类网站和更多的门户网站。伴随着互联网行业的高度发展和应用,将来每个物品都有可能存在自己的识别标志,都需要传输到后台系统进行逻辑处理,不同程度级别的数据将会分开处理,各类行业数据皆需要强大的系统后盾支撑,只能通过云计算来实现。Cloud technology is a collective term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies applied based on the cloud computing business model. It can form resource pools, providing flexible and convenient on-demand access. Cloud computing technology will become a crucial support. Backend services of technical network systems require substantial computing and storage resources, such as video websites, image websites, and many portal websites. With the rapid development and application of the internet industry, every item may have its own identification mark in the future, requiring transmission to backend systems for logical processing. Data at different levels will be processed separately, and various industry data will all require robust system support, which can only be achieved through cloud computing.

云计算(cloud computing)是一种计算模式,它将计算任务分布在大量计算机构成的资源池上,使各种应用系统能够根据需要获取计算力、存储空间和信息服务。提供资源的网络被称为“云”。“云”中的资源在使用者看来是可以无限扩展的,并且可以随时获取,按需使用,随时扩展,按使用付费。Cloud computing is a computing model that distributes computing tasks across a resource pool consisting of a large number of computers, enabling various application systems to access computing power, storage space, and information services as needed. The network providing these resources is called the "cloud." From the user's perspective, the resources in the "cloud" are infinitely scalable, readily available, on-demand, expandable, and pay-as-you-go.

作为云计算的基础能力提供商,会建立云计算资源池(简称云平台,一般称为IaaS(Infrastructure as a Service,基础设施即服务)平台,在资源池中部署多种类型的虚拟资源,供外部客户选择使用。云计算资源池中主要包括:计算设备(为虚拟化机器,包含操作系统)、存储设备、网络设备。As a provider of fundamental cloud computing capabilities, a cloud resource pool (referred to as a cloud platform, generally called an IaaS (Infrastructure as a Service) platform) is established. Various types of virtual resources are deployed in the resource pool for external customers to choose from. The cloud resource pool mainly includes: computing devices (virtualized machines containing operating systems), storage devices, and network devices.

按照逻辑功能划分,在IaaS(Infrastructure as a Service,基础设施即服务)层上可以部署PaaS(Platform as a Service,平台即服务)层,PaaS层之上再部署SaaS(Software as a Service,软件即服务)层,也可以直接将SaaS部署在IaaS上。PaaS为软件运行的平台,如数据库、web容器等。SaaS为各式各样的业务软件,如web门户网站、短信群发器等。一般来说,SaaS和PaaS相对于IaaS是上层。Based on logical function, a PaaS (Platform as a Service) layer can be deployed on top of the IaaS (Infrastructure as a Service) layer, and a SaaS (Software as a Service) layer can be deployed on top of the PaaS layer. Alternatively, SaaS can be directly deployed on top of IaaS. PaaS is the platform for running software, such as databases and web containers. SaaS refers to various types of business software, such as web portals and bulk SMS senders. Generally speaking, SaaS and PaaS are upper layers compared to IaaS.

云存储(cloud storage)是在云计算概念上延伸和发展出来的一个新的概念,分布式云存储系统(以下简称存储系统)是指通过集群应用、网格技术以及分布存储文件系统等功能,将网络中大量各种不同类型的存储设备(存储设备也称之为存储节点)通过应用软件或应用接口集合起来协同工作,共同对外提供数据存储和业务访问功能的一个存储系统。Cloud storage is a new concept that extends and develops from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) refers to a storage system that uses cluster applications, grid technology and distributed storage file systems to bring together a large number of storage devices of various types in the network (storage devices are also called storage nodes) to work together through application software or application interfaces to provide data storage and business access functions to the outside world.

目前,存储系统的存储方法为:创建逻辑卷,在创建逻辑卷时,就为每个逻辑卷分配物理存储空间,该物理存储空间可能是某个存储设备或者某几个存储设备的磁盘组成。客户端在某一逻辑卷上存储数据,也就是将数据存储在文件系统上,文件系统将数据分成许多部分,每一部分是一个对象,对象不仅包含数据而且还包含数据标识(ID,ID entity)等额外的信息,文件系统将每个对象分别写入该逻辑卷的物理存储空间,且文件系统会记录每个对象的存储位置信息,从而当客户端请求访问数据时,文件系统能够根据每个对象的存储位置信息让客户端对数据进行访问。Currently, the storage method in storage systems is as follows: Logical volumes are created, and during creation, physical storage space is allocated to each logical volume. This physical storage space may consist of a single storage device or the disks of several storage devices. Clients store data on a logical volume, which means storing the data on the file system. The file system divides the data into many parts, each part being an object. Each object contains not only the data but also additional information such as a data identifier (ID, ID entity). The file system writes each object to the physical storage space of that logical volume, and it records the storage location information of each object. Therefore, when a client requests access to data, the file system can allow the client to access the data based on the storage location information of each object.

存储系统为逻辑卷分配物理存储空间的过程,具体为:按照对存储于逻辑卷的对象的容量估量(该估量往往相对于实际要存储的对象的容量有很大余量)和独立冗余磁盘阵列(RAID,Redundant Array of Independent Disk)的组别,预先将物理存储空间划分成分条,一个逻辑卷可以理解为一个分条,从而为逻辑卷分配了物理存储空间。The process by which a storage system allocates physical storage space to a logical volume is as follows: the physical storage space is pre-divided into stripes according to the capacity estimate of the objects stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the grouping of Redundant Array of Independent Disks (RAID). A logical volume can be understood as a stripe, thus allocating physical storage space to the logical volume.

数据库(Database),简而言之可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进行新增、查询、更新、删除等操作。所谓“数据库”是以一定方式储存在一起、能与多个用户共享、具有尽可能小的冗余度、与应用程序彼此独立的数据集合。A database, simply put, can be viewed as an electronic filing cabinet—a place to store electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, with minimal redundancy, and independent of application programs.

数据库管理系统(英语:Database Management System,简称DBMS)是为管理数据库而设计的电脑软件系统,一般具有存储、截取、安全保障、备份等基础功能。数据库管理系统可以依据它所支持的数据库模型来作分类,例如关系式、XML(Extensible MarkupLanguage,即可扩展标记语言);或依据所支持的计算机类型来作分类,例如服务器群集、移动电话;或依据所用查询语言来作分类,例如SQL(结构化查询语言(Structured QueryLanguage)、XQuery;或依据性能冲量重点来作分类,例如最大规模、最高运行速度;亦或其他的分类方式。不论使用哪种分类方式,一些DBMS能够跨类别,例如,同时支持多种查询语言。A Database Management System (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters or mobile devices; or according to the query language used, such as SQL (Structured Query Language) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, supporting multiple query languages simultaneously.

本发明实施例涉及的系统可以是由客户端、多个节点(接入网络中的任意形式的计算设备,如服务器、用户终端)通过网络通信的形式连接形成的分布式系统。如本申请所公开的数据处理方法或数据处理系统,其中多个服务器可组成为一区块链,而服务器为区块链上的节点。The system involved in the embodiments of the present invention can be a distributed system formed by connecting clients and multiple nodes (any form of computing device in the network, such as servers and user terminals) through network communication. As disclosed in the data processing method or data processing system of this application, multiple servers can form a blockchain, and the servers are nodes on the blockchain.

区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层。Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying platform, a platform product service layer, and an application service layer.

区块链底层平台可以包括用户管理、基础服务、智能合约等处理模块。其中,用户管理模块负责所有区块链参与者的身份信息管理,包括维护公私钥生成(账户管理)、密钥管理以及用户真实身份和区块链地址对应关系维护(权限管理)等,并且在授权的情况下,监管和审计某些真实身份的交易情况,提供风险控制的规则配置(风控审计);基础服务模块部署在所有区块链节点设备上,用来验证业务请求的有效性,并对有效请求完成共识后记录到存储上,对于一个新的业务请求,基础服务先对接口适配解析和鉴权处理(接口适配),然后通过共识算法将业务信息加密(共识管理),在加密之后完整一致的传输至共享账本上(网络通信),并进行记录存储;智能合约模块负责合约的注册发行以及合约触发和合约执行,开发人员可以通过某种编程语言定义合约逻辑,发布到区块链上(合约注册),根据合约条款的逻辑,调用密钥或者其它的事件触发执行,完成合约逻辑,同时还提供对合约升级注销的功能。The underlying blockchain platform can include processing modules such as user management, basic services, and smart contracts. The user management module is responsible for managing the identity information of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between user real identities and blockchain addresses (access management). Under authorization, it also monitors and audits transactions of certain real identities and provides risk control rule configuration (risk control audit). The basic services module is deployed on all blockchain node devices to verify the validity of business requests. After consensus is reached on valid requests, they are recorded in storage. For a new business request, the basic services first perform interface adaptation parsing and authentication (interface adaptation), then encrypt the business information using a consensus algorithm (consensus management), and finally transmit it completely and consistently to the shared ledger (network communication) for recording and storage. The smart contract module is responsible for contract registration, issuance, triggering, and execution. Developers can define contract logic using a programming language and publish it to the blockchain (contract registration). Based on the contract terms, execution is triggered by calling keys or other events to complete the contract logic. It also provides functions for contract upgrades and cancellations.

平台产品服务层提供典型应用的基本能力和实现框架,开发人员可以基于这些基本能力,叠加业务的特性,完成业务逻辑的区块链实现。应用服务层提供基于区块链方案的应用服务给业务参与方进行使用。The platform's product service layer provides the basic capabilities and implementation frameworks for typical applications. Developers can leverage these basic capabilities, along with the specific characteristics of their business needs, to implement blockchain-based business logic. The application service layer provides blockchain-based application services to business stakeholders.

下面结合具体实施方式对本申请提供的数据处理方法做出详细说明。The data processing method provided in this application will be described in detail below with reference to specific implementation methods.

图2示出了本申请某些实施方式的数据处理方法的步骤流程图,该数据处理方法的执行主体可以是终端设备,也可以是服务器等,本申请对此不设限。如图2所示,该信息处理方法主要可以包括如下步骤S210~步骤S240:Figure 2 shows a flowchart of the data processing method according to certain embodiments of this application. The executing entity of this data processing method can be a terminal device or a server, etc., and this application does not set any limitations. As shown in Figure 2, the information processing method mainly includes the following steps S210 to S240:

S210.响应于数据查询请求,在缓存中查找与数据查询请求相匹配的目标缓存数据。S210. In response to a data query request, locate the target cached data that matches the data query request in the cache.

将会经常访问的数据复制到靠近应用程序的快速存储中缓存,可以提高系统性能和伸缩性。缓存可以为Memcached,Memcached是一种分布式的高速缓存系统,可以通过缓存数据库以查询数据,减少数据库访问次数,能够提高网页或应用服务器的响应速度。Frequently accessed data can be copied to a fast storage location closer to the application for caching, which can improve system performance and scalability. One such cache is Memcached, a distributed high-speed caching system that caches database queries, reducing the number of database accesses and improving the response speed of web pages or application servers.

图3示意性地示出了内容展示主体中内容展示信息被触发展示的可视化效果。如图3所示,请求端可以产生大量的高并发请求,其中包括并发查询请求1和并发查询请求2。并发查询请求1和并发查询请求2对应的是同一个目标缓存数据。缓存响应于该高并发请求中的请求1和请求2在缓存中查找与数据查询请求相匹配的目标缓存数据。Figure 3 schematically illustrates the visualization effect of content display information being triggered and displayed in the main content display body. As shown in Figure 3, the requesting end can generate a large number of high-concurrency requests, including concurrent query request 1 and concurrent query request 2. Concurrent query request 1 and concurrent query request 2 correspond to the same target cached data. In response to requests 1 and 2 in this high-concurrency request, the cache searches for the target cached data that matches the data query request in the cache.

S220.获取目标缓存数据的超时时间,并确定超时时间是否已过期,超时时间小于目标缓存数据的失效时间。S220. Obtain the timeout of the target cached data and determine whether the timeout has expired. The timeout is less than the expiration time of the target cached data.

查找到与数据查询请求相匹配的目标缓存数据后获取目标缓存数据的超时时间timeout1,并确定超时时间timeout1是否已过期,超时时间timeout1小于目标缓存数据的失效时间timeout2。超时时间已过期的缓存数据的超时时间戳的所在时刻已经超过当前的系统时间,指示该缓存数据较旧,需要查询数据库以更新。超时时间timeout1已过期但失效时间timeout2未过期的缓存数据还保存在缓存中,该缓存数据可以被读取出来,只是数据较旧。而失效时间timeout2已过期的缓存数据已经不在缓存中存储,无法被读取出来。After finding the target cached data that matches the data query request, the timeout period (timeout1) of the target cached data is obtained, and it is determined whether timeout1 has expired. Timeout1 is less than the expiration time (timeout2) of the target cached data. If the timeout timestamp of cached data has expired, the timeout is older than the current system time, indicating that the cached data is outdated and needs to be updated by querying the database. Cached data whose timeout1 has expired but whose expiration time (timeout2) has not expired is still stored in the cache and can be read, but the data is older. Cached data whose expiration time (timeout2) has expired is no longer stored in the cache and cannot be read.

具体地,可以获取当前系统时间,并将当前系统时间与超时时间timeout1所在的时刻进行比较,来确定超时时间timeout1是否已过期。若当前系统时间所在时刻位于超时时间timeout1所在的时刻之后,则认为超时时间timeout1已过期。若当前系统时间所在时刻位于超时时间timeout1所在的时刻之前或当前系统时间所在时刻与超时时间timeout1所在的时刻为同一时刻,则认为超时时间timeout1未过期。Specifically, the current system time can be obtained and compared with the timeout period (timeout1) to determine whether timeout1 has expired. If the current system time is after the timeout period (timeout1), then timeout1 is considered expired. If the current system time is before the timeout period (timeout1) or the two times are the same, then timeout1 is considered not expired.

同理,可以获取当前系统时间,并将当前系统时间与失效时间Timeout2所在的时刻进行比较,来确定失效时间Timeout2是否已过期。若当前系统时间所在时刻位于失效时间Timeout2所在的时刻之后,则认为失效时间Timeout2已过期。若当前系统时间所在时刻位于失效时间Timeout2所在的时刻之前或当前系统时间所在时刻与失效时间Timeout2所在的时刻为同一时刻,则认为失效时间Timeout2未过期。Similarly, the current system time can be obtained and compared with the time of expiration time 2 to determine whether expiration time 2 has expired. If the current system time is after the time of expiration time 2, then expiration time 2 is considered to have expired. If the current system time is before the time of expiration time 2, or if the current system time and the time of expiration time 2 are the same, then expiration time 2 is considered not to have expired.

S230.若超时时间未过期,则向数据查询请求的请求方返回目标缓存数据。S230. If the timeout period has not expired, return the target cached data to the requester of the data query request.

当超时时间timeout1未过期时,则目标缓存数据仍保存在缓存中并且还无需进行更新,此时则向数据查询请求的请求方直接返回目标缓存数据,系统的响应速度较快。If the timeout period 1 has not expired, the target cached data is still stored in the cache and does not need to be updated. At this time, the target cached data is directly returned to the requester of the data query request, and the system response speed is relatively fast.

S240.若超时时间已过期,则延长目标缓存数据的超时时间,并在数据库中查找与数据查询请求相匹配的目标数据库数据。S240. If the timeout period has expired, extend the timeout period of the target cached data and search the database for target database data that matches the data query request.

当超时时间timeout1已过期时,则延长目标缓存数据的超时时间timeout1,并在数据库中查找与数据查询请求相匹配的目标数据库数据,以将该目标数据库数据更新到缓存中成为新的目标缓存数据,并且覆盖或删除原有的超时时间timeout1已过期的目标缓存数据。如图3所示,在缓存中与并发查询服务的数据查询请求1相匹配的目标缓存数据的timeout1已过期,则延长timeout1并将延长后的timeout1作为与数据查询请求1相匹配的目标缓存数据的新的超时时间,从而能够使得在数据查询请求1之后,与请求1携带的查询关键字相同的并发查询服务的请求2到达缓存时,请求2查找缓存数据并获取到该目标缓存数据的超时时间timeout1未过期,timeout2位于timeout1之后因此timeout2也未过期,因而请求2能够直接命中缓存并返回缓存数据,从而能够提升系统的响应速度。When timeout1 expires, the timeout of the target cached data is extended by timeout1. The system then searches the database for target database data that matches the data query request, updates the cache with this new target cached data, and overwrites or deletes the original target cached data whose timeout1 has expired. As shown in Figure 3, if the timeout1 of the target cached data matching the concurrent query service's data query request 1 has expired, timeout1 is extended and used as the new timeout for the target cached data matching data query request 1. This ensures that when concurrent query service request 2, carrying the same query keyword as request 1, arrives at the cache after data query request 1, the timeout1 for request 2 to find and retrieve the target cached data has not expired, and timeout2, being after timeout1, has also not expired. Therefore, request 2 can directly hit the cache and return the cached data, thus improving the system's response speed.

具体例子中,超时时间timeout1可以设置为缓存数据生成之后10分钟的时刻,失效时间timeout2可以设置为缓存数据生成之后20分钟的时刻。当目标缓存数据的超时时间timeout1已过期时,则延长目标缓存数据的超时时间timeout1,例如,将长目标缓存数据的超时时间timeout1从缓存数据生成之后10分钟的时刻延长至缓存数据生成之后15分钟的时刻,此时,延长后的超时时间timeout1仍小于失效时间timeout2,也就是说延长后的超时时间timeout1所在时刻仍位于失效时间timeout2所在时刻之前。In a specific example, the timeout period (timeout1) can be set to 10 minutes after the cached data is generated, and the expiration period (timeout2) can be set to 20 minutes after the cached data is generated. When the timeout period (timeout1) of the target cached data has expired, the timeout period (timeout1) of the target cached data is extended. For example, the timeout period (timeout1) of the target cached data is extended from 10 minutes after the cached data is generated to 15 minutes after the cached data is generated. In this case, the extended timeout period (timeout1) is still less than the expiration period (timeout2), meaning that the time of the extended timeout period (timeout1) is still before the time of the expiration period (timeout2).

设置超时时间或失效时间的伪代码可以如下所示:The pseudocode for setting a timeout or expiration time can be shown below:

下面结合图4~图11对以上实施例中的部分步骤进行详细说明。The following describes some of the steps in the above embodiments in detail with reference to Figures 4 to 11.

图4示意性地示出了本申请实施例中在缓存中查找与数据查询请求相匹配的目标缓存数据的部分步骤流程。如图4所示,在以上实施例的基础上,步骤S210中的在缓存中查找与数据查询请求相匹配的目标缓存数据,可以进一步包括以下步骤S410~步骤S430:Figure 4 schematically illustrates part of the steps in the embodiment of this application for finding target cache data that matches the data query request in the cache. As shown in Figure 4, based on the above embodiment, step S210, finding target cache data that matches the data query request in the cache, can further include the following steps S410 to S430:

S410.获取数据查询请求中携带的查询关键字;S410. Obtain the query keywords carried in the data query request;

S420.在缓存中查找与查询关键字相匹配的目标关键字,并确定目标关键字的失效时间是否已过期;S420. Locate the target keyword that matches the query keyword in the cache and determine whether the expiration time of the target keyword has expired;

S430.若目标关键字的失效时间未过期,则将与目标关键字相关联的缓存数据确定为与数据查询请求相匹配的目标缓存数据。S430. If the expiration time of the target keyword has not expired, the cached data associated with the target keyword will be determined as the target cached data that matches the data query request.

缓存可以以Key(关键字)-Value(值)的形式存储数据。数据查询请求中携带的查询关键字,可以通过该查询关键字在缓存中查找与查询关键字相匹配的目标关键字,并确定目标关键字的失效时间是否已过期。若目标关键字的失效时间未过期,则将与目标关键字相关联的缓存数据确定为与数据查询请求相匹配的目标缓存数据。其中,目标关键字的失效时间可以与对应的目标缓存数据的失效时间一致。例如,目标关键字的失效时间和对应的目标缓存数据的失效时间均为timeout2。Caching can store data in a key-value format. A query request carries a query keyword, which can be used to search the cache for a matching target keyword and determine if the target keyword's expiration time has expired. If the target keyword's expiration time has not expired, the cached data associated with that target keyword is identified as the target cached data matching the data query request. The expiration time of the target keyword can be the same as the expiration time of the corresponding target cached data. For example, both the expiration time of the target keyword and the expiration time of the corresponding target cached data can be `timeout2`.

图5示意性地示出了本申请实施例中在缓存中查找与数据查询请求相匹配的目标缓存数据的部分步骤流程。如图5所示,在以上实施例的基础上,步骤S210中的在缓存中查找与数据查询请求相匹配的目标缓存数据,还可以进一步包括以下步骤S510~步骤S530:Figure 5 schematically illustrates part of the steps in the embodiment of this application for finding target cache data that matches the data query request in the cache. As shown in Figure 5, based on the above embodiment, step S210, finding target cache data that matches the data query request in the cache, may further include the following steps S510 to S530:

S510.若目标关键字的失效时间已过期,则在数据库中查找与目标关键字相关联的数据库数据;S510. If the expiration time of the target keyword has expired, search the database for database data associated with the target keyword;

S520.根据查找得到的数据库数据更新与目标关键字相关联的缓存数据;S520. Update the cached data associated with the target keyword based on the retrieved database data;

S530.将更新后的缓存数据确定为与数据查询请求相匹配的目标缓存数据。S530. Determine the updated cached data as the target cached data that matches the data query request.

若目标关键字的失效时间timeout2已过期,说明在缓存中不再存储中目标关键字对应的目标缓存数据,或者缓存中存储的目标缓存数据已失效,不可用。此时,则在数据库中查找与目标关键字相关联的数据库数据,并根据查找得到的数据库数据更新与目标关键字相关联的缓存数据,进而将更新后的缓存数据确定为与数据查询请求相匹配的目标缓存数据,并将该目标缓存数据返回到发出数据查询请求的请求方。If the timeout period 2 for the target keyword has expired, it means that the target cache data corresponding to the target keyword is no longer stored in the cache, or the target cache data stored in the cache has expired and is unavailable. In this case, the database associated with the target keyword is searched, and the cache data associated with the target keyword is updated based on the searched database data. The updated cache data is then identified as the target cache data that matches the data query request, and this target cache data is returned to the requester who issued the data query request.

可以理解,缓存的存储空间有限制,当缓存空间被用满时,为了保证缓存在稳定服务的同时能够有效提升命中率,可以对缓存数据设置失效时间,以便在缓存数据失效时间过期后对该缓存数据进行清理,从而能保证缓存数据准确性的同时清理过期缓存,有利于提高缓存命中率。It is understandable that cache storage space is limited. When the cache space is full, in order to ensure stable service while effectively improving the hit rate, an expiration time can be set for the cache data. After the cache data expires, the cache data can be cleaned up, which can ensure the accuracy of the cache data while cleaning up expired cache, thus improving the cache hit rate.

图6示意性地示出了本申请实施例中延长目标缓存数据的超时时间的步骤流程。如图6所示,在以上实施例的基础上,步骤S240中的延长目标缓存数据的超时时间,可以进一步包括以下步骤S610~步骤S620:Figure 6 schematically illustrates the steps for extending the timeout period of the target cached data in an embodiment of this application. As shown in Figure 6, based on the above embodiment, extending the timeout period of the target cached data in step S240 may further include the following steps S610 to S620:

S610.根据数据查询请求中携带的请求时间戳确定发起数据查询请求的请求时间;S610. Determine the request time of initiating the data query request based on the request timestamp carried in the data query request;

S620.将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点。S620. Extend the timeout period of the target cached data to the target time point between the request time and the expiration time of the target cached data.

可以理解,根据数据查询请求中携带的请求时间戳确定发起数据查询请求的请求时间,并且将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点,可以使得目标缓存时间能在发起数据查询请求之后一段时间内超时时间不过期,该段时间可以为2分钟、3分钟、4分钟、5分钟、6分钟等,在该段时间内,数据查询请求已经足以从数据库中完成查找并将与数据查询请求相匹配的目标数据库数据返回到缓存中,并根据目标数据库数据更新缓存中的目标缓存数据。此时缓存数据的生成时间也随缓存中的目标缓存数据更新而更新,缓存数据的生成时间更新为当前系统时间,与此同时,目标缓存数据的超时时间和失效时间也被重置,例如将目标缓存数据的超时时间重置为缓存数据生成之后10分钟的时刻,将目标缓存数据的失效时间重置为缓存数据生成之后20分钟的时刻。由此,能够保证,在数据查询请求1查询数据库的过程中,目标缓存数据的超时时间不过期,能够直接命中缓存并返回,有利于提高系统响应速度。并且,在数据查询请求1查询数据库完成后能够根据目标数据库数据更新缓存中的目标缓存数据,并且重置目标缓存数据的超时时间和失效时间,有利于提高缓存中的数据的准确性。It's understandable that determining the request time based on the request timestamp carried in the data query request, and extending the timeout of the target cached data to a target time point between the request time and the expiration time of the target cached data, ensures that the target cache timeout does not expire for a period after the data query request is initiated. This period could be 2 minutes, 3 minutes, 4 minutes, 5 minutes, 6 minutes, etc. Within this period, the data query request has sufficient time to complete the search in the database and return the target database data matching the data query request to the cache, and update the target cached data in the cache according to the target database data. At this time, the generation time of the cached data is also updated along with the update of the target cached data in the cache, updating to the current system time. Simultaneously, the timeout and expiration time of the target cached data are also reset, for example, resetting the timeout of the target cached data to 10 minutes after the cached data was generated, and resetting the expiration time of the target cached data to 20 minutes after the cached data was generated. Therefore, it can be guaranteed that during the data query request 1's database query, the timeout of the target cached data does not expire, allowing for direct cache hits and returns, which helps improve system response speed. Furthermore, after data query request 1 completes the database query, it can update the target cache data in the cache based on the target database data, and reset the timeout and expiration time of the target cache data, which helps to improve the accuracy of the data in the cache.

图7示意性地示出了本申请实施例中将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点的步骤流程。如图7所示,在以上实施例的基础上,步骤S620中的将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点,还可以进一步包括以下步骤S710~步骤S730:Figure 7 schematically illustrates the steps of extending the timeout of the target cached data to a target time point between the request time and the expiration time of the target cached data in an embodiment of this application. As shown in Figure 7, based on the above embodiment, step S620, extending the timeout of the target cached data to a target time point between the request time and the expiration time of the target cached data, may further include the following steps S710 to S730:

S710.获取请求时间与目标缓存数据的超时时间之间的时间差;S710. Obtain the time difference between the request time and the timeout of the target cached data;

S720.根据时间差选取位于请求时间和目标缓存数据的失效时间之间的目标时间点;S720. Select the target time point between the request time and the expiration time of the target cached data based on the time difference;

S730.将目标缓存数据的超时时间延长至目标时间点。S730. Extend the timeout period for the target cached data to the target time point.

将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点的具体过程可以为,获取数据查询请求的请求时间与目标缓存数据的超时时间之间的时间差,并根据时间差选取位于请求时间和目标缓存数据的失效时间之间的目标时间点。当数据查询请求的请求时间与目标缓存数据的超时时间之间的时间差较大时,将目标时间点选取为较接近于目标缓存数据的失效时间的时间点。The specific process of extending the timeout of the target cached data to a target time point between the request time and the expiration time of the target cached data can be as follows: obtain the time difference between the request time of the data query request and the timeout time of the target cached data, and select a target time point between the request time and the expiration time of the target cached data based on the time difference. When the time difference between the request time of the data query request and the timeout time of the target cached data is large, the target time point is selected as a time point closer to the expiration time of the target cached data.

图8示意性地示出了本申请实施例中在数据库中查找与数据查询请求相匹配的目标数据库数据的步骤流程。如图8所示,在以上实施例的基础上,步骤S240中的在数据库中查找与数据查询请求相匹配的目标数据库数据,还可以进一步包括以下步骤S810~步骤S830:Figure 8 schematically illustrates the steps of searching for target database data that matches the data query request in the database according to an embodiment of this application. As shown in Figure 8, based on the above embodiment, step S240, searching for target database data that matches the data query request in the database, may further include the following steps S810 to S830:

S810.获取数据查询请求中携带的查询关键字;S810. Obtain the query keywords carried in the data query request;

S820.在数据库中查找与查询关键字相匹配的目标关键字;S820. Search the database for target keywords that match the query keywords;

S830.将与目标关键字相关联的数据库数据确定为与数据查询请求相匹配的目标数据库数据。S830. Identify the database data associated with the target keyword as the target database data that matches the data query request.

数据库也可以以Key-Value的形式存储数据。数据查询请求中携带有查询关键字,可以通过该查询关键字在数据库中查找与查询关键字相匹配的目标关键字,并在数据库查询过程中将与目标关键字相关联的数据库数据确定为与数据查询请求相匹配的目标数据库数据。数据库和缓存均以Key-Value的形式存储数据,可以方便数据查询,以及方便数据库中的目标数据库数据对缓存数据进行更新。Databases can also store data in key-value pairs. Data query requests carry query keywords, which can be used to search the database for target keywords that match the query keywords. During the database query process, the database data associated with the target keywords is identified as the target database data that matches the data query request. Both databases and caches store data in key-value pairs, which facilitates data retrieval and allows the target database data to easily update the cached data.

图9示意性地示出了本申请实施例中在数据库中查找与数据查询请求相匹配的目标数据库数据之前的步骤流程。如图9所示,在以上实施例的基础上,在步骤S240的在数据库中查找与数据查询请求相匹配的目标数据库数据之前,还可以进一步包括以下步骤S910~步骤S930:Figure 9 schematically illustrates the steps in this embodiment before searching for target database data that matches the data query request in the database. As shown in Figure 9, based on the above embodiment, before searching for target database data that matches the data query request in the database in step S240, the following steps S910 to S930 may be further included:

S910.通过发起数据查询请求的当前线程发起获取线程锁的加锁请求;S910. The current thread that initiated the data query request initiates a lock acquisition request to obtain the thread lock;

S920.若当前线程加锁失败,则将当前线程配置为休眠状态;S920. If the current thread fails to acquire the lock, then configure the current thread to a sleeping state;

S930.若当前线程加锁成功,则令当前线程保持运行状态。S930. If the current thread successfully acquires the lock, then keep the current thread running.

在数据库中查找与数据查询请求相匹配的目标数据库数据之前,通过发起数据查询请求的当前线程发起获取线程锁的加锁请求,并且令加锁成功的线程保持运行状态,将加锁失败的当前线程配置为休眠状态,可以限制查询数据库的请求数,防止大量请求直接访问数据库,能够避免数据库受到冲击。只有成功获取到线程锁的请求才能查询数据库,其他请求只能进入休眠状态等待。Before searching for target database data that matches the query request, the current thread initiating the query request requests a lock acquisition request. Threads that successfully acquire the lock remain running, while threads that fail to acquire the lock are put into a sleep state. This limits the number of database query requests, preventing a large number of requests from directly accessing the database and avoiding database overload. Only requests that successfully acquire the thread lock can query the database; other requests must enter a sleep state and wait.

图10示意性地示出了本申请实施例中将当前线程配置为休眠状态之后的步骤流程。如图10所示,在以上实施例的基础上,在步骤S920的将当前线程配置为休眠状态之后,还可以进一步包括以下步骤S1010~步骤S1020:Figure 10 schematically illustrates the process flow after configuring the current thread to a sleep state in an embodiment of this application. As shown in Figure 10, based on the above embodiment, after configuring the current thread to a sleep state in step S920, the following steps S1010 to S1020 may be further included:

S1010.监测当前线程以确定是否满足当前线程的唤醒条件;S1010. Monitor the current thread to determine if the wake-up condition for the current thread is met;

S1020.当满足当前线程的唤醒条件时,将当前线程配置为运行状态,以通过当前线程重新发起数据查询请求。S1020. When the wake-up condition of the current thread is met, configure the current thread to run so that the data query request can be re-initiated through the current thread.

将当前线程配置为休眠状态之后,可以监测当前线程以确定是否满足当前线程的唤醒条件以便再次将线程唤醒。当满足当前线程的唤醒条件时,将当前线程配置为运行状态,以通过当前线程重新发起数据查询请求,从而使得当前线程能够重新发起该数据查询请求以继续完成数据查询。After configuring the current thread to a sleeping state, the current thread can be monitored to determine whether the wake-up conditions are met so that the thread can be woken up again. When the wake-up conditions are met, the current thread is configured to run, allowing it to re-initiate the data query request and continue completing the data query.

图11示意性地示出了本申请实施例中监测当前线程以确定是否满足当前线程的唤醒条件的步骤流程。如图11所示,在以上实施例的基础上,步骤S1010中的监测当前线程以确定是否满足当前线程的唤醒条件,可以进一步包括以下步骤S1110~步骤S1130:Figure 11 schematically illustrates the steps of monitoring the current thread to determine whether the wake-up condition of the current thread is met in an embodiment of this application. As shown in Figure 11, based on the above embodiment, the monitoring of the current thread in step S1010 to determine whether the wake-up condition of the current thread is met may further include the following steps S1110 to S1130:

S1110.监测当前线程的休眠时间;S1110. Monitor the current thread's sleep time;

S1120.若休眠时间大于或者等于预设的时间阈值,则确定满足当前线程的唤醒条件;S1120. If the sleep time is greater than or equal to the preset time threshold, then the wake-up condition of the current thread is determined to be met;

S1130.若休眠时间小于时间阈值,则确定不满足当前线程的唤醒条件。S1130. If the sleep time is less than the time threshold, then it is determined that the wake-up condition of the current thread is not met.

监测当前线程以确定是否满足当前线程的唤醒条件,具体地,可以监测当前线程的休眠时间。若休眠时间大于或者等于预设的时间阈值,则确定满足当前线程的唤醒条件;若休眠时间小于时间阈值,则确定不满足当前线程的唤醒条件。时间阈值可以为设置为稍大于数据查询请求从数据库中查找并将数据返回更新到缓存中所需时间的长度。例如,当数据查询请求从数据库中查找并将数据返回更新到缓存中所需时间一般为8ms~10ms时,时间阈值可以设置为12ms。休眠时间达到时间阈值之前,进入数据查询请求已经足以从数据库中完成查找并将与数据查询请求相匹配的目标数据库数据返回到缓存中,并根据目标数据库数据更新缓存中的目标缓存数据,并且重置目标缓存数据的超时时间和失效时间。由此,在当前线程的休眠完成并唤醒之后,能够对缓存重新发起该数据查询请求以命中缓存,向该数据查询请求的请求方返回对应的目标缓存数据。The current thread is monitored to determine if its wake-up condition is met. Specifically, the current thread's sleep time can be monitored. If the sleep time is greater than or equal to a preset time threshold, the wake-up condition is met; if the sleep time is less than the time threshold, the wake-up condition is not met. The time threshold can be set slightly longer than the time required for a data query request to retrieve data from the database and update the cache. For example, if the time required for a data query request to retrieve data from the database and update the cache is typically 8ms to 10ms, the time threshold can be set to 12ms. Before the sleep time reaches the time threshold, the data query request has already completed its search in the database and returned the target database data matching the query request to the cache. The target cache data is then updated based on the target database data, and the timeout and expiration time of the target cache data are reset. Thus, after the current thread completes its sleep and wakes up, it can re-initiate the data query request to hit the cache and return the corresponding target cache data to the requester.

图12示意性地示出了本申请实施例中监测当前线程以确定是否满足当前线程的唤醒条件的步骤流程。如图12所示,在以上实施例的基础上,步骤S1010中的监测当前线程以确定是否满足当前线程的唤醒条件,可以进一步包括以下步骤S1210~步骤S1230:Figure 12 schematically illustrates the steps of monitoring the current thread to determine whether the wake-up condition of the current thread is met in an embodiment of this application. As shown in Figure 12, based on the above embodiment, the monitoring of the current thread in step S1010 to determine whether the wake-up condition of the current thread is met can further include the following steps S1210 to S1230:

S1210.监测当前线程请求获取的线程锁的当前状态;S1210. Monitor the current state of the thread lock that the current thread is requesting to acquire;

S1220.若线程锁处于释放状态,则确定满足当前线程的唤醒条件;S1220. If the thread lock is in a released state, then the wake-up condition of the current thread is determined to be met;

S1230.若线程锁处于锁定状态,则确定不满足当前线程的唤醒条件。S1230. If the thread lock is in a locked state, then it is determined that the wake-up condition of the current thread is not met.

监测当前线程以确定是否满足当前线程的唤醒条件,具体地,可以监测当前线程请求获取的线程锁的当前状态,若线程锁处于释放状态,则确定满足当前线程的唤醒条件;若线程锁处于锁定状态,则确定不满足当前线程的唤醒条件。可以理解,数据查询请求从数据库中成功取得数据并根据目标数据库数据更新缓存中的目标缓存数据,线程锁才会处于释放状态,此时,确定满足当前线程的唤醒条件,将当前线程唤醒并对缓存重新发起该数据查询请求以命中缓存,向该数据查询请求的请求方返回对应的目标缓存数据。由此,在线程锁处于释放状态时,将当前线程唤醒以对缓存重新发起该数据查询请求命中缓存;在线程锁处于锁定状态,不将当前线程唤醒,当前线程继续休眠等待制造线程所处于释放状态;能够使得线程锁在数据查询请求从数据库中成功取得数据并根据目标数据库数据更新缓存中的目标缓存数据的时机唤醒,从而能够使得休眠线程的等待时间缩减到最短,进而能够提高系统的响应速度。The system monitors the current thread to determine if its wake-up condition is met. Specifically, it monitors the current state of the thread lock the current thread is requesting. If the thread lock is in a released state, the wake-up condition is met; if the thread lock is in a locked state, the wake-up condition is not met. The thread lock is released only when a data query successfully retrieves data from the database and updates the target cache data based on the target database data. At this point, the wake-up condition is met, the current thread is woken up, and it re-initiates the data query to hit the cache, returning the corresponding target cache data to the requester. Therefore, when the thread lock is released, the current thread is woken up to re-initiate the data query to hit the cache; when the thread lock is locked, the current thread is not woken up and continues to sleep, waiting for the thread to be released. This ensures that the thread lock is woken up when the data query successfully retrieves data from the database and updates the target cache data based on the target database data, minimizing the waiting time of sleeping threads and improving system response speed.

在某些实施方式中,线程锁可以为互斥锁。互斥锁包括有互斥量(mutex),线程在访问共享资源前对互斥量进行加锁,线程在访问完成后释放互斥量上的锁。对互斥量进行加锁后,任何其他试图再次对互斥量加锁的线程将会被阻塞直到当前线程释放该互斥锁。如果释放互斥锁时有多个线程阻塞,所有在该互斥锁上的阻塞线程都会变成可运行状态,第一个变为可运行状态的线程可以对互斥量加锁,其他线程将会看到互斥锁依然被锁住,只能回去等待它重新变为可用。在这种方式下,每次只有一个线程可以向前运行查询数据库,从而可以防止大量请求直接访问数据库,能够避免数据库受到高并发请求的冲击,提高系统的稳定性。并且,对于高并发请求,同一时间内只有一个请求能够访问数据库查询数据,并将查询得到的数据更新到缓存中,可以避免多次对数据库的访问,从而能够节省系统资源。In some implementations, thread locks can be mutexes. A mutex consists of a mutex, which a thread acquires before accessing a shared resource and releases afterward. Once a mutex is locked, any other thread attempting to acquire it again will be blocked until the current thread releases the mutex. If multiple threads are blocked when the mutex is released, all blocked threads on that mutex become runnable. The first runnable thread can acquire the mutex, and other threads will see that the mutex is still locked and must wait for it to become available again. In this approach, only one thread can execute a database query at a time, preventing a large number of requests from directly accessing the database, thus avoiding the impact of high concurrency and improving system stability. Furthermore, for high concurrency requests, only one request can access the database to query data and update the cache at any given time, avoiding multiple database accesses and saving system resources.

图13示意性地示出了本申请实施例中在数据库中查找与数据查询请求相匹配的目标数据库数据之后的步骤流程。如图13所示,在以上实施例的基础上,在步骤S240的在数据库中查找与数据查询请求相匹配的目标数据库数据之后,还可以进一步包括以下步骤S1310~步骤S1330:Figure 13 schematically illustrates the steps following the search for target database data matching the data query request in the database in this embodiment of the application. As shown in Figure 13, based on the above embodiment, after searching for target database data matching the data query request in the database in step S240, the following steps S1310 to S1330 may be further included:

S1310.根据目标数据库数据更新缓存中的目标缓存数据;S1310. Update the target cache data in the cache according to the target database data;

S1320.重置目标缓存数据的超时时间和失效时间;S1320. Reset the timeout and expiration time of the target cached data;

S1330.释放线程锁,并向数据查询请求的请求方返回更新后的目标缓存数据。S1330. Release the thread lock and return the updated target cached data to the requester of the data query request.

在数据库中查找与数据查询请求相匹配的目标数据库数据之后,可以根据目标数据库数据更新缓存中的目标缓存数据,并重置目标缓存数据的超时时间和失效时间,接着释放线程锁,并向数据查询请求的请求方返回更新后的目标缓存数据,实现系统对数据查询请求方的响应。从而能够在数据查询请求每次查询数据库之后,可以将取得的数据库数据更新到缓存中,从而实现对缓存数据的更新。并且,对于访问越频繁的缓存数据,在缓存数据的超时时间过期但失效时间未过期的时间段内被访问的可能性越大,则对于访问频繁的缓存数据,在缓存数据的超时时间过期但失效时间未过期时,更有可能通过对应的目标数据库数据更新缓存中的目标缓存数据,并且重置目标缓存数据的超时时间和失效时间,从而能够在目标缓存数据尚未失效时就对目标缓存数据进行更新并重置失效时间,进而能够防止该访问频繁的目标缓存数据失效,提高系统对携带热点关键字的数据查询请求的响应速度,能够避免系统受到高并发请求的冲击。After retrieving the target database data that matches the data query request, the target cache data in the cache can be updated based on the target database data. The timeout and expiration time of the target cache data are then reset. The thread lock is released, and the updated target cache data is returned to the requester of the data query request, thus realizing the system's response to the data query requester. This allows the retrieved database data to be updated in the cache after each database query, thereby updating the cached data. Furthermore, for frequently accessed cached data, the likelihood of it being accessed within the period between the timeout and expiration time is higher. Therefore, for frequently accessed cached data, when the timeout expires but the expiration time has not, there is a greater chance that the target cache data in the cache will be updated based on the corresponding target database data, and the timeout and expiration time of the target cache data will be reset. This allows the target cache data to be updated and its expiration time reset before it expires, preventing the frequently accessed target cache data from becoming invalid. This improves the system's response speed to data query requests carrying hot keywords and avoids the system being impacted by high-concurrency requests.

相关技术中,为了保护数据库的安全性,即使不会有大量请求同时到达后端数据库,但是在缓存失效的瞬间,大量的请求会因为获取不到互斥锁而睡眠,在获取到线程锁的请求查询数据库结果返回之前,所有查询同一个key的请求都需要等待,只有在等待一段时间过后重试才能读取到数据,客户端得不到及时的响应,从而降低了查询服务的响应速度,使得扣费或者信息获取流程呈现卡顿。而在终端设备110或者服务器130执行本申请提供的数据处理方法,可以令超时时间已过期的但失效时间未过期目标缓存数据重新可用,避免在查询数据库过程中阻塞关键字相同的新的请求,而是使得该新的请求能够直接命中缓存并即时返回数据,并且对该超时时间已过期的目标缓存数据进行数据更新并且重置超时时间和失效时间,从而能够使得查询频繁的缓存数据实现长时间持续性地不失效,实现自动续期,能够保证缓存的持续的可用性,可以提高对缓存的命中率并保护数据库,提高系统业务的稳定性,还能够避免缓存失效后查询数据库所需的时间造成请求的等待,从而提高系统响应速度。In related technologies, to protect database security, even if a large number of requests do not arrive at the backend database simultaneously, at the moment the cache expires, a large number of requests will sleep because they cannot acquire the mutex lock. Before the request that acquires the thread lock returns the database query result, all requests querying the same key need to wait. Only after waiting for a period of time and retrying can the data be read. The client does not receive a timely response, thereby reducing the response speed of the query service and causing the billing or information retrieval process to be sluggish. When the data processing method provided in this application is executed on the terminal device 110 or the server 130, the target cache data whose timeout period has expired but whose expiration time has not expired can be made available again. This avoids blocking new requests with the same keywords during the database query process. Instead, it allows the new request to directly hit the cache and return the data immediately. Furthermore, the data of the target cache data whose timeout period has expired is updated and the timeout and expiration time are reset. This enables frequently queried cache data to remain valid for a long time and achieve automatic renewal. This ensures the continuous availability of the cache, improves the cache hit rate, protects the database, improves the stability of system business, and avoids the waiting time caused by the time required to query the database after the cache expires, thereby improving the system response speed.

应当注意,尽管在附图中以特定顺序描述了本申请中方法的各个步骤,但是,这并非要求或者暗示必须按照该特定顺序来执行这些步骤,或是必须执行全部所示的步骤才能实现期望的结果。附加的或备选的,可以省略某些步骤,将多个步骤合并为一个步骤执行,以及/或者将一个步骤分解为多个步骤执行等。It should be noted that although the steps of the method in this application are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and/or one step may be broken down into multiple steps.

以下介绍本申请的装置实施例,可以用于执行本申请上述实施例中的数据处理方法。图14示意性地示出了本申请实施例提供的数据处理系统1400的结构框图。如图14所示,数据处理系统1400可以包括:The following describes an apparatus embodiment of this application, which can be used to execute the data processing method described in the above embodiments of this application. Figure 14 schematically shows a structural block diagram of a data processing system 1400 provided in an embodiment of this application. As shown in Figure 14, the data processing system 1400 may include:

缓存查找模块1410,被配置为响应于数据查询请求,在缓存中查找与数据查询请求相匹配的目标缓存数据;The cache lookup module 1410 is configured to, in response to a data query request, search the cache for target cache data that matches the data query request.

时间获取模块1420,被配置为获取目标缓存数据的超时时间,并确定超时时间是否已过期,超时时间小于目标缓存数据的失效时间;The time acquisition module 1420 is configured to acquire the timeout period of the target cached data and determine whether the timeout period has expired. The timeout period is less than the expiration time of the target cached data.

第一执行模块1430,被配置为若超时时间未过期,则向数据查询请求的请求方返回目标缓存数据;The first execution module 1430 is configured to return the target cached data to the requester of the data query request if the timeout period has not expired.

第二执行模块1440,被配置为若超时时间已过期,则延长目标缓存数据的超时时间,并在数据库中查找与数据查询请求相匹配的目标数据库数据。The second execution module 1440 is configured to extend the timeout period of the target cached data if the timeout period has expired, and search for target database data that matches the data query request in the database.

在本申请的一些实施例中,基于以上技术方案,缓存查找模块1410包括:In some embodiments of this application, based on the above technical solutions, the cache lookup module 1410 includes:

第一关键字获取单元,被配置为获取数据查询请求中携带的查询关键字;The first keyword acquisition unit is configured to acquire the query keywords carried in the data query request;

第一关键字匹配单元,被配置为在缓存中查找与查询关键字相匹配的目标关键字,并确定目标关键字的失效时间是否已过期;The first keyword matching unit is configured to search for the target keyword that matches the query keyword in the cache and determine whether the expiration time of the target keyword has expired.

缓存数据查找单元,被配置为若目标关键字的失效时间未过期,则将与目标关键字相关联的缓存数据确定为与数据查询请求相匹配的目标缓存数据。The cached data lookup unit is configured to determine the cached data associated with the target keyword as the target cached data that matches the data query request if the expiration time of the target keyword has not expired.

在本申请的一些实施例中,基于以上技术方案,缓存查找模块1410还包括:In some embodiments of this application, based on the above technical solutions, the cache lookup module 1410 further includes:

执行单元,被配置为若目标关键字的失效时间已过期,则在数据库中查找与目标关键字相关联的数据库数据;The execution unit is configured to search for database data associated with the target keyword if the expiration time of the target keyword has expired.

缓存更新单元,被配置为根据查找得到的数据库数据更新与目标关键字相关联的缓存数据;The cache update unit is configured to update the cache data associated with the target keyword based on the retrieved database data;

目标缓存数据获取单元,被配置为将更新后的缓存数据确定为与数据查询请求相匹配的目标缓存数据。The target cache data acquisition unit is configured to determine the updated cache data as the target cache data that matches the data query request.

在本申请的一些实施例中,基于以上技术方案,第二执行模块1440包括:In some embodiments of this application, based on the above technical solutions, the second execution module 1440 includes:

第一延时单元,被配置为根据数据查询请求中携带的请求时间戳确定发起数据查询请求的请求时间;The first delay unit is configured to determine the request time for initiating the data query request based on the request timestamp carried in the data query request;

第二延时单元,被配置为将目标缓存数据的超时时间延长至位于请求时间和目标缓存数据的失效时间之间的目标时间点。The second delay unit is configured to extend the timeout period of the target cached data to a target time point between the request time and the expiration time of the target cached data.

在本申请的一些实施例中,基于以上技术方案,第二延时单元包括:In some embodiments of this application, based on the above technical solutions, the second delay unit includes:

时间差获取子单元,被配置为获取请求时间与目标缓存数据的超时时间之间的时间差;The time difference acquisition subunit is configured to acquire the time difference between the request time and the timeout of the target cached data.

目标时间点选取子单元,被配置为根据时间差选取位于请求时间和目标缓存数据的失效时间之间的目标时间点;The target time point selection subunit is configured to select a target time point between the request time and the expiration time of the target cached data based on the time difference.

延时子单元,被配置为将目标缓存数据的超时时间延长至目标时间点。The delay subunit is configured to extend the timeout period of the target cached data to the target time point.

在本申请的一些实施例中,基于以上技术方案,第二执行模块1440还包括:In some embodiments of this application, based on the above technical solutions, the second execution module 1440 further includes:

第二关键字获取单元,被配置为获取数据查询请求中携带的查询关键字;The second keyword acquisition unit is configured to acquire the query keywords carried in the data query request;

第二关键字匹配单元,被配置为在数据库中查找与查询关键字相匹配的目标关键字;The second keyword matching unit is configured to search the database for target keywords that match the query keywords;

数据库数据查找单元,被配置为将与目标关键字相关联的数据库数据确定为与数据查询请求相匹配的目标数据库数据。The database lookup unit is configured to identify database data associated with a target keyword as the target database data that matches the data query request.

在本申请的一些实施例中,基于以上技术方案,第二执行模块1440还包括:In some embodiments of this application, based on the above technical solutions, the second execution module 1440 further includes:

加锁单元,被配置为通过发起数据查询请求的当前线程发起获取线程锁的加锁请求;The locking unit is configured to initiate a locking request to acquire the thread lock through the current thread that initiated the data query request;

休眠单元,被配置为若当前线程加锁失败,则将当前线程配置为休眠状态;The sleep unit is configured to put the current thread into a sleep state if the current thread fails to acquire the lock.

运行单元,被配置为若当前线程加锁成功,则令当前线程保持运行状态。The execution unit is configured to keep the current thread running if the current thread successfully acquires the lock.

在本申请的一些实施例中,基于以上技术方案,休眠单元包括:In some embodiments of this application, based on the above technical solutions, the sleep unit includes:

监测子单元,被配置为监测当前线程以确定是否满足当前线程的唤醒条件;The monitoring subunit is configured to monitor the current thread to determine whether the wake-up condition of the current thread is met;

唤醒子单元,被配置为当满足当前线程的唤醒条件时,将当前线程配置为运行状态,以通过当前线程重新发起数据查询请求。The wake-up subunit is configured to set the current thread to a running state when the wake-up condition of the current thread is met, so that the data query request can be re-initiated through the current thread.

在本申请的一些实施例中,基于以上技术方案,监测子单元包括:In some embodiments of this application, based on the above technical solutions, the monitoring subunit includes:

时间监测子单元,被配置为监测当前线程的休眠时间;The time monitoring subunit is configured to monitor the sleep time of the current thread;

第一执行子单元,被配置为若休眠时间大于或者等于预设的时间阈值,则确定满足当前线程的唤醒条件;The first execution subunit is configured to determine that the wake-up condition of the current thread is met if the sleep time is greater than or equal to a preset time threshold.

第二执行子单元,被配置为若休眠时间小于时间阈值,则确定不满足当前线程的唤醒条件。The second execution subunit is configured to determine that the wake-up condition of the current thread is not met if the sleep time is less than the time threshold.

在本申请的一些实施例中,基于以上技术方案,监测子单元包括:In some embodiments of this application, based on the above technical solutions, the monitoring subunit includes:

状态监测子单元,被配置为监测当前线程请求获取的线程锁的当前状态;The state monitoring subunit is configured to monitor the current state of the thread lock that the current thread is requesting to acquire;

第三执行子单元,被配置为若线程锁处于释放状态,则确定满足当前线程的唤醒条件;The third execution subunit is configured to determine if the current thread wake-up condition is met if the thread lock is in a released state.

第四执行子单元,被配置为若线程锁处于锁定状态,则确定不满足当前线程的唤醒条件。The fourth execution subunit is configured to determine that the wake-up condition for the current thread is not met if the thread lock is in a locked state.

在本申请的一些实施例中,基于以上技术方案,线程锁为互斥锁。In some embodiments of this application, based on the above technical solutions, the thread lock is a mutex lock.

在本申请的一些实施例中,基于以上技术方案,第二执行模块1440还包括:In some embodiments of this application, based on the above technical solutions, the second execution module 1440 further includes:

缓存更新单元,被配置为根据目标数据库数据更新缓存中的目标缓存数据;The cache update unit is configured to update the target cache data in the cache based on the target database data.

时间重置单元,被配置为重置目标缓存数据的超时时间和失效时间;The time reset unit is configured to reset the timeout and expiration time of the target cached data.

数据返回单元,被配置为释放线程锁,并向数据查询请求的请求方返回更新后的目标缓存数据。The data return unit is configured to release the thread lock and return the updated target cached data to the requester of the data query request.

本申请各实施例中提供的数据处理系统的具体细节已经在对应的方法实施例中进行了详细的描述,此处不再赘述。The specific details of the data processing systems provided in the various embodiments of this application have been described in detail in the corresponding method embodiments, and will not be repeated here.

图15示意性地示出了用于实现本申请实施例的电子设备的计算机系统结构框图。Figure 15 schematically illustrates a computer system architecture block diagram for implementing an electronic device according to an embodiment of this application.

需要说明的是,图15示出的电子设备的计算机系统1500仅是一个示例,不应对本申请实施例的功能和使用范围带来任何限制。It should be noted that the computer system 1500 of the electronic device shown in Figure 15 is only an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

如图15所示,计算机系统1500包括中央处理器1501(Central Processing Unit,CPU),其可以根据存储在只读存储器1502(Read-Only Memory,ROM)中的程序或者从存储部分1508加载到随机访问存储器1503(Random Access Memory,RAM)中的程序而执行各种适当的动作和处理。在随机访问存储器1503中,还存储有系统操作所需的各种程序和数据。中央处理器1501、在只读存储器1502以及随机访问存储器1503通过总线1504彼此相连。输入/输出接口1505(Input/Output接口,即I/O接口)也连接至总线1504。As shown in Figure 15, the computer system 1500 includes a central processing unit (CPU) 1501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 1502 or programs loaded from storage section 1508 into random access memory (RAM). The RAM 1503 also stores various programs and data required for system operation. The CPU 1501, ROM 1502, and RAM 1503 are interconnected via a bus 1504. An input/output interface 1505 (I/O interface) is also connected to the bus 1504.

以下部件连接至输入/输出接口1505:包括键盘、鼠标等的输入部分1506;包括诸如阴极射线管(Cathode Ray Tube,CRT)、液晶显示器(Liquid Crystal Display,LCD)等以及扬声器等的输出部分1507;包括硬盘等的存储部分1508;以及包括诸如局域网卡、调制解调器等的网络接口卡的通信部分1509。通信部分1509经由诸如因特网的网络执行通信处理。驱动器1510也根据需要连接至输入/输出接口1505。可拆卸介质1511,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1510上,以便于从其上读出的计算机程序根据需要被安装入存储部分1508。The following components are connected to the input/output interface 1505: an input section 1506 including a keyboard, mouse, etc.; an output section 1507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1508 including a hard disk, etc.; and a communication section 1509 including a network interface card such as a local area network card, modem, etc. The communication section 1509 performs communication processing via a network such as the Internet. A drive 1510 is also connected to the input/output interface 1505 as needed. A removable medium 1511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 1510 as needed so that computer programs read from it can be installed into the storage section 1508 as needed.

特别地,根据本申请的实施例,各个方法流程图中所描述的过程可以被实现为计算机软件程序。例如,本申请的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分1509从网络上被下载和安装,和/或从可拆卸介质1511被安装。在该计算机程序被中央处理器1501执行时,执行本申请的系统中限定的各种功能。Specifically, according to embodiments of this application, the processes described in the various method flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1509, and/or installed from removable medium 1511. When the computer program is executed by central processing unit 1501, it performs various functions defined in the system of this application.

需要说明的是,本申请实施例所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(Erasable Programmable Read Only Memory,EPROM)、闪存、光纤、便携式紧凑磁盘只读存储器(Compact Disc Read-Only Memory,CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本申请中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本申请中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、有线等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such transmitted data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

附图中的流程图和框图,图示了按照本申请各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

应当注意,尽管在上文详细描述中提及了用于动作执行的设备的若干模块或者单元,但是这种划分并非强制性的。实际上,根据本申请的实施方式,上文描述的两个或更多模块或者单元的特征和功能可以在一个模块或者单元中具体化。反之,上文描述的一个模块或者单元的特征和功能可以进一步划分为由多个模块或者单元来具体化。It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.

通过以上的实施方式的描述,本领域的技术人员易于理解,这里描述的示例实施方式可以通过软件实现,也可以通过软件结合必要的硬件的方式来实现。因此,根据本申请实施方式的技术方案可以以软件产品的形式体现出来,该软件产品可以存储在一个非易失性存储介质(可以是CD-ROM,U盘,移动硬盘等)中或网络上,包括若干指令以使得一台计算设备(可以是个人计算机、服务器、触控终端、或者网络设备等)执行根据本申请实施方式的方法。Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.

本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.

应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求来限制。It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims (13)

1.一种数据处理方法,其特征在于,包括:1. A data processing method, characterized in that it includes: 响应于数据查询请求,在缓存中查找与所述数据查询请求相匹配的目标缓存数据;In response to a data query request, the target cached data that matches the data query request is retrieved from the cache; 获取所述目标缓存数据的超时时间,并确定所述超时时间是否已过期,所述超时时间小于所述目标缓存数据的失效时间;Obtain the timeout period of the target cached data and determine whether the timeout period has expired, wherein the timeout period is less than the expiration time of the target cached data; 若所述超时时间未过期,则向所述数据查询请求的请求方返回所述目标缓存数据;If the timeout period has not expired, the target cached data is returned to the requester of the data query request; 若所述超时时间已过期,则通过发起所述数据查询请求的当前线程发起获取线程锁的加锁请求;If the timeout period has expired, a lock acquisition request to acquire the thread lock is initiated by the current thread that initiated the data query request. 若所述当前线程加锁失败,则将所述当前线程配置为休眠状态;If the current thread fails to acquire the lock, then the current thread is configured to sleep. 若所述当前线程加锁成功,则令所述当前线程保持运行状态;If the current thread successfully acquires the lock, then the current thread remains running. 延长所述目标缓存数据的超时时间,以便其他数据查询请求能够命中并返回所述目标缓存数据;Extend the timeout period of the target cached data so that other data query requests can hit and return the target cached data; 在数据库中查找与所述数据查询请求相匹配的目标数据库数据;Search the database for target database data that matches the data query request; 根据所述目标数据库数据更新所述缓存中的目标缓存数据;Update the target cache data in the cache according to the target database data; 重置所述目标缓存数据的超时时间和失效时间;Reset the timeout and expiration time of the target cached data; 释放所述线程锁,并向所述数据查询请求的请求方返回更新后的目标缓存数据。Release the thread lock and return the updated target cached data to the requester of the data query request. 2.根据权利要求1所述的数据处理方法,其特征在于,所述在缓存中查找与所述数据查询请求相匹配的目标缓存数据,包括:2. The data processing method according to claim 1, characterized in that, the step of searching for target cached data matching the data query request in the cache includes: 获取所述数据查询请求中携带的查询关键字;Obtain the query keywords carried in the data query request; 在缓存中查找与所述查询关键字相匹配的目标关键字,并确定所述目标关键字的失效时间是否已过期;Search the cache for a target keyword that matches the query keyword, and determine whether the expiration time of the target keyword has expired; 若所述目标关键字的失效时间未过期,则将与所述目标关键字相关联的缓存数据确定为与所述数据查询请求相匹配的目标缓存数据。If the expiration time of the target keyword has not expired, the cached data associated with the target keyword will be determined as the target cached data that matches the data query request. 3.根据权利要求2所述的数据处理方法,其特征在于,所述在缓存中查找与所述数据查询请求相匹配的目标缓存数据,还包括:3. The data processing method according to claim 2, characterized in that, the step of searching for target cached data matching the data query request in the cache further includes: 若所述目标关键字的失效时间已过期,则在数据库中查找与所述目标关键字相关联的数据库数据;If the expiration time of the target keyword has expired, then search the database for database data associated with the target keyword; 根据查找得到的数据库数据更新与所述目标关键字相关联的缓存数据;Update the cached data associated with the target keyword based on the retrieved database data; 将更新后的缓存数据确定为与所述数据查询请求相匹配的目标缓存数据。The updated cached data is identified as the target cached data that matches the data query request. 4.根据权利要求1所述的数据处理方法,其特征在于,所述延长所述目标缓存数据的超时时间,包括:4. The data processing method according to claim 1, wherein extending the timeout period of the target cached data includes: 根据所述数据查询请求中携带的请求时间戳确定发起所述数据查询请求的请求时间;The request time when the data query request was initiated is determined based on the request timestamp carried in the data query request; 将所述目标缓存数据的超时时间延长至位于所述请求时间和所述目标缓存数据的失效时间之间的目标时间点。Extend the timeout period of the target cached data to a target time point between the request time and the expiration time of the target cached data. 5.根据权利要求4所述的数据处理方法,其特征在于,所述将所述目标缓存数据的超时时间延长至位于所述请求时间和所述目标缓存数据的失效时间之间的目标时间点,包括:5. The data processing method according to claim 4, characterized in that extending the timeout of the target cached data to a target time point located between the request time and the expiration time of the target cached data includes: 获取所述请求时间与所述目标缓存数据的超时时间之间的时间差;Obtain the time difference between the request time and the timeout of the target cached data; 根据所述时间差选取位于所述请求时间和所述目标缓存数据的失效时间之间的所述目标时间点;The target time point is selected based on the time difference, which is located between the request time and the expiration time of the target cached data. 将所述目标缓存数据的超时时间延长至所述目标时间点。Extend the timeout period of the target cached data to the target time point. 6.根据权利要求1所述的数据处理方法,其特征在于,所述在数据库中查找与所述数据查询请求相匹配的目标数据库数据,包括:6. The data processing method according to claim 1, characterized in that, the step of searching for target database data matching the data query request in the database includes: 获取所述数据查询请求中携带的查询关键字;Obtain the query keywords carried in the data query request; 在数据库中查找与所述查询关键字相匹配的目标关键字;Search the database for target keywords that match the query keywords; 将与所述目标关键字相关联的数据库数据确定为与所述数据查询请求相匹配的目标数据库数据。The database data associated with the target keyword is identified as the target database data that matches the data query request. 7.根据权利要求1所述的数据处理方法,其特征在于,在将所述当前线程配置为休眠状态之后,所述方法还包括:7. The data processing method according to claim 1, characterized in that, after configuring the current thread to a sleep state, the method further includes: 监测所述当前线程以确定是否满足所述当前线程的唤醒条件;Monitor the current thread to determine whether the wake-up condition for the current thread is met; 当满足所述当前线程的唤醒条件时,将所述当前线程配置为运行状态,以通过所述当前线程重新发起数据查询请求。When the wake-up condition of the current thread is met, the current thread is configured to run, so that the data query request can be re-initiated through the current thread. 8.根据权利要求7所述的数据处理方法,其特征在于,所述监测所述当前线程以确定是否满足所述当前线程的唤醒条件,包括:8. The data processing method according to claim 7, characterized in that, monitoring the current thread to determine whether the wake-up condition of the current thread is met includes: 监测所述当前线程的休眠时间;Monitor the sleep time of the current thread; 若所述休眠时间大于或者等于预设的时间阈值,则确定满足所述当前线程的唤醒条件;If the sleep time is greater than or equal to a preset time threshold, then the wake-up condition of the current thread is determined to be met. 若所述休眠时间小于所述时间阈值,则确定不满足所述当前线程的唤醒条件。If the sleep time is less than the time threshold, then it is determined that the wake-up condition of the current thread is not met. 9.根据权利要求7所述的数据处理方法,其特征在于,所述监测所述当前线程以确定是否满足所述当前线程的唤醒条件,包括:9. The data processing method according to claim 7, characterized in that, monitoring the current thread to determine whether the wake-up condition of the current thread is met includes: 监测所述当前线程请求获取的线程锁的当前状态;Monitor the current state of the thread lock that the current thread is requesting to acquire; 若所述线程锁处于释放状态,则确定满足所述当前线程的唤醒条件;If the thread lock is in a released state, then the wake-up condition of the current thread is determined to be met; 若所述线程锁处于锁定状态,则确定不满足所述当前线程的唤醒条件。If the thread lock is in a locked state, it is determined that the wake-up condition for the current thread is not met. 10.根据权利要求1所述的数据处理方法,其特征在于,所述线程锁为互斥锁。10. The data processing method according to claim 1, wherein the thread lock is a mutex lock. 11.一种数据处理系统,其特征在于,包括:11. A data processing system, characterized in that it comprises: 缓存查找模块,被配置为响应于数据查询请求,在缓存中查找与所述数据查询请求相匹配的目标缓存数据;The cache lookup module is configured to, in response to a data query request, search the cache for target cache data that matches the data query request. 时间获取模块,被配置为获取所述目标缓存数据的超时时间,并确定所述超时时间是否已过期,所述超时时间小于所述目标缓存数据的失效时间;The time acquisition module is configured to acquire the timeout time of the target cached data and determine whether the timeout time has expired, wherein the timeout time is less than the expiration time of the target cached data; 第一执行模块,被配置为若所述超时时间未过期,则向所述数据查询请求的请求方返回所述目标缓存数据;The first execution module is configured to return the target cached data to the requester of the data query request if the timeout period has not expired. 第二执行模块,被配置为若所述超时时间已过期,则延长所述目标缓存数据的超时时间,以便其他数据查询请求能够命中并返回所述目标缓存数据,并在数据库中查找与所述数据查询请求相匹配的目标数据库数据;The second execution module is configured to extend the timeout period of the target cached data if the timeout period has expired, so that other data query requests can hit and return the target cached data, and search for target database data that matches the data query request in the database. 所述第二执行模块还包括:The second execution module also includes: 加锁单元,被配置为通过发起所述数据查询请求的当前线程发起获取线程锁的加锁请求;The locking unit is configured to initiate a locking request to acquire the thread lock through the current thread that initiated the data query request; 休眠单元,被配置为若所述当前线程加锁失败,则将所述当前线程配置为休眠状态;The sleep unit is configured to put the current thread into a sleep state if the current thread fails to acquire the lock. 运行单元,被配置为若所述当前线程加锁成功,则令所述当前线程保持运行状态;The execution unit is configured to keep the current thread running if the current thread successfully acquires the lock. 缓存更新单元,被配置为根据所述目标数据库数据更新所述缓存中的目标缓存数据;The cache update unit is configured to update the target cache data in the cache according to the target database data; 时间重置单元,被配置为重置所述目标缓存数据的超时时间和失效时间;The time reset unit is configured to reset the timeout and expiration time of the target cached data; 数据返回单元,被配置为释放所述线程锁,并向所述数据查询请求的请求方返回更新后的目标缓存数据。The data return unit is configured to release the thread lock and return the updated target cached data to the requester of the data query request. 12.一种计算机可读介质,其上存储有计算机程序,该计算机程序被处理器执行时实现权利要求1至10中任意一项所述的数据处理方法。12. A computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the data processing method according to any one of claims 1 to 10. 13.一种电子设备,其特征在于,包括:13. An electronic device, characterized in that it comprises: 处理器;以及Processor; and 存储器,用于存储所述处理器的可执行指令;Memory for storing the executable instructions of the processor; 其中,所述处理器配置为经由执行所述可执行指令来执行权利要求1至10中任意一项所述的数据处理方法。The processor is configured to execute the data processing method of any one of claims 1 to 10 by executing the executable instructions.
HK42021036229.9A 2021-08-05 Method and system for processing data, computer readable medium and electronic apparatus HK40046413B (en)

Publications (2)

Publication Number Publication Date
HK40046413A HK40046413A (en) 2021-11-05
HK40046413B true HK40046413B (en) 2024-04-05

Family

ID=

Similar Documents

Publication Publication Date Title
CN113010552B (en) Data processing method, system, computer readable medium and electronic device
CN110447017B (en) Rule-based modification in a data storage equipment monitor
US11841861B1 (en) Constrained query execution
JP6181290B2 (en) Transaction ordering
EP2653986B1 (en) Client-side caching of a database transaction token.
US11709841B2 (en) Methods for updating reference count and shared objects in a concurrent system
US10097659B1 (en) High performance geographically distributed data storage, retrieval and update
US9910881B1 (en) Maintaining versions of control plane data for a network-based service control plane
US10970311B2 (en) Scalable snapshot isolation on non-transactional NoSQL
US11570182B1 (en) Compute-less authorization
CN103514298A (en) Method for achieving file lock and metadata server
CN117321581A (en) Techniques for deterministic distributed caching to accelerate SQL queries
US12189632B2 (en) Methods for updating reference count and shared objects in a concurrent system
CN115422188A (en) Table structure online changing method and device, electronic equipment and storage medium
US10055448B2 (en) Techniques to reduce contention windows
US11275601B2 (en) System and method for auto recovery of deleted virtual machines identified through comparison of virtual machine management application snapshots and having corresponding backups at a storage device
US12008041B2 (en) Shared cache for multiple index services in nonrelational databases
US20250298784A1 (en) Capturing unique constraint violations when building a unique secondary index
HK40046413B (en) Method and system for processing data, computer readable medium and electronic apparatus
US11947568B1 (en) Working set ratio estimations of data items in a sliding time window for dynamically allocating computing resources for the data items
WO2024198872A1 (en) Data management system, and data updating method and apparatus
US12007954B1 (en) Selective forwarding for multi-statement database transactions
CN119301581A (en) Diskless active data protection as cache
US11580082B2 (en) Object storage system with control entity quota usage mapping
HK40046413A (en) Method and system for processing data, computer readable medium and electronic apparatus