A data request processing method, device, server and storage medium

By setting a forced expiration flag and a logical expiration time for each request identifier, the performance degradation caused by cache breakdown is solved, and the database pressure and performance are reduced while meeting business needs.

CN114036195BActive Publication Date: 2025-02-18SHENZHEN LEXIN SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111330999.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-11
Publication Date
2025-02-18
Estimated Expiration
2041-11-11

AI Technical Summary

Technical Problem

The cache is broken down and the performance is degraded, the database pressure increases, and the time-consuming process increases.

Method used

By setting a forced expiration flag and a logical expiration time for each request identifier, if the target forced expiration flag is the first identifier, the response data is obtained from the cache and updated asynchronously at the logical expiration time to avoid the cache being broken down.

Benefits of technology

While meeting business needs, ensure that there is always data in the cache, reduce database pressure and improve performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114036195B_ABST
    Figure CN114036195B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a data request processing method, device, server and storage medium, the method comprising: receiving a target data request sent by a client, the target data request including a target request identifier; detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure; if there is target cache data, obtaining a target forced expiration identifier and a target logical expiration time corresponding to the target request identifier from the target cache data; if the target forced expiration identifier is a first identifier, obtaining target response data corresponding to the target request identifier from the target cache data, and asynchronously updating the target cache data when the current request time is greater than or equal to the target logical expiration time. The technical solution of the embodiment of the present invention can solve the problem of performance degradation caused by cache breakdown.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to computer technology, and in particular to a data request processing method, device, server and storage medium. Background Art

[0002] With the rapid development of computer technology, there are often high concurrent requests. In order to improve user access speed, the data with high access popularity in the database is usually stored in the cache, so that the response data can be directly obtained from the cache later, which improves the access speed.

[0003] Currently, when data in the database is modified, the old data in the cache is directly cleared to reclaim the memory in time and improve the efficient use of the cache. However, after the old data in the cache is cleared, the cache will be broken, causing a large number of requests to directly query the database, resulting in increased database pressure, increased time consumption, and decreased performance. Summary of the invention

[0004] The embodiments of the present invention provide a data request processing method, device, server and storage medium to solve the problem of performance degradation caused by cache breakdown.

[0005] In a first aspect, an embodiment of the present invention provides a data request processing method, including:

[0006] Receiving a target data request sent by a client, wherein the target data request includes a target request identifier;

[0007] Detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure;

[0008] If the target cache data exists, obtaining the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier from the target cache data;

[0009] If the target forced expiration identifier is the first identifier, the target response data corresponding to the target request identifier is obtained from the target cache data, and the target cache data is asynchronously updated when the current request time is greater than or equal to the target logical expiration time.

[0010] In a second aspect, an embodiment of the present invention further provides a data request processing device, including:

[0011] A target data request receiving module, used for receiving a target data request sent by a client, wherein the target data request includes a target request identifier;

[0012] A target cache data detection module, used to detect whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure;

[0013] An expiration information acquisition module, configured to acquire a target forced expiration identifier and a target logical expiration time corresponding to the target request identifier from the target cache data if the target cache data exists;

[0014] The target response data acquisition module is used to obtain the target response data corresponding to the target request identifier from the target cache data if the target forced expiration identifier is the first identifier, and asynchronously update the target cache data when the current request time is greater than or equal to the target logical expiration time.

[0015] In a third aspect, an embodiment of the present invention further provides a server, the server comprising:

[0016] one or more processors;

[0017] A memory for storing one or more programs;

[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the data request processing method provided by the embodiment of the present invention.

[0019] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data request processing method provided in the embodiment of the present invention.

[0020] The embodiment of the present invention sets the forced expiration flag and logical expiration time corresponding to each request identifier in advance according to whether the response data of each request needs to be forced to expire and the maximum delay time allowed for delayed update of the response data. If the target forced expiration flag corresponding to the target request identifier is the first identifier, that is, forced expiration is not required, the target response data corresponding to the target request identifier is directly obtained from the target cache data, and the target cache data is asynchronously updated when the current request time is greater than or equal to the target logical expiration time. Therefore, by performing asynchronous updates based on the forced expiration flag and the logical expiration time, it is possible to ensure that there is always data in the cache while meeting business needs, avoid cache breakdown, reduce database pressure, and improve performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a flow chart of a data request processing method provided by Embodiment 1 of the present invention;

[0022] Figure 2 is a flow chart of a data request processing method provided by Embodiment 2 of the present invention;

[0023] Figure 3 is a structural diagram of a data request processing device provided by Embodiment 3 of the present invention;

[0024] Figure 4 It is a structural diagram of a server provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION

[0025] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0026] Embodiment 1

