Application node cache updating method, storage medium and terminal
By setting unique cache periods for local caches using a hash-based method, the method addresses database instability caused by simultaneous cache expiration, ensuring stable and efficient database access.
Patent Information
- Application Number
- CN202411292988.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-17
AI Technical Summary
Database cache systems experience instability and slow access due to simultaneous expiration of large numbers of local caches, leading to a surge in access requests that overwhelm the database and cause crashes.
Implement a method to set different cache periods for multiple local caches using a hash-based formula, ensuring they expire at different times, thereby distributing the cache invalidation and update process to avoid simultaneous access to the database.
Prevents simultaneous cache expiration and update, reducing database access pressure and maintaining service stability by distributing cache invalidation and update times.
Smart Images

Figure CN119149595A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database cache, and in particular to an application node cache update method, storage medium and terminal. Background Art
[0002] The history of cache technology can be traced back to the early days of the computer industry. With the development of computer technology, cache technology has also continued to evolve and innovate, and has now become an indispensable component of computer systems. The earliest cache technology was browser cache, which stores some web page resources on the local computer so that they can be quickly loaded the next time they are visited. Later, with the continuous development of Internet technology, cache technology has also gradually developed, and various types of cache technologies have emerged, such as static resource file cache, content delivery network (CDN-Content Delivery Network) cache, database cache, and distributed cache.
[0003] In the Internet field, cache technology also plays a very important role. It can significantly improve the performance and availability of websites and applications, relieve server pressure, reduce bandwidth costs, and improve user experience. At present, database cache and distributed cache are mainly used in the Internet. The traditional database local cache update algorithm generally sets an effective time for the local cache data. When accessing the local cache data, first check whether the effective time of the local cache data has expired. If not, directly use the data in the local cache. If expired, re-query the database and update the old data in the local cache with the latest data. However, if a large amount of cached data in a certain application node happens to expire at the same time, and the service itself is a high-traffic service, the access volume of these cached data is large, then a large number of query requests will pass through the cache layer at the same time and be transmitted to the database layer. The database may not be able to withstand the sudden surge in access requests, and the access becomes slow or even crashes, resulting in instability of the entire service. Summary of the invention
[0004] The embodiment of the present invention provides an application node cache update method, storage medium and terminal. Through a predetermined cache period setting method, different cache periods are set for multiple local caches that are simultaneously established or invalidated in an application node, so that the multiple local caches are subsequently invalidated at different times.
[0005] In a first aspect, an embodiment of the present invention provides an application node cache update method, comprising:
[0006] The target application node establishes K local caches at the first timestamp T1; K>0, and K is an integer;
[0007] The target application node is based on the Nth iLocal cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer;
[0008] When the Nth i Local cache in T Ni After the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0009] In a second aspect, an embodiment of the present invention provides an application node cache update method, comprising:
[0010] The target application node determines K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer;
[0011] The target application node sends the Nth i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer;
[0012] The target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0013] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method steps described in the first aspect or the method steps described in the second aspect are implemented.
[0014] In a fourth aspect, an embodiment of the present invention provides a terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method steps described in the first aspect or the method steps described in the second aspect when executing the computer program.
[0015] The application node cache update method, storage medium and terminal provided by the embodiments of the present invention have the following technical effects:
[0016] The embodiment of the present invention obtains multiple local caches that are established or invalidated at the same time in a certain application node, sets a different cache period for each local cache through the hash value of each local cache and the preset time period or the original cache period of the local cache, and a predetermined setting method, and updates the local cache after the local cache expires. Applying the above method, multiple local caches that are established or invalidated at the same time in the same application node can have different cache periods and subsequently expire at different times. This solves the problem that the database receives a large number of access requests at the same time, resulting in slow access, crashes and unstable services. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 A schematic diagram of the architecture of a distributed system provided by an embodiment of the present invention;
[0019] Figure 2 A flow chart of an application node cache update method provided by an embodiment of the present invention;
[0020] Figure 3 Another flow chart of an application node cache update method provided by an embodiment of the present invention
[0021] Figure 4 A schematic diagram of the structure of an application node cache update device provided by an embodiment of the present invention;
[0022] Figure 5 A schematic diagram of another application node cache update device provided by an embodiment of the present invention
[0023] Figure 6 A block diagram of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are only examples of devices and methods consistent with some aspects of the present invention as detailed in the attached claims.
[0026] In the description of the present invention, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0027] In the Internet field, caching technology plays a very important role. It can significantly improve the performance and availability of websites and applications, relieve server pressure, and reduce bandwidth costs. Currently, database cache and distributed cache are mainly used in the Internet.
[0028] like Figure 1 As shown, it is a schematic diagram of the architecture of a distributed system provided by an embodiment of the present invention. The distributed system includes at least one user terminal 101, at least one application node 102 and at least one database 103. The user terminal is a device used by the user, such as a smart phone, a tablet computer, etc.; the application node is used to temporarily store local cache data and provide local cache data for the user terminal; the database persists all data and provides data query services for the application node. When the distributed system includes multiple application nodes, the multiple application nodes can share a database or use different databases.
[0029] like Figure 1 The distributed system shown in the figure uses local cache technology to save frequently accessed hot data in the database to the local cache of each application node, which can greatly improve the service response speed and system throughput. There is a lot of data that needs to be cached locally. If a large number of local caches are established at the same time in a certain application node, and the data corresponding to these local caches are all stored in the same database, when the cache cycles of these local caches are the same, these local caches will fail at the same time and need to be cached and updated. Then a large number of access requests will instantly pass through the cache layer and be transmitted to the database layer, causing a surge in database access pressure, slowing down the database, or even crashing, which in turn affects the availability and stability of the service. Or if a large number of local caches in a certain application node fail at the same time and have the same cache cycle, it will also cause the above problems.
[0030] In view of the above problems, the present invention provides an application node cache update method, a storage medium and a terminal. In the following, each step of the application node cache update method in the embodiment of the present invention will be described in more detail with reference to the accompanying drawings and embodiments.
[0031] Figure 2 A flow chart of an application node cache update method provided by an embodiment of the present invention. Figure 2 As shown, the method of the embodiment of the present invention may include the following steps:
[0032] S201, the target application node establishes K local caches at the first timestamp T1; K>0, and K is an integer.
[0033] In the embodiment of the present invention, the target application node establishes K local caches at the first timestamp T1, where K>0 and K is an integer. The data that needs to establish a local cache is generally frequently accessed data, and there is a lot of data that needs to establish a local cache. Therefore, K is generally a large value, such as 1000, 10000, etc., or even larger, and each local cache is accessed more frequently. Therefore, if all local caches fail at the same time, it will cause greater access pressure on the database.
[0034] S202, the target application node according to the Nth i Local cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer.
[0035] Optionally, after the target application node establishes K local caches at the same time at the first timestamp, if the cache periods of these K local caches are the same, then these K cache periods will expire at the same time. For example, the target application node establishes 10,000 local caches at the same time at 10 o'clock, and the cache period of all local caches is 1 hour, then these 10,000 local caches will expire at 11 o'clock. After each local cache expires, the cache will be updated, and access requests will be sent to the database at the same time, causing a surge in database access pressure, slowing down the database, and possibly affecting the availability and stability of the service. Therefore, in order to avoid this situation, a different cache period can be set for each local cache so that a large number of local caches do not expire at the same time, alleviating the access pressure on the database.
[0036] Optionally, as can be seen from the above, the target application node establishes K local caches at the first timestamp T1. When setting a different cache period for each local cache, it is easy to cause confusion if the cache period is set irregularly. Therefore, the cache period can be set in combination with the relevant information of each local cache. Specifically, the target application node sets the cache period according to the Nth time stamp. i Local cache, set the Nthi The cache period of the local cache is T i , where 1≤i≤K, and i is an integer. If i=1, it is the N1th local cache, which can be understood as the first local cache among the K local caches established by the target application node, and the corresponding cache period T1 is set. The specific steps include:
[0037] S202.1, the target application node is based on the formula T i =hash(key i )%(T / 2)+(T / 2) calculates the cache period T i , where hash(key i ) is the Nth i The hash value of the local cache, T is the preset time period, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and taking the remainder;
[0038] S202.2, the Nth i The cache period of the local cache is set to T i .
[0039] Optionally, set the Nth i The cache period of the local cache is T i When you first need to obtain the Nth i The cache period of the local cache is T i . Cache period T i It can be obtained through the following formula:
[0040] T i =hash(key i )%(T / 2)+(T / 2) (1)
[0041] In the above formula, hash(key i ) is the Nth i The hash value of the local cache, T is the preset time period, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) to get the remainder. Each local cache is actually a data item, such as the N1th local cache is A=1. To set a cache period for each local cache, each local cache period needs to be distinguished, and the hash value of the data can distinguish the data. Therefore, the hash value of the local cache can be used to obtain the cache period of the local cache.
[0042] When setting the cache period of the K local caches, although the cache periods of different local caches should be different as much as possible, it is also necessary to ensure that the cache period of each local cache is within an appropriate range and cannot be too long or too short. Therefore, the cache period of the above K local caches should be within an appropriate range.
[0043] As can be seen from the above, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and taking the remainder, we can know through analysis that 0≤hash(key i )%(T / 2)≤(T / 2)-1, from which we can know that T / 2≤T i ≤T-1, that is, the cache period of all local caches is distributed in the time range of T / 2 to T-1. T is a preset time period, which can be determined according to the actual situation. If T is 100, the cache period of all local caches is distributed in the time range of 50 to 99. For example, the hash value of the N1th local cache is 10, the hash value of the N2th local cache is 25, and T is 100. Then, according to the above formula (1), the cache period of the N1th local cache is T1=60, and the cache period of the N2th local cache is T2=75. Of course, if there are a large number of local caches in the target application node, according to the above method, there may be multiple local caches with the same cache period. For example, when T is 100, if the hash value of the N1th local cache is 10, the calculated cache period is 60; if the hash value of the N3th local cache is 60, the calculated cache period is also 60, and the cache periods of the two are the same. However, the number will be greatly reduced compared to all local caches in the target application node.
[0044] Calculate the Nth i The cache period of the local cache is T i After that, the target application node can i The cache period of the local cache is set to T i .
[0045] Based on any of the above optional embodiments, S203, when the Nth i The local cache is After the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0046] In the embodiment of the present invention, after the target application node sets corresponding cache periods for K local caches, each local cache will also become invalid after its corresponding cache period expires. At this time, the target application node needs to update the local cache. Since the cache period of each local cache may be different, each local cache will also become invalid at different times.i The local cache is After the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache. The timestamp can be obtained by the following formula:
[0047]
[0048] In the above formula, For the Timestamp, T1 is the first timestamp. From the above, we can know that the target application node is established at the first timestamp. i Local cache, and the Nth i The cache period of the local cache is T i , so the Nth i The expiration time of the local cache is the first timestamp plus its corresponding cache period. For example, the first timestamp T1=100, the Nth i The cache period of the local cache is T i =60, then The timestamp is 100+60=160, which is the Nth i The local cache expires in 160 seconds.
[0049] Nth i After the local cache becomes invalid, the target application node needs to i The local cache is updated to obtain a new local cache.
[0050] In an optional embodiment, the target application node is in the first Timestamp updates the Nth i Local cache, get the new Nth i Local cache.
[0051] In the embodiment of the present invention, the target application node may be Timestamp, that is, the Nth i When the local cache fails, update the Nth i Local cache, get the new Nth i Local cache. For example, the target application node establishes the N1 local cache and the N2 local cache at 0 seconds, and the cache cycles of the N1 local cache and the N2 local cache are 60 seconds and 75 seconds respectively. Then, the N1 local cache will be updated immediately after the first cache cycle expires, that is, after 60 seconds, and the N2 local cache will be updated immediately after the first cache cycle expires, that is, after 75 seconds. It will not expire until the end of the second cache cycle, and then the local cache will be updated again according to the database, and the same operation will be performed for each cache cycle.
[0052] In another optional embodiment, if the target application node is in the Tth NK+1 The timestamp received for the Nth i The local cache usage request updates the Nth i Local cache, get the new Nth i Local cache; the T NK+1 The timestamp is located at the T Ni After the timestamp.
[0053] In the embodiment of the present invention, the target application node may be at the Nth i When the local cache fails, the Nth i Local cache, get the new Nth i Local cache. Therefore, in the T Ni After the timestamp, the Nth i The local cache is invalid. If a user terminal requests the Nth i If the local cache is used, the corresponding Nth i Local cache requires the target application node to re-update the corresponding Nth i Local cache.
[0054] Therefore, if the target application node is in the T NK+1 Timestamp received for the Nth i If the local cache is used, the Nth i Local cache, get the new Nth i Local cache; among them, the T NK+1 The timestamp is located at the Tth Ni After the timestamp. For example, the target application node establishes the corresponding Nth i Local cache, Nth i The local cache period is 60 seconds, so the Nth i The local cache expires at 110 seconds, and the target application node does not update the Nth i Local cache. Within 150 seconds, the target application node receives the Nth i When the local cache is used, the Nth i Local cache, get the new Nth i Local cache.
[0055] In summary, an embodiment of the present invention provides an application node cache update method, which obtains multiple local caches established at the same time in a certain application node, sets a different cache period for each local cache through the hash value and preset time period of each local cache, and a predetermined setting method, and updates the local cache after the local cache expires. Applying the above method, multiple local caches established at the same time or expired at the same time in the same application node can have different cache periods and subsequently expire at different times. This solves the problem that the database receives a large number of access requests at the same time, resulting in slow access, crashes, and unstable services.
[0056] The above-mentioned embodiment of the invention is aimed at an application node establishing multiple local caches at the same timestamp, setting a corresponding cache period for each local cache, and avoiding the simultaneous invalidation of multiple local caches, that is, preventing multiple local caches from being invalidated at the same time in advance when multiple local caches are established. However, if multiple local caches have been established in the target application node, and these multiple local caches will be invalidated at the same time, if the cache periods of these multiple local caches are the same, then they will continue to be invalidated at the same time. In order to avoid this situation, when these multiple local caches are invalid, the cache period of each local cache can be updated to make the cache period of each local cache different. For details, please refer to Figure 3 , Figure 3 Another flow chart of an application node cache update method provided by an embodiment of the present invention. Figure 3 As shown, the method of the embodiment of the present invention may include the following steps:
[0057] S301, the target application node determines K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer;
[0058] S302, the target application node sends the Nth i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer.
[0059] In the embodiment of the present invention, first, the target application node needs to determine K local caches, which are all invalidated at the first timestamp and have the same cache period T. Then, in the next cache period, these K local caches will continue to be invalidated at the same time. Therefore, when each local cache is invalidated at the first timestamp, the cache period of each local cache needs to be updated and set, so that the cache period of each local cache is different, so that all local caches will not be invalidated at the same time in the next cache period.
[0060] Specifically, the target application node sends the Nth i The cache cycle update of the local cache is set to Ti , where 1≤i≤K, and i is an integer. If i=1, it is the N1th local cache, which can be understood as the first local cache among the K local caches established by the target application node, and the corresponding cache period T1 is set. The specific steps include:
[0061] S302.1, the target application node is based on the formula T i =hash(key i )%(T / 2)+(T / 2) calculates the cache period T i , where hash(key i ) is the Nth i The hash value of the local cache, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and taking the remainder;
[0062] S302.2, the Nth i The cache period of the local cache is set to T i .
[0063] Optionally, set the Nth i The cache period of the local cache is T i When you first need to obtain the Nth i The cache period of the local cache is T i . Cache period T i It can be obtained through the following formula:
[0064] T i =hash(key i )%(T / 2)+(T / 2) (3)
[0065] In the above formula, hash(key i ) is the Nth i The hash value of the local cache, T is N i The original cache cycle of the local cache, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and take the remainder.
[0066] Calculate the Nth i The cache period of the local cache is T i After that, the target application node can i The cache cycle update of the local cache is set to T i .
[0067] Based on any of the above optional embodiments, S303, the target application node updates the Nth i Local cache, get the new Nthi Local cache.
[0068] In the embodiment of the present invention, the Nth i After the local cache timestamp expires, the target application node needs to update the Nth i Local cache, get the new Nth i Local cache.
[0069] In an optional embodiment, the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0070] In the embodiment of the present invention, the target application node may be at the first timestamp, that is, the Nth i When the local cache fails, update the Nth i Local cache, get the new Nth i Local cache. For example, the Nth i The local cache expires in 100 seconds, and the target application node immediately updates the Nth i Local cache, get the new Nth i Local cache. If the Nth i The cache period of the local cache is 60, so the Nth i After the local cache expires in 160 seconds, the target application node will re-update the Nth i Local cache, performs the same operation in each cache cycle.
[0071] In another optional embodiment, if the target application node receives the Nth i The local cache usage request updates the Nth i Local cache, get the new Nth i Local cache; the second timestamp is located after the first timestamp.
[0072] In the embodiment of the present invention, the target application node may be at the Nth i When the local cache fails, the Nth i Local cache, get the new Nth i Local cache. So after the first timestamp, the Nth i The local cache is invalid. If a user terminal requests the Nth i If the local cache is used, the corresponding Nth i Local cache requires the target application node to re-update the corresponding Nth i Local cache.
[0073] Therefore, if the target application node receives the Nth i If the local cache is used, the Nth i Local cache, get the new Nth i Local cache; wherein the second timestamp is located at After the timestamp. For example, the Nth i The local cache expires in 50 seconds, and the target application node does not update the Nth i Local cache. In 100 seconds, the target application node receives the Nth message sent by the user terminal. i When the local cache is used, the Nth i Local cache, get the new Nth i Local cache.
[0074] In summary, an embodiment of the present invention provides an application node cache update method, which obtains multiple local caches that are invalidated at the same time in a certain application node, sets a different cache period for each local cache through the hash value of each local cache and the original cache period of the local cache, and a predetermined setting method, and updates the local cache after the local cache is invalidated. Applying the above method, multiple local caches that are established or invalidated at the same time in the same application node can have different cache periods and subsequently expire at different times. This solves the problem that the database receives a large number of access requests at the same time, resulting in slow access, crashes, and unstable services.
[0075] The following are embodiments of the device of the present invention, which can be used to implement the method embodiments of the present invention. For details not disclosed in the device embodiments of the present invention, please refer to the method embodiments of the present invention.
[0076] See also Figure 4 , is a structural diagram of an application node cache update device provided in an embodiment of the present invention.
[0077] The application node cache updating device 400 in the embodiment of the present invention includes: a local cache establishing module 401 , a cache period setting module 402 and a local cache updating module 403 .
[0078] A local cache establishment module is used for the target application node to establish K local caches at the first timestamp T1; K>0, and K is an integer;
[0079] The cache cycle setting module is used for the target application node to set the cache cycle according to the Nth i Local cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer;
[0080] The local cache update module is used when the Nth i Local cache in T Ni After the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0081] It should be noted that the application node cache update device provided in the above embodiment only uses the division of the above functional modules as an example when executing the application node cache update method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the application node cache update device provided in the above embodiment belongs to the same concept as the application node cache update method embodiment. Therefore, for details not disclosed in the embodiment of the device of the present invention, please refer to the embodiment of the application node cache update method of the present invention, which will not be repeated here.
[0082] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0083] See also Figure 5 , is a structural diagram of another application node cache update device provided in an embodiment of the present invention.
[0084] The application node cache updating device 500 in the embodiment of the present invention includes: a local cache determining module 501 , a cache period setting module 502 and a local cache updating module 503 .
[0085] A local cache establishment module is used for the target application node to determine K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer;
[0086] The cache cycle setting module is used for the target application node to store the Nth i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer;
[0087] A local cache update module is used for the target application node to update the Nth i Local cache, get the new Nth i Local cache.
[0088] It should be noted that the application node cache update device provided in the above embodiment only uses the division of the above functional modules as an example when executing the application node cache update method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the application node cache update device provided in the above embodiment belongs to the same concept as the application node cache update method embodiment. Therefore, for details not disclosed in the embodiment of the device of the present invention, please refer to the embodiment of the application node cache update method of the present invention, which will not be repeated here.
[0089] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0090] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of the method of any of the above embodiments are implemented. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), or any type of medium or device suitable for storing instructions and / or data.
[0091] An embodiment of the present invention further provides a terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above-mentioned method embodiments when executing the program.
[0092] Figure 6 A block diagram of a terminal provided by an embodiment of the present invention. Figure 6 , an embodiment of the present invention provides a terminal 600, including: a processor (processor) 601, a communication interface (Communications Interface) 602, a memory (memory) 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604. The processor 601 can call the logic instructions in the memory 603 to execute the following method, including: the target application node establishes K local caches at the first timestamp T1; K>0, and K is an integer; the target application node establishes K local caches according to the Nth i Local cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer; when the Nth i Local cache in T NiAfter the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0093] Or execute the following method, including: the target application node determines K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer; the target application node sends the Nth local cache at the first timestamp i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer; the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0094] The terminal structure block diagram shown in the embodiment of the present invention does not constitute a limitation on the terminal 600. The terminal 600 may include more or fewer components than those shown in the figure, or combine certain components, or adopt a different component arrangement.
[0095] The embodiment of the present invention discloses a computer program product, the computer program product includes a computer program stored on a non-transitory computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: the target application node establishes K local caches at a first timestamp T1; K>0, and K is an integer; the target application node establishes K local caches according to the Nth i Local cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer; when the Nth i Local cache in T Ni After the timestamp expires, the target application node updates the Nth i Local cache, get the new Nth i Local cache. Or including: the target application node determines K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer; the target application node sends the Nth local cache at the first timestamp i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer; the target application node updates the Nth i Local cache, get the new Nth i Local cache.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for updating application node cache, characterized in that: include: The target application node establishes K local caches at the first timestamp T1; K>0, and K is an integer; The target application node is based on the Nth i Local cache, set the Nth i The cache period of the local cache is T i ; Wherein, 1≤i≤K, and i is an integer; When the Ni-th local cache is in After the timestamp expires, the target application node updates the Ni-th local cache to obtain a new Ni-th local cache.
2. The method according to claim 1, characterized in that: The target application node is based on the Nth i Local cache, set the Nth i The cache period of the local cache is T i ,include: The target application node is based on the formula T i =hash(key i )%(T / 2)+(T / 2) calculates the cache period T i , where hash(key i ) is the Nth i The hash value of the local cache, T is the preset time period, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and taking the remainder; The Nth i The cache period of the local cache is set to T i .
3. The method according to claim 2, characterized in that: The said The timestamp is obtained as follows: in, For the said Timestamp, T1 is the first timestamp.
4. The method according to any one of claims 1 to 3, characterized in that: The target application node updates the Ni-th local cache to obtain a new Ni-th local cache, including: The target application node is in the The timestamp updates the Ni-th local cache to obtain a new Ni-th local cache.
5. The method according to any one of claims 1 to 3, characterized in that: The target application node updates the Ni-th local cache to obtain a new Ni-th local cache, including: If the target application node is in When receiving a request to use the Ni-th local cache, the Ni-th local cache is updated to obtain a new Ni-th local cache; The timestamp is located at the After the timestamp.
6. A method for updating application node cache, characterized in that: include: The target application node determines K local caches; the K local caches are all invalidated at the first timestamp and have the same cache period T; K>0, and K is an integer; The target application node sends the Nth i The cache cycle update of the local cache is set to T i ; Wherein, 1≤i≤K, and i is an integer; The target application node updates the Nth i Local cache, get the new Nth i Local cache.
7. The method according to claim 6, characterized in that: The target application node sends the Nth i The cache cycle update of the local cache is set to T i ,include: The target application node is based on the formula T i =hash(key i )%(T / 2)+(T / 2) calculates the cache period T i , where hash(key i ) is the hash value of the Ni-th local cache, hash(key i )%(T / 2) is hash(key i ) divided by (T / 2) and taking the remainder; The Nth i The cache period of the local cache is set to T i .
8. The method according to claim 6 or 7, characterized in that: The target application node updates the Nth i Local cache, get the new Nth i Local cache, including: The target application node updates the Nth i Local cache, get the new Nth i local cache; or If the target application node receives the Nth i The local cache usage request updates the Nth i Local cache, get the new Nth i Local cache; the second timestamp is located after the first timestamp.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 or the method according to any one of claims 6 to 8 is implemented.
10. A terminal comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 5 or the method according to any one of claims 6 to 8 is implemented.
