Hotspot data caching method and apparatus, storage medium, and computer device
By dynamically adjusting the active slots in the local and remote caches when receiving client requests, the risk of Redis-like caches crashing under high concurrency is mitigated, achieving improved cache consistency and access speed.
Patent Information
- Application Number
- CN202211716902.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Existing technologies that simply use remote caching methods like Redis are insufficient to support high-concurrency access to hot data, increasing the risk of system crashes due to excessive pressure from hot data access.
When a client's activity access request is received, the number of activity slots in the local cache and the remote cache is checked. If the local cache is empty, the activity slots are transferred from the remote cache to the local cache. The number of activity slots is then processed according to the request type to maintain cache consistency and reduce the pressure on the remote cache.
By dynamically transferring data between local and remote caches, the consistency of active slots is maintained, reducing the pressure on remote caches, lowering the risk of system crashes, and improving access response speed.
Smart Images

Figure CN116126912B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and particularly relates to a hot data caching method and device, a storage medium and a computer device. BACKGROUND
[0002] In the design of high-performance service architecture, caching is an indispensable link. In actual projects, some hot data is usually stored in Redis or Memcached cache middleware. Only when the cache access is not hit, the database is queried, which can not only improve the access speed, but also reduce the pressure on the database.
[0003] In the scenario of e-commerce promotion activities, the number of activities is a kind of hot data. Due to the rapid development of online e-commerce and the gradual expansion of the network popularization population, the pure use of Redis type remote cache has been difficult to support such high concurrency access, increasing the risk of system collapse due to excessive access pressure of hot data. SUMMARY
[0004] The present application aims to at least solve one of the above technical defects, especially the technical defect that the pure use of Redis type remote cache in the prior art has been difficult to support high concurrency access, increasing the risk of system collapse due to excessive access pressure of hot data.
[0005] In a first aspect, the present application provides a hot data caching method, which is applied to any node of a server, and includes the following steps:
[0006] When receiving an activity access request initiated by a client, a target activity ID, a request type and a target node contained in the activity access request are acquired;
[0007] According to the target activity ID, a target activity corresponding to the target activity ID is determined;
[0008] If a local cache service corresponding to the target activity in the target node is started, it is judged whether a first target number recorded in the local cache is zero; wherein the first target number is the number of the number of activities corresponding to the target activity recorded in the local cache;
[0009] If the first target number is zero, it is judged whether a second target number recorded in the remote cache is zero; wherein the second target number is the number of the number of activities corresponding to the target activity recorded in the remote cache;
[0010] If the second target number is not zero, a third target number is calculated;
[0011] If the second target number is greater than the third target number, the first target number recorded in the local cache is updated to the third target number, and the second target number recorded in the remote cache is updated to the difference between the second target number and the third target number.
[0012] According to the request type, a strategy corresponding to the request type is selected to process the number of the activity quota corresponding to the target activity recorded in the local cache.
[0013] In one of the embodiments, the method further comprises:
[0014] If the second target number is not greater than the third target number, the first target number recorded in the local cache is updated to the second target number, and the second target number recorded in the remote cache is updated to zero.
[0015] According to the request type, a strategy corresponding to the request type is selected to process the number of the activity quota corresponding to the target activity recorded in the local cache.
[0016] In one of the embodiments, the method further comprises:
[0017] If the first target number is not zero, according to the request type, a strategy corresponding to the request type is selected to process the number of the activity quota corresponding to the target activity recorded in the local cache.
[0018] In one of the embodiments, the method further comprises:
[0019] If the second target number is zero, the local cache service is closed, and a notification of closing the local cache service is sent to other nodes in the service end;
[0020] The target node is set with a no-quota identifier; wherein the no-quota identifier is used to represent that there is no activity quota corresponding to the target activity in the remote cache of the corresponding node.
[0021] In one of the embodiments, the step of calculating the third target number comprises:
[0022] The number of nodes of the service end is obtained;
[0023] According to the target activity ID, the number of activity quotas is obtained; wherein the number of activity quotas is the number of activity quotas corresponding to the target activity;
[0024] The number of activity quotas is divided by the number of nodes, and the quotient of the number of activity quotas and the number of nodes is rounded down to obtain a first value;
[0025] If the first value is not less than a preset second value, the second value is determined as the third target quantity.
[0026] If the first value is less than the second value, the first value is determined as the third target quantity.
[0027] In one of the embodiments, the request type includes a first request type and a second request type.
[0028] When the request type is the first request type, a strategy corresponding to the request type is selected to process the quantity of the activity quota corresponding to the target activity recorded in the local cache, including:
[0029] The quantity of the activity quota corresponding to the target activity recorded in the local cache is decremented by one.
[0030] In one of the embodiments, when the request type is the second request type, a strategy corresponding to the request type is selected to process the quantity of the activity quota corresponding to the target activity recorded in the local cache, including:
[0031] The quantity of the activity quota corresponding to the target activity recorded in the local cache is returned to the client.
[0032] In one of the embodiments, the method further includes:
[0033] When the local cache service of any node of the server is closed, the quantity of the activity quota corresponding to the target activity recorded in the remote cache of the node is updated to the sum of the quantity of the activity quota corresponding to the target activity recorded in the local cache and the quantity of the activity quota corresponding to the target activity recorded in the current remote cache, and the quantity of the activity quota corresponding to the target activity recorded in the local cache of the node is updated to zero.
[0034] In a second aspect, the application provides a hotspot data cache device, which is applied to any node of a server and includes:
[0035] An acquisition module, configured to acquire a target activity ID, a request type and a target node included in an activity access request initiated by a client when the activity access request is received.
[0036] A determination module, configured to determine a target activity corresponding to the target activity ID according to the target activity ID.
[0037] The first judging module is configured to judge whether a first target number recorded in the local cache is zero if the local cache service corresponding to the target activity in the target node is started, wherein the first target number is a number of activity quotas corresponding to the target activity recorded in the local cache.
[0038] The second judging module is configured to judge whether a second target number recorded in the remote cache is zero if the first target number is zero, wherein the second target number is a number of activity quotas corresponding to the target activity recorded in the remote cache.
[0039] The calculating module is configured to calculate a third target number if the second target number is not zero.
[0040] The updating module is configured to update the first target number recorded in the local cache to the third target number and update the second target number recorded in the remote cache to a difference between the second target number and the third target number if the second target number is greater than the third target number.
[0041] The request processing module is configured to select a strategy corresponding to the request type to process a number of activity quotas corresponding to the target activity recorded in the local cache according to the request type.
[0042] In a third aspect, a storage medium is provided, and the storage medium stores computer readable instructions. When the computer readable instructions are executed by one or more processors, the one or more processors perform the steps of the hot data caching method according to any one of the above embodiments.
[0043] In a fourth aspect, a computer device is provided, and the computer device includes one or more processors and a memory.
[0044] The memory stores computer readable instructions. When the computer readable instructions are executed by the one or more processors, the one or more processors perform the steps of the hot data caching method according to any one of the above embodiments.
[0045] From the above technical solutions, it can be seen that the embodiments of the present application have the following advantages:
[0046] The hotspot data caching method, device, storage medium and computer device provided by the application, when the server receives an activity access request initiated by the client, the target activity ID, the request type and the target node contained in the activity access request are acquired, so as to determine the target activity corresponding to the target activity ID; if the local cache service corresponding to the target activity in the target node is started at this time, it is judged whether the first target quantity recorded in the local cache is zero; wherein the first target quantity is the quantity of the activity quota corresponding to the target activity recorded in the local cache; if the first target quantity is zero, it is further judged whether the second target quantity recorded in the remote cache is zero; wherein the second target quantity is the quantity of the activity quota corresponding to the target activity recorded in the remote cache; if the second target quantity is not zero, the third target quantity is calculated; after obtaining the third target quantity, the size relationship between the second target quantity and the third target quantity is judged; if the second target quantity is greater than the third target quantity, the first target quantity recorded in the local cache is updated to the third target quantity, and the second target quantity recorded in the remote cache is updated to the difference between the second target quantity and the third target quantity; that is, the activity quota corresponding to the target activity added in the local cache all comes from the remote cache, so that the quantity of the activity quota corresponding to the target activity can be kept consistent in the local cache and the remote cache, and finally the quantity of the activity quota corresponding to the target activity recorded in the local cache is processed according to the request type and the strategy corresponding to the request type. By querying whether the activity quota corresponding to the target activity exists in the local cache, if not, a certain quantity of activity quotas in the remote cache is allocated to the local cache, so that the pressure of the remote cache can be reduced, the risk of system collapse due to excessive hotspot data access pressure can be reduced, and the speed of access response can also be improved to a certain extent by reading data from the local cache. BRIEF DESCRIPTION OF DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.
[0048] Figure 1 A flowchart of a hotspot data caching method provided by an embodiment of the present application;
[0049] Figure 2 A flowchart of the step of calculating the third target quantity provided by an embodiment of the present application;
[0050] Figure 3A flowchart of steps of processing the number of activity quotas corresponding to the target activity recorded in the local cache according to the request type is provided for the embodiments of the present application;
[0051] Figure 4 A structural diagram of a hot data cache device is provided for the embodiments of the present application.
[0052] Figure 5 An internal structure diagram of a computer device is provided for the embodiments of the present application. DETAILED DESCRIPTION
[0053] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0054] As shown in Figure 1 The present application provides a hot data caching method, which is applied to any node of a server and includes the following steps.
[0055] Step S101: When receiving an activity access request initiated by a client, obtaining a target activity ID, a request type and a target node contained in the activity access request.
[0056] Step S102: Determining a target activity corresponding to the target activity ID according to the target activity ID.
[0057] Each target activity ID corresponds to a unique target activity.
[0058] Step S103: If the local cache service corresponding to the target activity in the target node is started, determining whether a first target number recorded in the local cache is zero.
[0059] The first target number is the number of activity quotas corresponding to the target activity recorded in the local cache.
[0060] Specifically, the local cache service of the target node can be manually started by an operation and maintenance personnel, or the local cache service can be set to be started in a certain time period to achieve the purpose of automatically starting the local cache service.
[0061] It can be understood that if the local cache service corresponding to the target activity in the target node is not started, the activity access request can be responded by using the activity quota corresponding to the target activity in the remote cache.
[0062] Step S104: If the first target quantity is zero, it is determined whether the second target quantity recorded in the remote cache is zero.
[0063] The second target quantity is the number of activity quotas corresponding to the target activity recorded in the remote cache.
[0064] Step S105: If the second target quantity is zero, the local cache service is closed, and a notification of closing the local cache service is sent to other nodes in the service end.
[0065] Step S106: An empty quota identifier is set for the target node.
[0066] The empty quota identifier is used to represent that there is no activity quota corresponding to the target activity in the remote cache of the corresponding node.
[0067] Specifically, when the first target quantity and the second target quantity are both zero, it means that there is no activity quota corresponding to the target activity in the local cache and the remote cache of the target node. At this time, in order to ensure the consistency of the activity quotas in the local cache and the remote cache, the local cache service corresponding to the target activity in the target node is closed, a notification of closing the local cache service is sent to other nodes in the service end, and finally an empty quota identifier is set for the target node.
[0068] Further, the empty quota identifier can be maintained by a Map data structure, and the value of the Map data structure is initially 0 or false. When the empty quota identifier is set, the value in the corresponding Map data structure is set to 1 or true.
[0069] Step S107: If the second target quantity is not zero, a third target quantity is calculated.
[0070] The third target quantity is the number of activity quotas corresponding to the target activity that needs to be transferred from the remote cache to the local cache when the first target quantity is zero.
[0071] Further, when the first target quantity recorded in the local cache is zero and the second target quantity recorded in the remote cache is not zero, the third target quantity needs to be calculated according to the number of nodes in the service end and the number of activity quotas corresponding to the target activity.
[0072] It can be understood that the purpose of determining whether the second target quantity is zero is to determine whether there is an activity quota corresponding to the target activity in the remote cache, and the determination criteria include but are not limited to determining whether the second target quantity is zero, determining whether the target activity is marked with an empty quota label.
[0073] Step S108: Determine the size relationship between the second target quantity and the third target quantity.
[0074] It can be understood that when the calculated third target quantity is greater than the second target quantity, i.e., the number of the activity quota corresponding to the target activity recorded in the remote cache, the activity quota corresponding to the third target quantity cannot be transferred from the activity quota corresponding to the target activity recorded in the remote cache to the local cache, and thus, it is necessary to determine the size relationship between the second target quantity and the third target quantity, so as to determine the number of the activity quota actually transferred from the activity quota corresponding to the target activity recorded in the remote cache to the local cache.
[0075] Step S109: If the second target quantity is greater than the third target quantity, the first target quantity recorded in the local cache is updated to the third target quantity, and the second target quantity recorded in the remote cache is updated to the difference between the second target quantity and the third target quantity.
[0076] Specifically, when the second target quantity, i.e., the number of the activity quota corresponding to the target activity recorded in the remote cache, is greater than the third target quantity, the activity quota corresponding to the third target quantity can be transferred from the activity quota corresponding to the target activity recorded in the remote cache to the local cache.
[0077] Step S110: According to the request type, a strategy corresponding to the request type is selected to process the number of the activity quota corresponding to the target activity recorded in the local cache.
[0078] Step S111: If the second target quantity is not greater than the third target quantity, the first target quantity recorded in the local cache is updated to the second target quantity, and the second target quantity recorded in the remote cache is updated to zero.
[0079] Step S112: According to the request type, a strategy corresponding to the request type is selected to process the number of the activity quota corresponding to the target activity recorded in the local cache.
[0080] Exemplarily, when the first target quantity recorded in the local cache is zero, it is assumed that the second target quantity recorded in the remote cache is 10, and the third target quantity is 8, at this time, the second target quantity recorded in the remote cache is greater than the third target quantity, and thus, the first target quantity recorded in the local cache is updated to 8, and the second target quantity recorded in the remote cache is updated to the difference between the second target quantity and the third target quantity, i.e., updated to 2. It is assumed that the second target quantity recorded in the remote cache is 10, and the third target quantity is 12, at this time, the second target quantity recorded in the remote cache is not greater than the third target quantity, and thus, the first target quantity recorded in the local cache is updated to 10, and the second target quantity recorded in the remote cache is updated to zero.
[0081] Step S113: If the first target quantity is not zero, then according to the request type, select the strategy corresponding to the request type to process the number of activity slots recorded in the local cache corresponding to the target activity.
[0082] Specifically, when the number of the first target recorded in the local cache is not zero, it is not necessary to transfer a certain number of activity slots from the activity slots corresponding to the target activity recorded in the remote cache to the local cache. Instead, the activity slots corresponding to the target activity recorded in the local cache will be used first.
[0083] The hot data caching method provided in this application, when the server receives an activity access request initiated by the client, obtains the target activity ID, request type, and target node contained in the activity access request; in order to determine the target activity corresponding to the target activity ID; if the local caching service corresponding to the target activity in the target node is already enabled, it determines whether the first target quantity recorded in the local cache is zero; wherein, the first target quantity is the number of activity slots corresponding to the target activity recorded in the local cache; if the first target quantity is zero, it further determines whether the second target quantity recorded in the remote cache is zero; wherein, the second target quantity is the number of activity slots corresponding to the target activity recorded in the remote cache; if the second target quantity is zero... If the quantity is not zero, calculate the third target quantity. After obtaining the third target quantity, determine the relationship between the second and third target quantities. If the second target quantity is greater than the third target quantity, update the first target quantity recorded in the local cache to the third target quantity, and update the second target quantity recorded in the remote cache to the difference between the second and third target quantities. This means that all activity slots added to the local cache corresponding to the target activity come from the remote cache, ensuring consistency in the number of activity slots corresponding to the target activity between the local and remote caches. Finally, based on the request type, select the strategy corresponding to the request type to process the number of activity slots recorded in the local cache corresponding to the target activity. By checking if there are activity slots corresponding to the target activity in the local cache, and if not, allocating a certain number of activity slots from the remote cache to the local cache, the pressure on the remote cache can be reduced, lowering the risk of system crash due to excessive access pressure from hot data. Furthermore, reading data from the local cache can also improve the access response speed to some extent.
[0084] like Figure 2 As shown, in one embodiment, the step of calculating the number of third targets includes:
[0085] Step S201: Obtain the number of nodes on the server.
[0086] The number of nodes on the server side is the total number of nodes on the server side.
[0087] Step S202: According to the target activity ID, the number of activity quotas is obtained; wherein, the number of activity quotas is the number of activity quotas corresponding to the target activity.
[0088] For example, assuming that the online mall of brand A launches a buy-one-get-one-free activity, the number of activity quotas is 30, that is, the number of activity quotas corresponding to the buy-one-get-one-free activity is 30.
[0089] Step S203: The number of activity quotas is divided by the number of nodes, and the quotient of the number of activity quotas and the number of nodes is rounded down to obtain a first value.
[0090] Step S204: If the first value is not less than a preset second value, the second value is determined as a third target number.
[0091] Step S205: If the first value is less than the second value, the first value is determined as the third target number.
[0092] For example, assuming that the number of nodes of the server is 16, and the number of activity quotas is 420, then the number of activity quotas is divided by the number of nodes to obtain 26.25, and the quotient of the number of activity quotas and the number of nodes is rounded down to obtain a first value of 26. If the preset second value is 10, the first value is not less than the preset second value, then the third target number is 10. If the preset second value is 30, the first value is less than the second value, then the third target number is 26.
[0093] Since the third target number is calculated according to the number of activity quotas and the number of nodes, then whether the number of activity quotas or the number of nodes changes will affect the third target number. For different activities, the third target number can be adjusted accordingly, the number of activity quotas transferred to the local cache can be reasonably set, which is further conducive to the load balancing of the local cache and the remote cache.
[0094] As shown in the figure, in one of the embodiments, the request type includes a first request type and a second request type, including: Figure 3 Step S301: According to the request type, the strategy corresponding to the request type is selected to process the number of activity quotas corresponding to the target activity recorded in the local cache.
[0095] Step S302: Determine whether the request type is the first request type.
[0096] Step S303: If the request type is the first request type, then the number of activity quotas corresponding to the target activity recorded in the local cache is decremented by one.
[0097] Step S303: If the request type is the first request type, then the number of activity quotas corresponding to the target activity recorded in the local cache is decremented by one.
[0098] Specifically, when the request type of the activity access request initiated by the client belongs to the first request type, i.e., the activity access request requests an activity quota corresponding to the target activity, the number of the activity quota corresponding to the target activity recorded in the local cache needs to be updated.
[0099] As shown in Figure 3 the request type includes the first request type and the second request type, including:
[0100] Step S304: If the request type is the second request type, return the number of the activity quota corresponding to the target activity recorded in the local cache to the client.
[0101] Specifically, when the request type of the activity access request initiated by the client belongs to the second request type, i.e., the purpose of the activity access request is to check the number of the activity quota corresponding to the target activity recorded in the local cache, the number of the activity quota corresponding to the target activity recorded in the local cache does not need to be updated, and the number of the activity quota corresponding to the target activity recorded in the local cache can be returned to the client.
[0102] In one of the embodiments, the method further includes:
[0103] When the local cache service of any node of the server is closed, the number of the activity quota corresponding to the target activity recorded in the remote cache of the node is updated to the sum of the number of the activity quota corresponding to the target activity recorded in the local cache and the number of the activity quota corresponding to the target activity recorded in the current remote cache, and the number of the activity quota corresponding to the target activity recorded in the local cache of the node is updated to zero.
[0104] Exemplarily, when the local cache service of any node is closed, if the number of the activity quota corresponding to the target activity recorded in the local cache is 2 and the number of the activity quota corresponding to the target activity recorded in the remote cache is 5, the number of the activity quota corresponding to the target activity recorded in the local cache is updated to zero, and the number of the activity quota corresponding to the target activity recorded in the remote cache is updated to 7.
[0105] It should be understood that although the steps in the flowcharts involved in the embodiments described above are shown in sequence according to the arrows, the steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of the steps is not strictly limited in sequence, and the steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts involved in the embodiments described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of the steps or stages is not necessarily sequential, but can be alternately executed with other steps or steps or stages in other steps.
[0106] The hotspot data caching device provided by the embodiments of the present application is described below. The hotspot data caching device described below can be correspondingly referred to the hotspot data caching method described above.
[0107] As shown in Figure 4 The embodiments of the present application provide a hotspot data caching device 400, which is applied to any node of a server and includes:
[0108] The obtaining module 401 is configured to obtain a target activity ID, a request type and a target node included in the active access request when receiving the active access request initiated by the client.
[0109] The determining module 402 is configured to determine a target activity corresponding to the target activity ID according to the target activity ID.
[0110] The first judging module 403 is configured to judge whether a first target number recorded in the local cache is zero if the local cache service corresponding to the target activity in the target node is started. The first target number is the number of activity quotas corresponding to the target activity recorded in the local cache.
[0111] The second judging module 404 is configured to judge whether a second target number recorded in the remote cache is zero if the first target number is zero. The second target number is the number of activity quotas corresponding to the target activity recorded in the remote cache.
[0112] The calculating module 405 is configured to calculate a third target number if the second target number is not zero.
[0113] The updating module 406 is configured to update the first target number recorded in the local cache to the third target number and update the second target number recorded in the remote cache to the difference between the second target number and the third target number if the second target number is greater than the third target number.
[0114] The request processing module 407 is configured to select a strategy corresponding to the request type to process the number of the activity quota corresponding to the target activity recorded in the local cache according to the request type.
[0115] In one of the embodiments, the apparatus further includes:
[0116] The third determining module is configured to update the first target number recorded in the local cache to the second target number and update the second target number recorded in the remote cache to zero if the second target number is not greater than the third target number.
[0117] The first processing module is configured to select a strategy corresponding to the request type to process the number of the activity quota corresponding to the target activity recorded in the local cache according to the request type.
[0118] In one of the embodiments, the apparatus further includes:
[0119] The second processing module is configured to select a strategy corresponding to the request type to process the number of the activity quota corresponding to the target activity recorded in the local cache according to the request type if the first target number is not zero.
[0120] In one of the embodiments, the apparatus further includes:
[0121] The fourth determining module is configured to close the local cache service and send a notification of closing the local cache service to other nodes in the service end if the second target number is zero.
[0122] The no-quota identifier setting module is configured to set a no-quota identifier for the target node, wherein the no-quota identifier is used to represent that the remote cache corresponding to the node has no activity quota corresponding to the target activity.
[0123] In one of the embodiments, the calculation module 405 includes:
[0124] The first obtaining sub-module is configured to obtain the number of nodes of the service end.
[0125] The second obtaining sub-module is configured to obtain the number of activity quotas according to the target activity ID, wherein the number of activity quotas is the number of activity quotas corresponding to the target activity.
[0126] The calculation sub-module is configured to divide the number of activity quotas by the number of nodes and round down the quotient of the number of activity quotas and the number of nodes to obtain a first value.
[0127] The first determining sub-module is configured to determine the second value as the third target number if the first value is not less than a preset second value.
[0128] The second determining sub-module is configured to determine the first number as the third target number if the first number is less than the second number.
[0129] In one of the embodiments, the request type includes a first request type and a second request type.
[0130] When the request type is the first request type, the request processing module 407 includes:
[0131] The first processing sub-module is configured to perform a minus one operation on the number of the event quota corresponding to the target event recorded in the local cache.
[0132] In one of the embodiments, the request type includes a first request type and a second request type.
[0133] When the request type is the second request type, the request processing module 407 includes:
[0134] The second processing sub-module is configured to return the number of the event quota corresponding to the target event recorded in the local cache to the client.
[0135] In one of the embodiments, the apparatus further includes:
[0136] The number updating module is configured to, when the local cache service of any node of the server is closed, update the number of the event quota corresponding to the target event recorded in the remote cache of the node to the sum of the number of the event quota corresponding to the target event recorded in the local cache and the number of the event quota corresponding to the target event recorded in the current remote cache, and update the number of the event quota corresponding to the target event recorded in the local cache of the node to zero.
[0137] The division of each module in the hot data cache apparatus is only for example, and in other embodiments, the hot data cache apparatus can be divided into different modules as needed to complete all or part of the functions of the hot data cache apparatus. Each module in the hot data cache apparatus can be implemented in whole or in part by software, hardware, and combinations thereof. Each module described above can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so as to be called and executed by the processor to perform the operations corresponding to each module.
[0138] In one embodiment, the present application further provides a storage medium, wherein the storage medium stores computer readable instructions, and the computer readable instructions are executed by one or more processors to make the one or more processors perform the following steps:
[0139] When receiving the activity access request initiated by the client, obtaining the target activity ID, the request type and the target node included in the activity access request;
[0140] According to the target activity ID, determining a target activity corresponding to the target activity ID;
[0141] If the local cache service corresponding to the target activity in the target node is started, judging whether a first target quantity recorded in the local cache is zero; wherein the first target quantity is a quantity of the activity quota corresponding to the target activity recorded in the local cache;
[0142] If the first target quantity is zero, judging whether a second target quantity recorded in the remote cache is zero; wherein the second target quantity is a quantity of the activity quota corresponding to the target activity recorded in the remote cache;
[0143] If the second target quantity is not zero, calculating a third target quantity;
[0144] If the second target quantity is greater than the third target quantity, updating the first target quantity recorded in the local cache to the third target quantity, and updating the second target quantity recorded in the remote cache to a difference between the second target quantity and the third target quantity;
[0145] According to the request type, selecting a strategy corresponding to the request type to process the quantity of the activity quota corresponding to the target activity recorded in the local cache.
[0146] In one of the embodiments, the computer readable instructions, when executed by the processor, further implement the following steps:
[0147] If the second target quantity is not greater than the third target quantity, updating the first target quantity recorded in the local cache to the second target quantity, and updating the second target quantity recorded in the remote cache to zero;
[0148] According to the request type, selecting a strategy corresponding to the request type to process the quantity of the activity quota corresponding to the target activity recorded in the local cache.
[0149] In one of the embodiments, the computer readable instructions, when executed by the processor, further implement the following steps:
[0150] If the first target quantity is not zero, according to the request type, selecting a strategy corresponding to the request type to process the quantity of the activity quota corresponding to the target activity recorded in the local cache.
[0151] In one of the embodiments, the computer readable instructions, when executed by the processor, further implement the following steps:
[0152] If the second target number is zero, the local cache service is closed, and a local cache service closing notification is sent to other nodes in the service end;
[0153] Setting an anonymous quota identifier for the target node; wherein the anonymous quota identifier is used to represent that there is no activity quota corresponding to the target activity in the remote cache of the corresponding node.
[0154] In one embodiment, the computer readable instructions, when executed by the processor, further implement the following steps:
[0155] Obtaining the number of nodes of the service end;
[0156] According to the target activity ID, obtaining the number of activity quotas; wherein the number of activity quotas is the number of activity quotas corresponding to the target activity;
[0157] Dividing the number of activity quotas by the number of nodes, and rounding down the quotient of the number of activity quotas and the number of nodes to obtain a first value;
[0158] If the first value is not less than a preset second value, the second value is determined as a third target number;
[0159] If the first value is less than the second value, the first value is determined as the third target number.
[0160] In one embodiment, the computer readable instructions, when executed by the processor, further implement the following steps:
[0161] Performing a minus one operation on the number of activity quotas corresponding to the target activity recorded in the local cache.
[0162] In one embodiment, the computer readable instructions, when executed by the processor, further implement the following steps:
[0163] Returning the number of activity quotas corresponding to the target activity recorded in the local cache to the client.
[0164] In one embodiment, the computer readable instructions, when executed by the processor, further implement the following steps:
[0165] When closing the local cache service of any node of the service end, updating the number of activity quotas corresponding to the target activity recorded in the remote cache of the node to the sum of the number of activity quotas corresponding to the target activity recorded in the local cache and the number of activity quotas corresponding to the target activity recorded in the current remote cache, and updating the number of activity quotas corresponding to the target activity recorded in the local cache of the node to zero.
[0166] In one embodiment, this application also provides a computer device storing computer-readable instructions, wherein when the one or more processors execute the computer-readable instructions, they perform the following steps:
[0167] When an activity access request is received from a client, retrieve the target activity ID, request type, and target node contained in the activity access request;
[0168] Based on the target activity ID, determine the target activity corresponding to the target activity ID;
[0169] If the local caching service corresponding to the target activity is enabled in the target node, then determine whether the first target quantity recorded in the local cache is zero; where the first target quantity is the number of activity slots corresponding to the target activity recorded in the local cache.
[0170] If the first target quantity is zero, then determine whether the second target quantity recorded in the remote cache is zero; where the second target quantity is the number of activity slots corresponding to the target activity recorded in the remote cache.
[0171] If the quantity of the second objective is not zero, then calculate the quantity of the third objective;
[0172] If the number of the second target is greater than the number of the third target, then update the number of the first target recorded in the local cache to the number of the third target, and update the number of the second target recorded in the remote cache to the difference between the number of the second target and the number of the third target;
[0173] Based on the request type, select the strategy corresponding to the request type to process the number of activity slots recorded in the local cache that correspond to the target activity.
[0174] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0175] If the number of the second target is not greater than the number of the third target, then update the number of the first target recorded in the local cache to the number of the second target, and update the number of the second target recorded in the remote cache to zero;
[0176] Based on the request type, select the strategy corresponding to the request type to process the number of activity slots recorded in the local cache that correspond to the target activity.
[0177] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0178] If the first target quantity is not zero, then based on the request type, select the strategy corresponding to the request type to process the number of activity slots recorded in the local cache that correspond to the target activity.
[0179] In one of the embodiments, the processor, when executing the computer readable instructions, further performs the following steps:
[0180] If the second target number is zero, the local cache service is closed, and a notification of closing the local cache service is sent to other nodes in the service end;
[0181] The target node is set with an anonymous quota identifier; wherein the anonymous quota identifier is used to represent that there is no activity quota corresponding to the target activity in the remote cache of the corresponding node.
[0182] In one of the embodiments, the processor, when executing the computer readable instructions, further performs the following steps:
[0183] The number of nodes of the service end is obtained;
[0184] According to the target activity ID, the number of activity quotas is obtained; wherein the number of activity quotas is the number of activity quotas corresponding to the target activity;
[0185] The number of activity quotas is divided by the number of nodes, and the quotient of the number of activity quotas and the number of nodes is rounded down to obtain a first value;
[0186] If the first value is not less than a preset second value, the second value is determined as a third target number;
[0187] If the first value is less than the second value, the first value is determined as the third target number.
[0188] In one of the embodiments, the processor, when executing the computer readable instructions, further performs the following steps:
[0189] The number of activity quotas corresponding to the target activity recorded in the local cache is decremented by one.
[0190] In one of the embodiments, the processor, when executing the computer readable instructions, further performs the following steps:
[0191] The number of activity quotas corresponding to the target activity recorded in the local cache is returned to the client.
[0192] In one of the embodiments, the processor, when executing the computer readable instructions, further performs the following steps:
[0193] When the local cache service of any node of the service end is closed, the number of activity quotas corresponding to the target activity recorded in the remote cache of the node is updated to the sum of the number of activity quotas corresponding to the target activity recorded in the local cache and the number of activity quotas corresponding to the target activity recorded in the current remote cache, and the number of activity quotas corresponding to the target activity recorded in the local cache of the node is updated to zero.
[0194] As shown in Figure 5 , Figure 5 An internal structure diagram of a computer device is provided for the embodiments of the present application. The computer device 500 can be provided as a server. Referring to Figure 5 , the computer device 500 includes a processing component 502, which further includes one or more processors, and a memory resource represented by a memory 501 for storing instructions, such as an application program, executable by the processing component 502. The application program stored in the memory 501 can include one or more than one module each corresponding to a set of instructions. In addition, the processing component 502 is configured to execute the instructions to perform the hotspot data caching method of any of the embodiments described above.
[0195] The computer device 500 can further include a power component 503 configured to perform power management of the computer device 500, a wired or wireless network interface 504 configured to connect the computer device 500 to a network, and an input / output (I / O) interface 505. The computer device 500 can operate based on an operating system stored in the memory 501, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.
[0196] Those skilled in the art can understand that Figure 5 the structure shown in the above is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or less components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0197] Finally, it should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting. It will be apparent to those skilled in the art that various modifications and variations can be made in the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application cover modifications and variations of this application provided they come within the scope of the appended claims and their equivalents.
[0198] Various embodiments described in the specification can be presented with respect to relative to sequence, methodology, data structures, and other illustrative criteria. However, these descriptions and representations are used by those skilled in the art of application development to most effectively convey the substance of their work to others skilled in the art. A skilled artisan will recognize that equivalents to the specific procedure described are possible, and are intended to be encompassed by the description and the claims. It will be apparent to those reasonably skilled in the art that changes can be made to the details of the above-described embodiments without departing from the underlying principles thereof.
[0199] The above description of disclosed embodiments is intended to be illustrative and not restrictive. Many embodiments will be apparent to those of skill in the art upon reading and understanding the above description, and the applications are not limited to the embodiments described. One skilled in the art will readily recognize from the prior art that the application can be practiced with various computer system configurations, including single-processor or multiprocessor computer systems, mini-computers or mainframe computers, computer-simulated or virtual machines, as well as computer systems and processes that can include distributed computing environments, multiprocessor systems, networked computers or the like. The application can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In this description, all addresses, version numbers, and like specifications are intended to be illustrative only and not restrictive.
Claims
1. A method for caching hotspot data, characterized by, The method is applied to any node of a service end, and comprises: When receiving an active access request initiated by a client, obtaining a target active ID, a request type and a target node contained in the active access request; According to the target active ID, determining a target active corresponding to the target active ID; If a local cache service corresponding to the target active in the target node has been started, judging whether a first target quantity recorded in a local cache is zero; wherein the first target quantity is a quantity of active quotas corresponding to the target active recorded in the local cache; If the first target quantity is zero, judging whether a second target quantity recorded in a remote cache is zero; wherein the second target quantity is a quantity of active quotas corresponding to the target active recorded in the remote cache; If the second target quantity is not zero, calculating a third target quantity; If the second target quantity is greater than the third target quantity, updating the first target quantity recorded in the local cache to the third target quantity, and updating the second target quantity recorded in the remote cache to a difference between the second target quantity and the third target quantity; According to the request type, selecting a strategy corresponding to the request type to process the quantity of active quotas corresponding to the target active recorded in the local cache.
2. The hotspot data caching method of claim 1, wherein, The method further comprises: If the second target quantity is not greater than the third target quantity, updating the first target quantity recorded in the local cache to the second target quantity, and updating the second target quantity recorded in the remote cache to zero; According to the request type, selecting a strategy corresponding to the request type to process the quantity of active quotas corresponding to the target active recorded in the local cache.
3. The hotspot data caching method of claim 1, wherein, The method further comprises: If the first target quantity is not zero, according to the request type, selecting a strategy corresponding to the request type to process the quantity of active quotas corresponding to the target active recorded in the local cache.
4. The method of claim 1, wherein, The method further comprises: If the second target quantity is zero, closing the local cache service, and sending a local cache service closing notification to other nodes in the service end; Setting a no-quota identifier for the target node; wherein the no-quota identifier is used to represent that there is no active quota corresponding to the target active in a remote cache of the corresponding node.
5. The method of claim 1, wherein, The step of calculating the third target quantity comprises: Obtaining a node quantity of the service end; According to the target active ID, obtaining an active quota quantity; wherein the active quota quantity is a quantity of active quotas corresponding to the target active; Dividing the active quota quantity by the node quantity, and rounding down the quotient of the active quota quantity and the node quantity to obtain a first value; If the first value is not less than a preset second value, determining the second value as the third target quantity; If the first value is less than the second value, determining the first value as the third target quantity.
6. The hot spot data caching method of any of claims 1 to 3, wherein, The request type comprises a first request type and a second request type; When the request type is the first request type, a strategy corresponding to the request type is selected to process the number of activity quotas corresponding to the target activity recorded in the local cache, including: performing a minus one operation on the number of activity quotas corresponding to the target activity recorded in the local cache.
7. The hotspot data caching method of claim 6, wherein, When the request type is the second request type, a strategy corresponding to the request type is selected to process the number of activity quotas corresponding to the target activity recorded in the local cache, including: returning the number of activity quotas corresponding to the target activity recorded in the local cache to the client.
8. The hot spot data caching method of any of claims 1 to 4, wherein, The method further includes: when the local cache service of any node of the server is closed, updating the number of activity quotas corresponding to the target activity recorded in the remote cache of the node to the sum of the number of activity quotas corresponding to the target activity recorded in the local cache and the number of activity quotas corresponding to the target activity recorded in the current remote cache, and updating the number of activity quotas corresponding to the target activity recorded in the local cache of the node to zero.
9. A hot spot data caching apparatus, characterized by, The device is applied to any node of the server, and includes: an acquisition module, configured to acquire a target activity ID, a request type and a target node included in an activity access request initiated by a client when the activity access request is received; a determination module, configured to determine a target activity corresponding to the target activity ID according to the target activity ID; a first judgment module, configured to judge whether a first target number recorded in the local cache is zero if the local cache service corresponding to the target activity in the target node has been started, wherein the first target number is the number of activity quotas corresponding to the target activity recorded in the local cache; a second judgment module, configured to judge whether a second target number recorded in the remote cache is zero if the first target number is zero, wherein the second target number is the number of activity quotas corresponding to the target activity recorded in the remote cache; a calculation module, configured to calculate a third target number if the second target number is not zero; an update module, configured to update the first target number recorded in the local cache to the third target number and update the second target number recorded in the remote cache to the difference between the second target number and the third target number if the second target number is greater than the third target number; a request processing module, configured to select a strategy corresponding to the request type to process the number of activity quotas corresponding to the target activity recorded in the local cache according to the request type.
10. A storage medium characterized by: The storage medium has computer readable instructions stored therein, and the computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the steps of the hot data caching method according to any one of claims 1 to 8.
11. A computer device, comprising: including: one or more processors, and a memory; the memory has computer readable instructions stored therein, and the computer readable instructions, when executed by the one or more processors, perform the steps of the hot data caching method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Access request processing method and device
CN109597915A
Hot spot data storage method and terminal
CN109992597A