[0027] Figure 1 This is a flow chart of a data request processing method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case of responding to data requests in high-concurrency scenarios. The method can be executed by a data request processing device, which can be implemented by software and / or hardware and integrated in a server. Figure 1 As shown, the method specifically comprises the following steps:

[0028] S110: Receive a target data request sent by a client, where the target data request includes a target request identifier.

[0029] The target data request may refer to any data request among various pending data requests currently sent by a large number of clients. The target request identifier may be used to uniquely identify the target data request so as to distinguish different data requests.

[0030] Specifically, the server may receive a target data request to be processed currently sent by the client.

[0031] S120: Detect whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure.

[0032] Among them, the preset cache structure can be a data structure preset for storing cached data. Exemplarily, the preset cache structure can be a key-value pair structure. The key information in each key-value pair information is the request identifier, and the corresponding value information is the cached data corresponding to the request identifier. The cached data may include: a forced expiration identifier, a logical expiration time, and response data. The forced expiration identifier can be used to characterize whether the cached response data needs to be forced to expire. For example, the forced expiration identifier may include a first identifier and a second identifier. The first identifier may refer to an identifier that does not need to be forced to expire. The second identifier may refer to an identifier that needs to be forced to expire, that is, the response data requested must be real-time data. The logical expiration time can be set based on the maximum delay duration allowed for delayed updates of the response data.

[0033] Specifically, when the cache is initialized, each response data with high access popularity in the database and the corresponding mandatory expiration identifier and logical expiration time can be directly stored in a cache with a preset cache structure; the response data can also be cached based on the request to improve the cache utilization efficiency. For example, when a data request corresponding to a request identifier is received for the first time, the response data corresponding to the request identifier is obtained from the database, and the mandatory expiration identifier and logical expiration time corresponding to the response data are configured based on business needs and then cached, so that caching during data access can ensure efficient use of the cache. When a target data request is received, it can be detected whether the target cache data corresponding to the target request identifier exists in the cache, so as to determine whether the target response data can be directly obtained from the cache.

[0034] Exemplarily, S120 may include: detecting whether there is target key information corresponding to the target request identifier in the cache; if so, using the target value information corresponding to the target key information as the target cache data. Specifically, the target request identifier may be matched with each key information in the cache. If the match is successful, it indicates that the target cache data exists, and the target value information corresponding to the successfully matched target key information is used as the target cache data; if the match fails, it indicates that the target data request is the first request, and the target cache data has not been cached in the current cache, that is, it is determined that the target cache data does not exist.

[0035] S130: If the target cache data exists, obtain the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier from the target cache data.

[0036] The target forced expiration flag can be used to indicate whether the cached target response data needs to be forced to expire. The target logical expiration time can be set based on the maximum delay time allowed for delayed update of the target response data.

[0037] Specifically, when the target cache data corresponding to the target request identifier exists in the cache, the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier can be directly obtained from the target cache data.

[0038] S140: If the target forced expiration identifier is the first identifier, obtain the target response data corresponding to the target request identifier from the target cache data, and asynchronously update the target cache data when the current request time is greater than or equal to the target logical expiration time.

[0039] The current request time may be the time when the target data request is currently received in real time.

[0040] Specifically, when the target forced expiration flag is the first flag, it indicates that there is no need to force expiration of the cached target response data. At this time, the target response data corresponding to the target request flag can be directly obtained from the cached target cache data and returned to the client to complete the data request response operation. This embodiment can simultaneously detect whether the current request time is greater than or equal to the target logical expiration time. If so, it indicates that the delay time that allows delayed updates has been reached. At this time, the operation of asynchronously updating the target cache data can be triggered, so that the cache data can be updated in a timely manner while ensuring response efficiency. This embodiment can ensure that there is always data in the cache while meeting business needs by performing asynchronous updates based on the logical expiration time, avoiding cache breakdown, reducing database pressure, and improving performance.

[0041] It should be noted that this embodiment only improves the data request processing method on the server side, and no improvement is required at the business level, so that the business is not aware of it and the switching cost is reduced.

[0042] Exemplarily, "asynchronously updating the target cache data" in S140 may include: obtaining the latest response data corresponding to the target request identifier from the database through an asynchronous thread, and updating the target response data and target logical expiration time in the target cache data based on the latest response data.

