Cache renewal method and system, electronic equipment, storage medium and program product
By implementing the asynchronous cache duration mechanism between the server and the client, the load pressure problem of the data layer after cached data expires is solved, and the stability and efficiency of the system are improved.
Patent Information
- Application Number
- CN202510283702.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-11
- Publication Date
- 2025-06-24
AI Technical Summary
In scenarios with high traffic concurrency, the cached data naturally expires and re-requests the data layer to obtain data, resulting in a large load pressure on the data layer.
The cache renewal is achieved through the asynchronous method of the server and the client. The client sends the expired cached data to the server, and the server decides whether to renew and performs renewal processing to avoid the client frequently requesting the data layer.
It effectively reduces the load pressure on the data layer in scenarios where a large number of caches expire, and improves the stability and efficiency of cache refresh.
Smart Images

Figure CN120196657A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data processing, and in particular, to a cache renewal method, system, electronic device, storage medium, and program product. Background Art
[0002] Currently, when using cache technology for data reading, generally, the data obtained from the database is stored in the cache, and a physical time for cache expiration is set. When a request arrives, if the required data is in the cache, the cached data is returned; if there is no data in the cache (no data has been cached or the cached data has expired), the source database is accessed.
[0003] Since the physical time for cache expiration is set relatively short, the cold data stored in the cache is relatively easy to expire, so there is a need to renew the cache. The cache renewal problem will introduce the problem of cache refreshing. In current software systems, the problem of cache data renewal is basically achieved through lazy loading, that is, when the cache data naturally expires, the data in the data layer is downloaded again through a request to complete cache renewal and data update. In a high-traffic and high-concurrency scenario, it is very likely that multiple requests will penetrate to the data layer, causing a relatively large load pressure on the data layer. Summary of the Invention
[0004] The purpose of the embodiments of the present application is to provide a cache renewal method, system, electronic device, storage medium, and program product, so as to improve the problem that the existing method causes a relatively large load pressure on the data layer when re-requesting data from the data layer after the cache data naturally expires.
[0005] In a first aspect, the embodiments of the present application provide a cache renewal method, which is applied to a server. The method includes:
[0006] Receiving the near-expired cache data sent by the client;
[0007] When it is determined that the near-expired cache data needs to be renewed, performing a renewal process on the near-expired cache data.
[0008] In the above implementation process, the client sends the cache data that is about to expire as near-expired cache data to the server, and the server determines whether the near-expired cache data needs to be renewed. If it needs to be renewed, the renewal process is performed on the near-expired cache data. In this way, it is not necessary for the client to re-request the data from the data layer to complete cache renewal after the cache naturally expires. This solution realizes cache renewal through the asynchronous method of the server and the client, and can effectively reduce the load pressure on the data layer in the scenario of a large number of cache expirations.
[0009] Optionally, the performing a renewal process on the near-expired cache data includes:
[0010] Obtain the cache key data corresponding to the approaching expiration cache data;
[0011] Send the cache key data to the client;
[0012] Obtain the latest cache data found by the client according to the cache key data;
[0013] Store the latest cache data in the cache to realize the renewal process of the approaching expiration cache data.
[0014] In the above implementation process, after the server obtains the cache key data, it sends it to the client. The client finds the latest cache data and returns it to the server, and the server performs cache refresh. In this way, the client does not need to perform cache refresh by itself, and the server can asynchronously implement cache refresh without affecting the normal business of the client, improving the stability of cache refresh.
[0015] Optionally, determine whether the approaching expiration cache data needs to be renewed in the following way:
[0016] Determine the cache configuration data corresponding to the cache key data according to the cache key data. The cache configuration data includes the cache expiration time and the renewal information indicating whether renewal is required;
[0017] If the cache configuration data includes the renewal information indicating that renewal is required and the remaining valid time of the cache expiration time is less than the set threshold, it is determined that the cache data needs to be renewed.
[0018] In the above implementation process, the server can quickly determine whether the cache data needs to be renewed according to the cache configuration data corresponding to each cache key data. In this way, the client does not need to care about the renewal problem of the cache data, and the server solves it asynchronously, which can reduce the data layer load pressure caused by cache renewal.
[0019] Optionally, the cache configuration data further includes a renewal method. The sending the cache key data to the client includes:
[0020] In the case where the renewal method is to renew by obtaining the cache data returned by the client, the cache key data is sent to the client;
[0021] In the case where the renewal method is to renew using the original cache data, the method further includes:
[0022] Re-store the approaching expiration cache data in the cache to realize the renewal process of the approaching expiration cache data.
[0023] In the above implementation process, the corresponding cache renewal method can be customized according to actual needs, with higher flexibility.
[0024] Optionally, the obtaining of the latest cache data found by the client according to the cache key data includes:
[0025] Calling a hook function to obtain the latest cache data, where the hook function is used to hook a target function, and the target function is used to instruct the client to find the latest cache data according to the cache key data.
[0026] In the above implementation process, the use of the hook function can decouple the logic of obtaining cache data from the main business logic. The main program does not need to directly call or know the specific cache search logic, and only needs to trigger the hook function at the appropriate time, with higher flexibility.
[0027] Optionally, after sending the cache key data to the client, it further includes:
[0028] If the latest cache data returned by the client is not obtained;
[0029] Then the near-expired cache data is redeposited into the cache to implement the renewal process of the near-expired cache data.
[0030] In the above implementation process, if the server fails to obtain the latest cache data returned by the client, the cache is refreshed according to the original logic, which can also implement the renewal of cache data and ensure that the business is stable and not affected by cache expiration.
[0031] In a second aspect, an embodiment of the present application provides a cache renewal method applied to a client, and the method includes:
[0032] Receiving a user data request;
[0033] Finding the corresponding cache data from the cache according to the user data request;
[0034] When it is determined that the cache data is about to expire, sending the cache data to the server, where the server is used to perform a renewal process on the cache data when it is determined that the cache data needs to be renewed.
[0035] In the above implementation process, the client triggers the cache expiration judgment based on the request, reducing the number of frequent judgments by the client, thereby reducing the load on the client, and the server is used to implement asynchronous cache renewal, which can effectively reduce the load pressure on the data layer in the scenario of a large number of cache expirations.
[0036] In a third aspect, an embodiment of the present application provides a cache renewal system, and the system includes:
[0037] A client, configured to receive a user data request and find corresponding cached data from a cache according to the user data request;
[0038] The client is further configured to send the cached data to a server when it is determined that the cached data is about to expire;
[0039] The server is configured to renew the cached data when it is determined that the cached data needs to be renewed.
[0040] In a fourth aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, where the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method provided in the first aspect or the second aspect above are run.
[0041] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the method provided in the first aspect or the second aspect above are run.
[0042] In a sixth aspect, an embodiment of the present application provides a computer program product, including computer program instructions, and when the computer program instructions are read and run by a processor, the steps in the method provided in the first aspect or the second aspect above are executed.
[0043] Other features and advantages of the present application will be described in the subsequent specification, and some of them will become obvious from the specification, or can be understood by implementing the embodiments of the present application. The objectives and other advantages of the present application can be achieved and obtained through the structures specifically pointed out in the written specification, claims, and drawings. Description of the Drawings
[0044] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and thus should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0045] Figure 1 It is a flowchart of a cache renewal method provided by an embodiment of the present application;
[0046] Figure 2 It is an interaction diagram of each module in a client and a server provided by an embodiment of the present application;
[0047] Figure 3A flowchart of a server implementing cache update through hook functions provided by an embodiment of the present application;
[0048] Figure 4 A flowchart of another cache renewal method provided by an embodiment of the present application;
[0049] Figure 5 A structural block diagram of a cache renewal device provided by an embodiment of the present application;
[0050] Figure 6 A structural block diagram of another cache renewal device provided by an embodiment of the present application;
[0051] Figure 7 A schematic structural diagram of an electronic device for executing a cache renewal method provided by an embodiment of the present application. Detailed implementation manners
[0052] Next, the technical solutions in the embodiments of the present application will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present application.
[0053] It should be noted that the terms "system" and "network" in the embodiments of the present invention can be used interchangeably. "A plurality of" means two or more. In view of this, "a plurality of" in the embodiments of the present invention can also be understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " generally represents an "or" relationship between the associated objects before and after without special instructions.
[0054] It should also be noted that all actions of obtaining signals, information, or data in the present application are carried out on the premise of complying with the corresponding data protection regulations and policies of the country where it is located and obtaining the authorization given by the owner of the corresponding device.
[0055] An embodiment of the present application provides a cache renewal method. In this method, the client sends the cache data that is about to expire as near-term cache data to the server, and the server determines whether the near-term cache data needs to be renewed. If it needs to be renewed, the near-term cache data is renewed. In this way, it is not necessary for the client to re-request the data from the data layer after the cache naturally expires to complete the cache renewal. This solution realizes cache renewal through the asynchronous method of the server and the client, which can effectively reduce the load pressure on the data layer in the scenario where a large number of caches expire.
[0056] Please refer to Figure 1 , Figure 1 A flowchart of a cache renewal method provided by an embodiment of the present application. This method is applied to the server and includes the following steps:
[0057] Step S110: Receive the near-expiration cache data sent by the client.
[0058] In some embodiments, the client can detect the expiration of the data in the cache in real time or at regular intervals. If it detects that some cache data is about to expire, it can send the near-expiration cache data to the server. That is, the near-expiration cache data refers to some cache data that is about to expire.
[0059] In some other embodiments, the client can receive a user data request, find the corresponding cache data from the cache according to the user data request, and then detect whether the cache data is about to expire, that is, trigger the detection of cache expiration based on the request. In this way, the client does not need to frequently judge the expiration of each cache data, which can effectively reduce the load of the client.
[0060] The client can judge whether the cache data is about to expire according to the cache expiration time of the cache data. For example, when the data is stored in the cache, the cache expiration time of the data will be refreshed at the same time, such as one hour or one day. Each data in the cache can be configured with the corresponding cache expiration time. In this way, the client can determine whether the data has expired according to the cache expiration time. For example, the client can determine the near-expiration cache data as the data whose remaining cache expiration time is less than the set threshold. For example, when the remaining cache expiration time of a certain data is less than 3 minutes (if the set threshold is 3 minutes), it is determined that the data is about to expire, and then the data is sent to the server.
[0061] In some embodiments, if different data is set with different cache expiration times, the corresponding set thresholds can also be different. For example, for general business data, which is updated relatively fast and may have a shorter cache expiration time, such as one hour, the corresponding set threshold can be larger, such as 5 minutes, that is, these data need to be refreshed as soon as possible to avoid affecting the business processing after expiration. For some data that is not updated frequently, its cache expiration time may be longer, such as one day, and the corresponding set threshold can be smaller, such as 3 minutes. Of course, in specific applications, it can be flexibly set according to the actual situation.
[0062] Step S120: If it is determined that the near-expiration cache data needs to be renewed, perform renewal processing on the near-expiration cache data.
[0063] Since not all data needs to be renewed, some data will expire and not be renewed after the cache expiration time. Therefore, after the server receives the approaching-expiration cache data, it still needs to determine whether the received approaching-expiration cache data needs to be renewed. In the case where renewal is required, the server performs the renewal process on the approaching-expiration cache data. In this way, the server performs cache refreshing, that is, cache renewal, without the need for the client to execute, which does not affect the normal business processing of the client, thus realizing the asynchronous processing of cache renewal.
[0064] In the above implementation process, the client sends the cache data that is about to expire as approaching-expiration cache data to the server. The server determines whether the approaching-expiration cache data needs to be renewed. If renewal is required, the server performs the renewal process on the approaching-expiration cache data. In this way, there is no need for the client to re-request the data from the data layer after the cache naturally expires to complete cache renewal. This solution realizes cache renewal in an asynchronous manner between the server and the client, which can effectively reduce the load pressure on the data layer in scenarios where a large number of caches expire.
[0065] Based on the above embodiments, it is possible that when the server is processing the renewal of cache data, the cache data at the front end is updated. In order to obtain the latest cache data for update, the server can obtain the cache key data corresponding to the approaching-expiration cache data, and then send the cache key data to the client. The client then locates the latest cache data according to the cache key data, and then sends the latest cache data to the server. After the server obtains the latest cache data, it stores the latest cache data in the cache to implement the renewal process for the approaching-expiration cache data.
[0066] In some embodiments, to facilitate the server to perform cache renewal processing, in the server, it can be divided into a working node module and an event listener module according to the data processing flow. The working node module can be used to receive the approaching-expiration cache data sent by the client. For example, the client can push the approaching-expiration cache data to the working node module through a long connection. After the working node module obtains the approaching-expiration cache data, it determines whether the approaching-expiration cache data needs to be renewed. If renewal is required, it obtains the cache key data corresponding to the approaching-expiration cache data, and then the working node module can also send the cache key data to the event listener module through a long connection for corresponding processing.
[0067] Among them, the interaction between the client, the working node module, and the event listener module is as Figure 2As shown in the figure, the client can provide functions such as cache data push, C-side scenario usage, cache data reading, cache data writing, cache framework introduction, and custom events. Here, the custom event means that the client supports custom functions to implement the cache renewal logic. The working node module can judge whether the cache data needs to be renewed, and then send the cache key data that needs to be renewed to the event listener module through a long connection. The working node module can provide functions such as long connection reception, renewal rule verification, renewal event distribution, and unified push. The event listener module can provide functions such as cache renewal interception, cache data update, exception logic fallback, plug-in expansion, event exception fallback, and custom events. Here, the custom event and the fallback method support the business side to expand and implement relevant logic by itself.
[0068] The above cache key data can be understood as the identifier of the cache data. When the cache data is stored, it is stored in the key-value format. The key is the identifier, and the value is the specific cache data. The cache key data can refer to user identification, commodity identification, etc. It can be the hash value of the cache data, etc., and has uniqueness.
[0069] Therefore, after the working node module obtains the near-expired cache data, it can obtain the cache key data through hashing. Or if the near-expired cache data pushed by the client includes the cache key data, the working node module can directly obtain the cache key data from the near-expired cache data. Then the working node module sends the cache key data to the event listener module. The event listener module then sends the cache key data to the client. After receiving the cache key data, the client can find the cache data corresponding to the cache key data according to its own data search logic, such as searching in the database, etc. The found cache data can be used as the latest cache data. The latest cache data is sent to the event listener module, and the event listener module then stores the latest cache data in the cache, that is, realizes the refresh and renewal of the near-expired cache data. At this time, the cache expiration time of the original near-expired cache data becomes the cache expiration time of the latest cache data, thus realizing the renewal of the near-expired cache data.
[0070] In the above implementation process, the server obtains the cache key data and sends it to the client. After the client finds the latest cache data, it returns it to the server, and the server performs cache refresh. In this way, the client does not need to perform cache refresh by itself, and the server can asynchronously implement cache refresh without affecting the normal business of the client, improving the stability of cache refresh.
[0071] On the basis of the above embodiment, after the working node module obtains the near-expired cache data, it can verify whether the near-expired cache data needs to be renewed according to the set rules.
[0072] The setting rules can be pre-configured according to the actual situation, including the matching of some data, so as to determine whether the near-expiry cache data needs to be renewed. Specifically, the cache configuration data corresponding to the cache key data can be determined according to the cache key data. The cache configuration data includes the cache expiration time and the renewal information indicating whether renewal is required. If the cache configuration data includes the renewal information indicating that renewal is required and the remaining valid time of the cache expiration time is less than the set threshold, it is determined that the cache data needs to be renewed.
[0073] Understandably, the corresponding cache configuration data can be pre-configured for each cache key data in the server according to the requirements. The cache configuration data includes the cache expiration time and the renewal information indicating whether renewal is required. In this way, the worker node module can find the corresponding cache configuration data according to the cache key data and determine the specific configuration of the cache key data.
[0074] The worker node module can judge whether the cache data is about to expire according to the cache expiration time. For example, whether the remaining valid time of the cache expiration time is less than the set threshold. If it is less, it is considered that the cache data is indeed about to expire. If the renewal information configured for the cache data includes the need for renewal, it is determined that the cache data needs to be renewed. After the judgment, the cache key data can be sent to the event listener module.
[0075] In some embodiments, the renewal information may include a renewal flag. For example, a renewal flag of 1 indicates the need for renewal, and a renewal flag of 0 indicates no need for renewal. In this way, it can be quickly judged whether the cache data needs to be renewed according to the renewal flag. In specific applications, the renewal information can be flexibly defined so that it can represent whether renewal is required.
[0076] In some embodiments, the worker node module may receive a large number of cache data to expire pushed by clients. Therefore, after the above judgment, the worker node module can uniformly push the cache key data determined to need renewal to the event listener module. Here, the worker node module can push the cache key data that needs renewal to the event listener module in real time or at regular intervals.
[0077] In order to facilitate the identification of the cache data of different clients, the client can also carry the client identifier when sending the cache data. When the worker node module sends the cache key data to the event listener module, it will also carry the client identifier corresponding to the cache key data, so that the subsequent event listener module can send the cache key data to the corresponding client.
[0078] In some other embodiments, when the server determines whether the near-expiration cached data needs to be renewed, the server can also make the determination based on the specific data-related information of the near-expiration cached data. For example, it can determine whether to renew according to the data type of the near-expiration cached data. The data type can be divided into hot data and cold data. Hot data refers to some data with a relatively high access rate, and cold data refers to some data with a relatively low access rate. For data of the hot data type, it is determined that renewal is needed, and for data of the cold data type, it is determined that renewal is not needed.
[0079] Here, the specific data type of the near-expiration cached data can be determined according to the specific data content of the near-expiration cached data. Different data types corresponding to different data contents can be predefined in advance, so that quick determination can be achieved. Or the near-expiration cached data can also be input into a machine learning model, and the machine learning model is used to predict whether the near-expiration cached data needs to be renewed. Specifically, the machine learning model can be obtained by being pre-trained with a large amount of cached data. During the training process, the machine learning model can learn the rules between different cached data and whether to renew. Thus, the trained machine learning model can accurately determine whether the near-expiration cached data needs to be renewed.
[0080] In the above implementation process, the server can quickly determine whether the cached data needs to be renewed according to the cache configuration data corresponding to each cache key data. In this way, the client does not need to care about the renewal problem of the cached data, and the server solves it asynchronously, which can reduce the data layer load pressure caused by cache renewal.
[0081] Based on the above embodiments, the cache configuration data can also include a renewal method. Before the event listener module sends the cache key data to the client, it can first determine the renewal method of the cached data. In the case where the renewal method is to renew by obtaining the cached data returned by the client, the cache key data is sent to the client. However, in the case where the renewal method is to renew using the original cached data, the near-expiration cached data can be re-stored in the cache to implement the renewal process of the near-expiration cached data.
[0082] Different cache key data can be configured with corresponding renewal methods, and the renewal methods can be different. For example, the renewal methods include renewing by obtaining the cached data returned by the client and renewing by obtaining the original cached data, etc. In this way, the event listener can perform different processes according to the renewal method.
[0083] If the renewal method is to obtain the original cached data for renewal, the event listener may not send the cache key data to the client at this time. Instead, it directly obtains the near-expiration cached data pushed by the client and reinserts the near-expiration cached data into the cache. This is also equivalent to refreshing the near-expiration cached data, and the refreshed near-expiration cached data also synchronously updates the cache expiration time, thus realizing the renewal of the near-expiration cached data.
[0084] In some embodiments, the cache configuration data corresponding to each cache key data may support dynamic editing and modification, so that the custom cache renewal method and cache expiration time can be adjusted according to the actual application scenario.
[0085] In the above implementation process, the corresponding cache renewal method can be customized according to actual needs, with higher flexibility.
[0086] Based on the above embodiments, in the method for the event listener module to obtain the latest cached data returned by the client, a hook function can be called to obtain the latest cached data. The hook function can be used to hook the target function, and the target function is used to instruct the client to find the latest cached data according to the cache key data.
[0087] Among them, the hook function is essentially a program for processing system messages. It is executed by system calls and hung into the system. It can be inserted into the function outside the normal program during normal program operation according to settings. Usually, the conditions for setting the hook function need to be set, and the hook function will be called under these conditions. In this solution, the condition for the hook function is that when the renewal method is to renew the cached data returned by the client, the hook function is called to obtain the cached data returned by the client.
[0088] When the hook function hooks the target function, the target function is executed, and then the latest cached data of the client is obtained.
[0089] It can be understood that if the client does not implement the target function, the latest cached data returned by the client cannot be obtained. At this time, the method for renewing the near-expiration cached data is to directly reinsert the near-expiration cached data into the cache. If the client implements the target function, the target function is executed to obtain the latest cached data.
[0090] In some embodiments, different clients may correspond to different target functions. For example, the database types of different clients are different, so when obtaining the latest cached data, the function names used, the languages used for function writing, and the number of related parameters are all different, so the implemented target functions may also be different.
[0091] In this case, the server can determine the corresponding target function according to the client's identifier, and then hook the target function corresponding to the client through the hook function, so as to execute the operations corresponding to the target function.
[0092] Then, the latest cached data can be returned as the return parameter of the hook function, so that the server can obtain the latest cached data.
[0093] The execution process of the event listener module can be as Figure 3 shown. After receiving the cache key data, the event listener module checks whether the hook function is implemented. If it is implemented, it calls the business interface to obtain the latest cached data, creates a ValueModel based on the latest cached data, and then adds it to the local cache to achieve cache refresh. If the hook function is not implemented, a ValueModel with an empty Value is created and then added to the local cache, that is, the original expired cached data is redeposited into the cache to achieve cache refresh, that is, to refresh the cached data and the cache expiration time again.
[0094] In the above implementation process, the use of the hook function can decouple the logic of obtaining cached data from the main business logic. The main program does not need to directly call or know the specific cache lookup logic, and only needs to trigger the hook function at the appropriate time, which is more flexible.
[0095] Based on the above embodiments, after the event listener module sends the cache key data to the client, if the latest cached data returned by the client is not obtained, the expired cached data is redeposited into the cache to achieve the renewal process of the expired cached data.
[0096] In this implementation method, the event listener module does not need to care whether the client has implemented the target function, and directly sends the cache key data to the client. If the client has not implemented the target function, the event listener module cannot obtain the latest cached data returned by the client, or the returned data is empty, or even if the client has implemented the target function, but due to abnormal conditions, the returned data is empty or no data is returned, the event listener module can implement cache renewal according to the original logic, that is, redeposit the original expired cached data into the cache to achieve cache refresh, and then achieve cache renewal, so as to ensure business stability and reduce the impact.
[0097] That is to say, the event listener module will perform exception handling and business processing. For the case where the client returns an empty value or an abnormal situation, the original logic can be defaulted, that is, the original cached data is deposited into the cache to achieve cache refresh, so as to ensure business stability.
[0098] In the above implementation process, if the server fails to obtain the latest cached data returned by the client, the cache is refreshed according to the original logic, which can also achieve the renewal of the cached data and ensure the stability of the service without being affected by cache expiration.
[0099] Based on the above embodiments, the present solution provides a new cache renewal method, which asynchronously refreshes the cache data that is about to expire. Compared with the traditional method of reloading according to the natural expiration based on traffic conditions, it is smoother and more stable, reducing the problem of cache penetration. Moreover, the present solution introduces a three-layer design, including a client, a worker node module, and an event listener module. The three modules coordinate and work with each other, ensuring clear overall data processing, reducing the coupling of modules, and increasing the convenience and scalability of use.
[0100] Combined with the above embodiments, as Figure 4 shown, the embodiment of the present application also provides a flowchart of another cache renewal method, which is applied to the client and includes the following steps:
[0101] Step S210: Receive a user data request.
[0102] Step S220: Search for the corresponding cached data in the cache according to the user data request.
[0103] Step S230: When it is determined that the cached data is about to expire, send the cached data to the server.
[0104] Among them, when it is determined that the cached data is about to expire, the client can send the about-to-expire cached data to the server as the near-expiration cached data. The cached data sent by the client to the server is called the near-expiration cached data in the above embodiments, and the server is used to renew the cached data when it is determined that the cached data needs to be renewed.
[0105] In this embodiment, the client can trigger the cache expiration judgment based on the request, reducing the number of frequent judgments by the client, thereby reducing the load of the client, and the server is used to implement asynchronous cache renewal, which can effectively reduce the load pressure on the data layer in the scenario of a large number of cache expirations.
[0106] It can be understood that those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working process of this embodiment can refer to the corresponding process in the foregoing method embodiment and will not be repeated here.
[0107] Combined with the above method embodiments, the embodiment of the present application provides a cache renewal system, which includes a client and a server.
[0108] Among them, the client is used to receive user data requests and find corresponding cached data from the cache according to the user data requests;
[0109] The client is further used to send the cached data to the server when it is determined that the cached data is about to expire;
[0110] The server is used to renew the cached data when it is determined that the cached data needs to be renewed.
[0111] It can be understood that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of this system embodiment can refer to the corresponding process in the foregoing method embodiment, and will not be repeated here.
[0112] Please refer to Figure 5 , Figure 5 FIG. is a structural block diagram of a cache renewal device provided by an embodiment of the present application. This device can be a module, program segment or code on an electronic device (such as a server). It should be understood that this device corresponds to the above Figure 1 method embodiment and can execute Figure 1 each step involved in the method embodiment. The specific functions of this device can be seen in the foregoing description. To avoid repetition, the detailed description is appropriately omitted here.
[0113] Optionally, the device 300 includes:
[0114] A data receiving module 310, configured to receive the near-expired cached data sent by the client;
[0115] A cache processing module 320, configured to renew the near-expired cached data when it is determined that the near-expired cached data needs to be renewed.
[0116] Optionally, the cache processing module 320 is configured to obtain the cache key data corresponding to the near-expired cached data; send the cache key data to the client; obtain the latest cached data found by the client according to the cache key data; and store the latest cached data in the cache to implement the renewal processing of the near-expired cached data.
[0117] Optionally, the cache processing module 320 is configured to determine the cache configuration data corresponding to the cache key data according to the cache key data. The cache configuration data includes the cache expiration time and renewal information indicating whether renewal is required; if the cache configuration data includes renewal information indicating that renewal is required and the remaining valid time of the cache expiration time is less than a set threshold, it is determined that the cached data needs to be renewed.
[0118] Optionally, the cache configuration data further includes a renewal method. The cache processing module 320 is configured to, when the renewal method is to renew the cache by obtaining the cache data returned by the client, send the cache key data to the client; when the renewal method is to renew the cache by using the original cache data, re-store the near-expired cache data into the cache to implement the renewal process for the near-expired cache data.
[0119] Optionally, the cache processing module 320 is configured to call a hook function to obtain the latest cache data. The hook function is used to hook a target function, and the target function is used to instruct the client to find the latest cache data according to the cache key data.
[0120] Optionally, the cache processing module 320 is further configured to, if the latest cache data returned by the client is not obtained, re-store the near-expired cache data into the cache to implement the renewal process for the near-expired cache data.
[0121] Please refer to Figure 6 , Figure 6 FIG. [0000263], which is a structural block diagram of another cache renewal device provided by an embodiment of the present application. The device may be a module, a program segment, or code on an electronic device (such as a client). It should be understood that the device corresponds to the above Figure 4 method embodiment and can execute Figure 4 each step involved in the method embodiment. The specific functions of the device can be seen in the above description. To avoid repetition, the detailed description is appropriately omitted here.
[0122] Optionally, the device 400 includes:
[0123] A request receiving module 410, configured to receive a user data request;
[0124] A data searching module 420, configured to search for corresponding cache data from the cache according to the user data request;
[0125] A data sending module 430, configured to send the cache data to the server when it is determined that the cache data is about to expire. The server is configured to renew the cache data when it is determined that the cache data needs to be renewed.
[0126] It should be noted that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described systems and devices can refer to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0127] Please refer to Figure 7 , Figure 7Schematic diagram of a structure of an electronic device for implementing a cache renewal method provided by an embodiment of the present application. The electronic device may be a client or a server. The electronic device may include: at least one processor 510, such as a CPU, at least one communication interface 520, at least one memory 530, and at least one communication bus 540. Among them, the communication bus 540 is used to implement connection communication between these components. Among them, the communication interface 520 of the device in the embodiment of the present application is used to communicate signaling or data with other node devices. The memory 530 may be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. Optionally, the memory 530 may also be at least one storage device located far from the aforementioned processor. Computer-readable instructions are stored in the memory 530. When the computer-readable instructions are executed by the processor 510, the electronic device executes the implementation process of the above-mentioned cache renewal method.
[0128] It can be understood that Figure 7 The structure shown is only schematic. The electronic device may further include more or fewer components than those shown in Figure 7 or have a different configuration from that shown in Figure 7 The components shown can be implemented by hardware, software, or a combination thereof. Figure 7 Each component shown in can be implemented by hardware, software, or a combination thereof.
[0129] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it executes the method process performed by the electronic device in the embodiment of the cache renewal method.
[0130] This embodiment 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, it includes:
[0131] Receiving expiring cache data sent by a client;
[0132] When it is determined that the expiring cache data needs to be renewed, performing a renewal process on the expiring cache data.
[0133] In summary, the embodiments of the present application provide a cache renewal method, system, electronic device, storage medium, and program product. In this solution, the client sends the cache data that is about to expire to the server as near-expired cache data, and the server determines whether the near-expired cache data needs to be renewed. If it needs to be renewed, the near-expired cache data is renewed. In this way, it is not necessary for the client to re-request the data from the data layer after the cache expires naturally to complete cache renewal. This solution realizes cache renewal in an asynchronous manner between the server and the client, which can effectively reduce the load pressure on the data layer in scenarios where a large number of caches expire.
[0134] In the embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some communication interfaces. The indirect coupling or communication connection of the devices or units can be in an electrical, mechanical or other form.
[0135] In addition, the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0136] Furthermore, in each embodiment of the present application, the functional modules can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.
[0137] In this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations.
[0138] The above are only the embodiments of the present application and are not used to limit the protection scope of the present application. For those skilled in the art, the present application can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A cache renewal method, characterized in that: Applied to a server, the method comprises: Receive expiring cache data sent by the client; When it is determined that the cache data about to expire needs to be renewed, a renewal process is performed on the cache data about to expire.
2. The method according to claim 1, characterized in that The renewing process of the cached data about to expire includes: Obtain cache key data corresponding to the expiring cache data; Sending the cache key data to the client; Obtain the latest cache data found by the client according to the cache key data; The latest cache data is stored in the cache to implement the renewal processing of the cache data that is about to expire.
3. The method according to claim 2, characterized in that Determine whether the cache data that is about to expire needs to be renewed by the following method: Determine cache configuration data corresponding to the cache key data according to the cache key data, wherein the cache configuration data includes a cache expiration time and renewal information indicating whether renewal is required; If the cache configuration data includes renewal information indicating that renewal is required and the remaining effective time of the cache expiration time is less than a set threshold, it is determined that the cache data needs to be renewed.
4. The method according to claim 3, characterized in that: The cache configuration data also includes a renewal method, and sending the cache key data to the client includes: When the renewal method is to obtain cache data returned by the client for renewal, the cache key data is sent to the client; In the case where the renewal mode is to use the original cache data for renewal, the method further includes: The cache data about to expire is stored again in the cache to implement the renewal processing of the cache data about to expire.
5. The method according to claim 4, characterized in that The obtaining the latest cache data found by the client according to the cache key data includes: A hook function is called to obtain the latest cache data, wherein the hook function is used to hook a target function, and the target function is used to instruct the client to search for the latest cache data according to the cache key data.
6. The method according to claim 2, characterized in that After sending the cache key data to the client, the method further includes: If the latest cache data returned by the client is not obtained; The cache data about to expire is then stored in the cache again to implement the renewal process for the cache data about to expire.
7. A cache renewal method, characterized in that: Applied to a client, the method comprises: receiving user data requests; Searching for corresponding cache data from the cache according to the user data request; When it is determined that the cached data is about to expire, the cached data is sent to a server, and the server is used to renew the cached data when it is determined that the cached data needs to be renewed.
8. A cache renewal system, characterized in that: The system comprises: The client is used to receive a user data request and search for corresponding cache data from the cache according to the user data request; The client is further configured to send the cached data to the server when determining that the cached data is about to expire; The server is used to renew the cached data when it is determined that the cached data needs to be renewed.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the method according to any one of claims 1 to 7 is executed.
10. 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 7 is performed.
11. A computer program product, characterized in that The method comprises computer program instructions, and when the computer program instructions are read and executed by a processor, the method according to any one of claims 1 to 7 is executed.