[0043] The latest response data may refer to the response data corresponding to the target request identifier currently stored in the database. The latest response data may be the original response data that has not been modified yet, or may be the new response data after modification.

[0044] Specifically, an asynchronous thread can be started, through which the latest response data corresponding to the target request identifier is obtained from the database, and the target response data and target logical expiration time in the cached target cache data are updated and overwritten based on the latest response data to ensure that the cached target response data is the latest response data, so that other data requests can obtain the latest response data from the cache and recalculate the target logical expiration time corresponding to the latest response data.

[0045] Exemplarily, updating the target response data and target logical expiration time in the target cache data based on the latest response data may include: updating the target response data in the target cache data based on the latest response data; determining the latest logical expiration time based on the current update time and the logical validity period corresponding to the target request identifier, and updating the target logical expiration time in the target cache data based on the latest logical expiration time.

[0046] The logic validity period may refer to the time duration of delayed update of cached response data. The logic validity period may be set based on the maximum delay period allowed for delayed update of target response data. For example, the logic validity period may be less than or equal to the maximum delay period. The current update time may refer to the time for updating cached target response data.

[0047] Specifically, the target response data in the target cache data can be updated to the latest response data obtained from the database, and the current update time is added to the logical validity period. The obtained time is determined as the latest logical expiration time, and the target logical expiration time in the target cache data is updated to the latest logical expiration time. Therefore, every time the target response data in the cache is asynchronously updated, the corresponding target logical expiration time also needs to be updated once.

[0048] It should be noted that this embodiment triggers the asynchronous update operation of the target cache data only when the target forced expiration flag is the first flag after receiving the target data request. Compared with the timed triggering of the asynchronous update operation, it can avoid the waste of resources caused by triggering the asynchronous update operation without a data request.

[0049] The technical solution of this embodiment sets the forced expiration identifier and logical expiration time corresponding to each request identifier in advance according to whether the response data of each request needs to be forced to expire and the maximum delay time allowed for delayed update of the response data. If the target forced expiration identifier corresponding to the target request identifier is the first identifier, that is, no forced expiration is required, the target response data corresponding to the target request identifier is directly obtained from the target cache data, and the target cache data is asynchronously updated when the current request time is greater than or equal to the target logical expiration time. Therefore, by performing asynchronous updates based on the forced expiration identifier and the logical expiration time, it is possible to ensure that there is always data in the cache while meeting business needs, avoiding cache breakdown, reducing database pressure, and improving performance.

[0050] On the basis of the above technical solution, after S140, it can also include: determining the latest actual expiration time based on the current update time and the actual valid duration corresponding to the target request identifier, and updating the target actual expiration time corresponding to the target request identifier based on the latest actual expiration time; wherein the target actual expiration time is used to characterize the time for deleting the target request identifier and the target cache data; the target actual expiration time is greater than the target logical expiration time.

[0051] The actual effective duration may refer to the effective duration corresponding to the cached key-value pair information. In this embodiment, the actual effective duration is greater than the logical effective duration. The current update time may refer to the time for updating the cached target response data.

[0052] Specifically, the current update time can be added to the actual effective time, and the obtained time can be determined as the latest actual expiration time, and the target actual expiration time corresponding to the target request identifier can be updated to the latest actual expiration time, so that each time the target response data in the cache is updated, the corresponding target actual expiration time is also updated. Since the target logical expiration time is less than the target actual expiration time, the target actual expiration time will be updated once before the target actual expiration time is reached, so the target actual expiration time will never be reached, so that the entire key-value pair information will never expire, that is, the target request identifier and the target cache data will not be deleted, so that there is always data in the cache, further avoiding the situation where the cache is broken down.

[0053] Embodiment 2

[0054] Figure 2 A flowchart of a data request processing method provided for Embodiment 2 of the present invention. Based on the above embodiments, this embodiment describes in detail the processing method when the target cache data corresponding to the target request identifier does not exist in the cache, and also describes in detail the processing method when the target forced expiration identifier is the second identifier, wherein the explanations of the terms that are the same or corresponding to the above embodiments are not repeated here.

[0055] See also Figure 2 The data request processing method provided in this embodiment specifically includes the following steps:

[0056] S210: Receive a target data request sent by a client, where the target data request includes a target request identifier.

[0057] S220, detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure, if so, executing step S230, if not, executing step S280.

[0058] S230: Obtain a target forced expiration identifier and a target logical expiration time corresponding to the target request identifier from the target cache data.

[0059] S240, detecting whether the target forced expiration mark is the first mark or the second mark, if it is the first mark, executing step S250; if it is the second mark, executing step S260.

[0060] S250: Obtain target response data corresponding to the target request identifier from the target cache data, and asynchronously update the target cache data when the current request time is greater than or equal to the target logical expiration time.

[0061] S260: Perform a distributed spin lock on each current data request corresponding to the target request identifier in the server cluster to determine the only first data request in an unlocked state.

[0062] Specifically, in a high-concurrency scenario, there are multiple current data requests whose request identifiers are all target request identifiers, and these current data requests can be responded to and processed using a distributed cluster. When the target forced expiration identifier corresponding to the target request identifier is the second identifier, it indicates that the target response data needs to be forced to expire. Since the cached response data is old response data, the response data cannot be directly obtained from the cache. At this time, a distributed spin lock can be performed on each current data request to ensure that only one data request (i.e., the first data request) can perform a database query operation in the server cluster at the same time to reduce database pressure.

[0063] S270. Based on the first data request, obtain the latest response data corresponding to the target request identifier from the database, and update the target response data in the target cache data based on the latest response data, and after the update is completed, update the target forced expiration identifier from the second identifier to the first identifier.

[0064] Specifically, the server processing the first data request can obtain the latest response data corresponding to the target request identifier from the database and return it to the corresponding client, and update the target response data in the cached target cache data to the latest response data to ensure that the cached response data is the latest response data. After the response data update is completed, the target forced expiration identifier can be updated from the second identifier to the first identifier to ensure that other data requests such as the target data request can directly obtain the latest response data from the cache.

[0065] It should be noted that for response data that does not allow delayed update, that is, real-time data, when the response data stored in the database is modified, the forced expiration flag corresponding to the cached response data needs to be updated from the first flag to the second flag for forced expiration to avoid obtaining old response data from the cache.

[0066] S280: Perform a distributed spin lock on each current data request corresponding to the target request identifier in the server cluster to determine the only second data request in an unlocked state.

[0067] Specifically, when the target cache data corresponding to the target request identifier does not exist in the cache, it indicates that this request is the first request. At this time, a distributed spin lock can be performed on the current data requests whose multiple request identifiers are all target request identifiers to ensure that only one data request (i.e., the second data request) can perform database query operations in the server cluster at the same time, so as to reduce database pressure.

[0068] S290. Based on the second data request, obtain the target response data corresponding to the target request identifier from the database, determine the target cache data corresponding to the target request identifier, and store the target request identifier and the target cache data in the cache.

[0069] Specifically, the server processing the second data request can obtain the latest response data corresponding to the target request identifier from the database and return it to the corresponding client, and configure the target forced expiration identifier and target logical expiration time corresponding to the target request identifier based on whether the response data needs to be forced to expire and the maximum delay duration allowed for delayed update when forced expiration is not required, thereby obtaining the target cache data corresponding to the target request identifier that includes the target forced expiration identifier, target logical expiration time and target response data, and can store the target request identifier and target cache data in the cache in the form of key-value pairs, so that for other data requests such as target data requests, the target response data can be obtained from the cache by returning to execute the operation of step S230.

[0070] This embodiment can ensure the cache hit rate when the server uses cache invalidation, improve server stability, and reduce concurrent lock competition problems or database pressure problems caused by cache breakdown in high concurrency scenarios.

[0071] The technical solution of this embodiment can further avoid cache breakdown, reduce database pressure and improve performance by performing distributed spin locks on each current data request corresponding to the target request identifier in the server cluster when the target forced expiration identifier is the second identifier or the target cache data corresponding to the target request identifier does not exist in the cache.

[0072] The following is an embodiment of a data request processing device provided in an embodiment of the present invention. The device and the data request processing methods of the above-mentioned embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the data request processing device, please refer to the embodiment of the above-mentioned data request processing method.

[0073] Embodiment 3

[0074] Figure 3 This is a schematic diagram of the structure of a data request processing device provided in Embodiment 3 of the present invention. This embodiment is applicable to the case of responding to data requests in high-concurrency scenarios. Figure 3 As shown, the device specifically includes: a target data request receiving module 310, a target cache data detecting module 320, an expiration information acquiring module 330 and a target response data acquiring module 340.

[0075] Among them, the target data request receiving module 310 is used to receive the target data request sent by the client, and the target data request includes a target request identifier; the target cache data detection module 320 is used to detect whether the target cache data corresponding to the target request identifier exists in the cache with a preset cache structure; the expiration information acquisition module 330 is used to obtain the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier from the target cache data if the target cache data exists; the target response data acquisition module 340 is used to obtain the target response data corresponding to the target request identifier from the target cache data if the target forced expiration identifier is the first identifier, and asynchronously update the target cache data when the current request time is greater than or equal to the target logical expiration time.

[0076] Optionally, the target response data acquisition module 340 includes:

[0077] The asynchronous update unit is used to obtain the latest response data corresponding to the target request identifier from the database through an asynchronous thread, and update the target response data and the target logical expiration time in the target cache data based on the latest response data.

[0078] Optionally, the asynchronous update unit is specifically used to: update the target response data in the target cache data based on the latest response data; determine the latest logical expiration time based on the current update time and the logical validity period corresponding to the target request identifier, and update the target logical expiration time in the target cache data based on the latest logical expiration time.

[0079] Optionally, the device further comprises:

[0080] The target actual expiration time update module is used to: after asynchronously updating the target cache data, determine the latest actual expiration time based on the current update time and the actual validity period corresponding to the target request identifier, and update the target actual expiration time corresponding to the target request identifier based on the latest actual expiration time;

[0081] The target actual expiration time is used to represent the time for deleting the target request identifier and the target cache data; the target actual expiration time is greater than the target logical expiration time.

[0082] Optionally, the preset cache structure is a key-value pair structure; the key information in each key-value pair is a request identifier, and the value information is cache data, and the cache data includes: a mandatory expiration identifier, a logical expiration time, and response data;

[0083] The target cache data detection module 320 is specifically used to: detect whether there is target key information corresponding to the target request identifier in the cache; if so, use the target value information corresponding to the target key information as the target cache data.

[0084] Optionally, the device further comprises:

[0085] A first data request determination module, configured to perform a distributed spin lock on each current data request corresponding to the target request identifier in the server cluster to determine the only first data request in an unlocked state if the target forced expiration identifier is the second identifier;

[0086] A data update module is used to obtain the latest response data corresponding to the target request identifier from the database based on the first data request, and update the target response data in the target cache data based on the latest response data, and after the update is completed, update the target forced expiration identifier from the second identifier to the first identifier.

[0087] Optionally, the device further comprises:

[0088] A second data request determination module is used to perform a distributed spin lock on each current data request corresponding to the target request identifier in the server cluster if the target cache data corresponding to the target request identifier does not exist in the cache, and determine the only second data request in an unlocked state;

[0089] The target cache data storage module is used to obtain the target response data corresponding to the target request identifier from the database based on the second data request, determine the target cache data corresponding to the target request identifier, and store the target request identifier and the target cache data in the cache.

[0090] The data request processing device provided in the embodiment of the present invention can execute the data request processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the data request processing method.

[0091] It is worth noting that in the embodiment of the above-mentioned data request processing device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0092] Embodiment 4

[0093] Figure 4 A schematic diagram of the structure of a server provided in Embodiment 4 of the present invention. Figure 4 A block diagram of an exemplary server 12 suitable for use in implementing embodiments of the present invention is shown. Figure 4 The server 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0094] like Figure 4 As shown, the server 12 is in the form of a general purpose computing device. The components of the server 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).

[0095] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0096] The server 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the server 12, including volatile and non-volatile media, removable and non-removable media.

[0097] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The server 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 4 not shown, usually called a "hard drive"). Although Figure 4 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0098] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.

[0099] The server 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), may communicate with one or more devices that enable a user to interact with the server 12, and / or may communicate with any device that enables the server 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed via an input / output (I / O) interface 22. In addition, the server 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with other modules of the server 12 via a bus 18. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the server 12, including, but not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0100] The processing unit 16 executes various functional applications and data processing by running the program stored in the system memory 28, for example, implementing a data request processing method provided by the embodiment of the present invention, the method comprising:

[0101] receiving a target data request sent by a client, the target data request including a target request identifier;

[0102] Detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure;

[0103] If the target cache data exists, the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier are obtained from the target cache data;

[0104] If the target forced expiration identifier is the first identifier, the target response data corresponding to the target request identifier is obtained from the target cache data, and the target cache data is asynchronously updated when the current request time is greater than or equal to the target logical expiration time.

[0105] Of course, those skilled in the art can understand that the processor can also implement the technical solution for data request processing provided by any embodiment of the present invention.

[0106] Embodiment 5

[0107] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the steps of the data request processing method provided in any embodiment of the present invention are implemented. The method includes:

[0108] receiving a target data request sent by a client, the target data request including a target request identifier;

[0109] Detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure;

[0110] If the target cache data exists, the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier are obtained from the target cache data;

[0111] If the target forced expiration identifier is the first identifier, the target response data corresponding to the target request identifier is obtained from the target cache data, and the target cache data is asynchronously updated when the current request time is greater than or equal to the target logical expiration time.

[0112] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0113] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0114] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0115] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0116] It should be understood by those skilled in the art that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0117] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A data request processing method, characterized in that: include: Receiving a target data request sent by a client, wherein the target data request includes a target request identifier; Detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure; If the target cache data exists, obtaining the target forced expiration identifier and the target logical expiration time corresponding to the target request identifier from the target cache data; If the target forced expiration identifier is the first identifier, the target response data corresponding to the target request identifier is obtained from the target cache data, and when the current request time is greater than or equal to the target logical expiration time, the target cache data is asynchronously updated; If the target forced expiration identifier is the second identifier, a distributed spin lock is performed on each current data request corresponding to the target request identifier in the server cluster to determine the only first data request in an unlocked state; Based on the first data request, the latest response data corresponding to the target request identifier is obtained from the database, and the target response data in the target cache data is updated based on the latest response data, and after the update is completed, the target forced expiration identifier is updated from the second identifier to the first identifier.

2. The method according to claim 1, characterized in that The asynchronously updating the target cache data includes: The latest response data corresponding to the target request identifier is obtained from the database through an asynchronous thread, and the target response data and the target logical expiration time in the target cache data are updated based on the latest response data.

3. The method according to claim 2, characterized in that The updating of the target response data and the target logical expiration time in the target cache data based on the latest response data includes: Based on the latest response data, updating the target response data in the target cache data; Based on the current update time and the logic validity period corresponding to the target request identifier, the latest logic expiration time is determined, and based on the latest logic expiration time, the target logic expiration time in the target cache data is updated.

4. The method according to claim 1, characterized in that: After asynchronously updating the target cache data, the method further includes: Determine the latest actual expiration time based on the current update time and the actual validity period corresponding to the target request identifier, and update the target actual expiration time corresponding to the target request identifier based on the latest actual expiration time; The target actual expiration time is used to represent the time for deleting the target request identifier and the target cache data; the target actual expiration time is greater than the target logical expiration time.

5. The method according to claim 1, characterized in that The preset cache structure is a key-value pair structure; the key information in each key-value pair is a request identifier, and the value information is cache data, and the cache data includes: a mandatory expiration identifier, a logical expiration time, and a response data; The detecting whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure includes: Detect whether there is target key information corresponding to the target request identifier in the cache; If it exists, the target value information corresponding to the target key information is used as the target cache data.

6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: If the target cache data corresponding to the target request identifier does not exist in the cache, a distributed spin lock is performed on each current data request corresponding to the target request identifier in the server cluster to determine the only second data request in an unlocked state; Based on the second data request, the target response data corresponding to the target request identifier is obtained from the database, the target cache data corresponding to the target request identifier is determined, and the target request identifier and the target cache data are stored in the cache.

7. A data request processing device, characterized in that: include: A target data request receiving module, used for receiving a target data request sent by a client, wherein the target data request includes a target request identifier; A target cache data detection module, used to detect whether there is target cache data corresponding to the target request identifier in a cache having a preset cache structure; An expiration information acquisition module, configured to acquire a target forced expiration identifier and a target logical expiration time corresponding to the target request identifier from the target cache data if the target cache data exists; A target response data acquisition module, configured to acquire the target response data corresponding to the target request identifier from the target cache data if the target forced expiration identifier is the first identifier, and to asynchronously update the target cache data when the current request time is greater than or equal to the target logical expiration time; The device also includes: A first data request determination module is configured to perform a distributed spin lock on each current data request corresponding to the target request identifier in the server cluster to determine the only first data request in an unlocked state if the target forced expiration identifier is the second identifier; A data update module is used to obtain the latest response data corresponding to the target request identifier from the database based on the first data request, and to update the target response data in the target cache data based on the latest response data, and after the update is completed, to update the target forced expiration identifier from the second identifier to the first identifier.

8. A server, characterized in that: The server comprises: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the data request processing method as described in any one of claims 1-6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data request processing method as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Data obtaining method and apparatus

    CN107943594A

  • Cache control method and device, terminal and storage medium

    CN109491928A