Cache-based processing method and device
By setting up a multi-level cache pool on the client and counting the number of requests, the network blocking problem of the cache strategy in the existing RPC technology in high concurrency scenarios is solved, and the response efficiency and the flexibility of the cache mechanism are improved.
Patent Information
- Application Number
- CN201810600524.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-06-12
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2038-06-12
AI Technical Summary
In existing RPC technology, caching strategies are all placed on the server side, which results in network congestion being prone to occur in high concurrency scenarios, response data not being returned in time, the cache management mechanism being inflexible, and hierarchical management lacking.
Set up a multi-level cache pool (first-level cache pool, second-level cache pool, third-level cache pool) on the client, query the local cache according to the data query request, obtain the data from the server if it does not exist, and count the number of requests. When the threshold is exceeded Write to local cache and use LRU storage mechanism to manage cache data.
It effectively reduces the number of network transmission requests, relieves server access pressure, improves response efficiency, and improves the flexibility of the caching mechanism by automatically triggering the caching mechanism.
Smart Images

Figure CN110598138B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a cache-based processing method and device. Background Art
[0002] In the existing RPC (remote procedure call) technology, the server provides a set of function interfaces to the client, and all cache strategies are placed on the server. In addition, in the use of cache, the server starts and stops the use of cache based on the switch configuration of the configuration file or database configuration table.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: First, all cache strategies are placed on the server side, which is prone to network congestion in high-concurrency scenarios, seriously affecting the timely return of response data of RPC requests. Second, starting and stopping the cache depends on manual configuration (modifying or setting configuration files, database configuration tables, etc.), and the working mechanism is not flexible. Third, the prior art mainly relies on the timeout mechanism to manage cache data, and the management method is single. In addition, the prior art does not perform hierarchical management of cache data. Summary of the invention
[0004] In view of this, the present invention provides a cache-based processing method and device, which can not only effectively alleviate the access pressure on the server caused by high-frequency network requests and improve the response efficiency of requests, but also automatically trigger the cache mechanism according to the statistics of the requests, thereby improving the flexibility of the cache mechanism.
[0005] To achieve the above objective, according to one aspect of the present invention, a cache-based processing method is provided.
[0006] The cache-based processing method of the present invention includes: querying the local cache according to a data query request to obtain target data; when the target data does not exist in the local cache, obtaining the target data from the server, and counting the number of requests for the target data, and when the number of requests for the target data exceeds an activation threshold, writing the target data obtained from the server into the local cache.
[0007] Optionally, the local cache includes: a first-level cache pool and a second-level cache pool; the step of querying the local cache according to the data query request to obtain the target data includes: querying the first-level cache pool according to the data query request; when the target data exists in the first-level cache pool, obtaining the target data from the first-level cache pool; when the target data does not exist in the first-level cache pool, querying the second-level cache pool according to the data query request; when the target data exists in the second-level cache pool, obtaining the target data from the second-level cache pool.
[0008] Optionally, the method further includes: before executing the step of obtaining the target data from the first-level cache pool, confirming that the target data in the first-level cache pool is within a first valid time length and the number of requests within the first valid time length is not greater than a first wear threshold.
[0009] Optionally, the method also includes: when the target data in the first-level cache pool exceeds a first valid time or the number of requests for the target data within the first valid time is greater than a first wear threshold, obtaining the target data from the server; and when the target data in the first-level cache pool exceeds the first valid time, deleting the target data in the first-level cache pool; when the number of requests for the target data in the first-level cache pool within the first valid time is greater than the first wear threshold, updating the target data in the first-level cache pool.
[0010] Optionally, the method further includes: before executing the step of obtaining the target data from the secondary cache pool, confirming that the target data in the secondary cache pool is within a second valid time period and the number of requests for the target data within the second valid time period is not greater than a second wear threshold.
[0011] Optionally, the method also includes: obtaining the target data from the server when the target data in the secondary cache pool exceeds the second valid time or the number of requests for the target data within the second valid time is greater than a second wear threshold; and deleting the target data in the secondary cache pool when the target data in the secondary cache pool exceeds the second valid time; updating the target data in the secondary cache pool when the number of requests for the target data in the secondary cache pool within the second valid time is greater than the second wear threshold.
[0012] Optionally, the method also includes: after executing the step of confirming that the target data in the secondary cache pool is within the second valid time length, determining whether the number of requests for the target data within the transition statistical period is greater than a transition threshold; if so, writing the target data obtained from the server into the primary cache pool, and deleting the target data in the secondary cache pool; wherein the transition statistical period is less than the second valid time length.
[0013] Optionally, the local cache also includes a three-level cache pool; the step of counting the number of requests for the target data includes: querying the three-level cache pool according to the data query request to obtain the corresponding statistical record; when the corresponding statistical record is within a third valid time period, adding one to the number of requests in the corresponding statistical record; when the corresponding statistical record exceeds the third valid time period, setting the number of requests in the corresponding statistical record to one.
[0014] Optionally, the first-level cache pool, the second-level cache pool and / or the third-level cache pool adopts an LRU storage mechanism.
[0015] To achieve the above objective, according to another aspect of the present invention, a cache-based processing device is provided.
[0016] The cache-based processing device of the present invention includes: an acquisition module, which is used to query the local cache according to a data query request to obtain target data; a communication module, which is used to obtain the target data from the server when the target data does not exist in the local cache; a cache startup module, which is used to count the number of requests for the target data when the target data does not exist in the local cache; and when the number of requests for the target data exceeds an activation threshold, the cache startup module is also used to write the target data obtained from the server into the local cache.
[0017] To achieve the above objective, according to another aspect of the present invention, an electronic device is provided.
[0018] The electronic device of the present invention comprises: one or more processors; and a storage device for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the cache-based processing method of the present invention.
[0019] To achieve the above objective, according to yet another aspect of the present invention, a computer readable medium is provided.
[0020] The computer-readable medium of the present invention stores a computer program, and when the program is executed by a processor, the cache-based processing method of the present invention is implemented.
[0021] One embodiment of the above invention has the following advantages or beneficial effects: by setting a local cache on the client, obtaining the target data from the local cache according to the data query request, and then obtaining the target data from the server when the target data does not exist in the local cache, a large number of data query requests can be directly processed locally, which significantly reduces the number of requests transmitted to the server through the network, effectively alleviates the access pressure on the server caused by high-frequency network requests, and improves the response efficiency of data query requests. In addition, by counting the number of requests for the target data when the target data does not exist in the local cache, and writing the target data obtained from the server to the local cache when the number of requests exceeds the activation threshold, the local cache mechanism of the client can be automatically triggered according to the statistics of the number of requests, thereby improving the flexibility of the cache mechanism.
[0022] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0024] Figure 1 is a schematic diagram of main steps of a cache-based processing method according to an embodiment of the present invention;
[0025] Figure 2 is a schematic diagram of main steps of a cache-based processing method according to another embodiment of the present invention;
[0026] Figure 3 is a schematic diagram of some steps of a cache-based processing method according to yet another embodiment of the present invention;
[0027] Figure 4 is a schematic diagram of some steps of a cache-based processing method according to yet another embodiment of the present invention;
[0028] Figure 5 is a schematic diagram of main modules of a cache-based processing device according to an embodiment of the present invention;
[0029] Figure 6 is a schematic diagram of the composition of a local cache according to an embodiment of the present invention;
[0030] Figure 7 is a schematic diagram of main modules of a cache-based processing device according to another embodiment of the present invention;
[0031] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0032] Fig. 9 It is a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0034] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.
[0035] Figure 1 FIG. 1 is a schematic diagram of the main steps of a cache-based processing method according to an embodiment of the present invention. The method of the embodiment of the present invention can be executed by a client. Figure 1 As shown, the cache-based processing method of the embodiment of the present invention includes:
[0036] Step S101: query the local cache according to the data query request to obtain target data.
[0037] Among them, the data query request can be a request format such as an RPC (remote procedure call) request or an Http request. In a specific example, the caller can make an RPC request through the parameters defined in the function interface provided by the server. After receiving the caller's RPC request, the client can query the local cache according to the parameters in the RPC request. If the target data exists in the local cache, the client directly obtains the target data from the local cache. The target data can be understood as "query result data". For example, the request parameter is a product identifier, and the target data is the detailed information of the product. For example, the request parameter is a merchant name, and the target data is the transaction information of the merchant.
[0038] The local cache may be set in the client memory and may cache data in the form of a key-value pair. Furthermore, the local cache may be a multi-level cache, including a first-level cache pool and a second-level cache pool. The first-level cache pool and the second-level cache pool are mainly used to cache target data with a high request frequency. Moreover, the request frequency of the cached data in the first-level cache pool is higher than the request frequency of the cached data in the second-level cache pool.
[0039] Step S102: When the target data does not exist in the local cache, obtain the target data from the server.
[0040] Specifically, when the target data does not exist in the local cache, the client may send a data query request to the server, and then receive result data corresponding to the data query request, ie, the target data, returned by the server.
[0041] Step S103: When the target data does not exist in the local cache, the number of requests for the target data is counted, and when the number of requests for the target data exceeds an activation threshold, the target data obtained from the server is written into the local cache.
[0042] In step S103, the number of requests for the target data can be understood as the “number of calls of the request parameter.” For example, if the request parameter in the data query request is a product ID, the client counts the number of calls of the received request parameter “product ID.”
[0043] In an embodiment of the present invention, by setting a local cache on the client, obtaining target data from the local cache according to a data query request, and obtaining target data from the server when the target data does not exist in the local cache, a large number of data query requests can be directly processed locally, significantly reducing the number of requests transmitted to the server through the network, effectively alleviating the access pressure on the server caused by high-frequency network requests, and improving the response efficiency of data query requests. In addition, by counting the number of requests for target data when the target data does not exist in the local cache, and writing the target data obtained from the server into the local cache when the number of requests exceeds the activation threshold, the local cache mechanism of the client can be automatically triggered according to the statistics of the number of requests, thereby improving the flexibility of the cache mechanism.
[0044] Figure 2 FIG. 1 is a schematic diagram of the main steps of a cache-based processing method according to another embodiment of the present invention. Figure 2 In the embodiment shown, the local cache includes: a first-level cache pool, a second-level cache pool, and a third-level cache pool. Among them, the first-level cache pool and the second-level cache pool are mainly used to cache target data with a high request frequency, and the third-level cache pool is mainly used to cache statistical records of data query requests. In addition, the request frequency of cached data in the first-level cache pool is higher than the request frequency of cached data in the second-level cache pool. Figure 2 As shown, the cache-based processing method of the embodiment of the present invention includes:
[0045] Step S201: query the first-level cache pool according to the data query request.
[0046] Among them, the data query request can be a request format such as an RPC request or an Http request. In specific implementation, the caller can make an RPC request through the parameters defined in the function interface provided by the server. After receiving the RPC request, the client can first query the first-level cache pool in the local cache according to the parameters in the RPC request. The first-level cache pool can cache data in the form of key-value pairs. Furthermore, the first-level cache pool adopts an LRU (least recently used) storage mechanism to ensure that the most recently requested target data is correctly recorded, and the target data requested earlier is deleted from the first-level cache pool.
[0047] Step S202: when the target data exists in the first-level cache pool, the target data is obtained from the first-level cache pool. Further, after the target data is obtained from the first-level cache pool, the obtained target data may be returned to the caller.
[0048] Step S203: When the target data does not exist in the first-level cache pool, query the second-level cache pool according to the data query request.
[0049] The secondary cache pool can cache data in the form of key-value pairs. Furthermore, the secondary cache pool adopts an LRU (least recently used) storage mechanism to ensure that the most recently requested target data is correctly recorded and that earlier requested target data is deleted from the secondary cache pool. By adopting the LRU storage mechanism in the primary and secondary cache pools, it is ensured that hot data does not occupy a large amount of client memory resources. In addition, the primary and secondary cache pools can also adopt a FIFO (first-in, first-out queue) storage mechanism.
[0050] Step S204: if the target data exists in the secondary cache pool, the target data is obtained from the secondary cache pool. Further, after the target data is obtained from the secondary cache pool, the obtained target data may be returned to the caller.
[0051] Step S205: When the target data does not exist in the secondary cache pool, the target data is obtained from the server.
[0052] Specifically, when the requested target data does not exist in the first-level cache pool or the second-level cache pool, the client can send a data query request to the server, and then receive the result data corresponding to the data query request, i.e., the target data, returned by the server. Further, after obtaining the target data from the server, the obtained target data can be returned to the caller.
[0053] Step S206: query the third-level cache pool according to the data query request to obtain corresponding statistical records.
[0054] The three-level cache pool can cache statistical records in the form of key-value pairs. Furthermore, the three-level cache pool adopts an LRU (least recently used) storage mechanism to ensure that the statistical records of the most recent data query requests are correctly saved, and the earlier statistical records are deleted from the three-level cache pool. Specifically, when the requested target data does not exist in the first-level cache pool or the second-level cache pool, the client can query the three-level cache pool according to the request parameters in the data query request to obtain the statistical records corresponding to the requested parameters. Among them, the statistical records may include: request parameters, the third effective duration (or referred to as "statistical cycle duration"), the number of requests within the third effective duration, and the activation threshold. In specific implementation, the third effective duration and the size of the activation threshold can be flexibly set as needed. For example, the third effective duration can be set to 5 minutes, and the activation threshold can be set to 100 times.
[0055] Step S207: Determine whether the corresponding statistical record is within the third valid time period. If yes, execute step S208; if not, execute step S212.
[0056] In an optional embodiment, the statistical record may further include a cycle end time. In this optional embodiment, step S207 further includes: comparing the cycle end time in the acquired statistical record with the current time. If the cycle end time is later than the current time, it is determined that the acquired statistical record is in the third valid time period; otherwise, it is determined that the acquired statistical record exceeds the third valid time period. In another optional embodiment, the statistical record may further include a status identifier. In this optional embodiment, step S207 further includes: when the value of the status identifier is "true", it indicates that the acquired statistical record is in the third valid time period; when the value of the status identifier is "false", it indicates that the acquired statistical record exceeds the third valid time period.
[0057] Step S208: Increase the number of requests in the corresponding statistical record by 1. After step S208, execute step S209.
[0058] Step S209: Determine whether the number of requests in the corresponding statistical record exceeds the activation threshold. If yes, execute step S210; if no, execute step S211.
[0059] In the embodiment of the present invention, when the number of requests for target data exceeds the activation threshold, it indicates that the data query request is relatively active and a cache strategy needs to be enabled for it, that is, the target data of the request is placed in the local cache through step S210.
[0060] Step S210: writing the target data obtained from the server into a secondary cache pool.
[0061] Step S211: No operation. It should be noted that the “no operation” in step S211 means that the operation in step S210 is not performed.
[0062] Step S212: Set the number of requests in the corresponding statistical record to 1. Further, after step S212, the method of the embodiment of the present invention further includes the following steps: updating the value of the period end time or the state identifier in the statistical record.
[0063] In an embodiment of the present invention, by setting up a local cache including a first-level cache pool, a second-level cache pool, and a third-level cache pool on the client, a large number of data query requests can be directly processed locally, which significantly reduces the number of requests transmitted to the server through the network, effectively alleviates the access pressure on the server caused by high-frequency network requests, and improves the response efficiency of data query requests. In addition, through the above steps, the local cache mechanism of the client can be triggered in real time and automatically according to the statistics of the number of requests, thereby eliminating the need to rely on manual configuration and improving the flexibility of the cache mechanism. In addition, by adopting the LRU storage mechanism in the first-level cache pool, the second-level cache pool, and the third-level cache pool, it can be ensured that the cached data does not occupy a large amount of memory resources on the client.
[0064] exist Figure 2 Based on the embodiment shown, the present invention makes further improvements, thereby proposing another processing method based on cache. In another embodiment of the present invention, the processing flow of step S201 to step S204 is improved. Figure 3 , Figure 4 The improved steps in another embodiment of the present invention are described in detail, and the unimproved steps are not described again.
[0065] Figure 3 FIG. 1 is a schematic diagram of some steps of a cache-based processing method according to another embodiment of the present invention. Figure 3 As shown, the method of the embodiment of the present invention includes the following steps:
[0066] Step S301: Determine whether target data exists in the first-level cache pool.
[0067] Step S302: Determine whether the target data is in the first valid time period. If yes, execute step S303; if no, execute step S306.
[0068] In the embodiment of the present invention, the first-level cache pool includes, in addition to the request parameters and the target data corresponding to the request parameters, the first effective duration, the number of requests for the target data within the first effective duration, and the first wear threshold. In specific implementation, the first effective duration and the first wear threshold can be flexibly set as needed. For example, the first effective duration can be set to 5 minutes, and the first wear threshold can be set to 10,000 times.
[0069] In an optional embodiment, the first-level cache pool also includes: the effective deadline of the target data. In this optional embodiment, step S302 further includes: comparing the effective deadline of the target data obtained by the query with the current time. If the effective deadline is later than the current time, it is judged that the target data is in the first effective duration; otherwise, it is judged that the target data exceeds the first effective duration. In another optional embodiment, the first-level cache pool may also include: a status identifier of the target data. In this optional embodiment, step S302 further includes: when the value of the status identifier of the target data is "true", it indicates that the target data is in the first effective duration; when the value of the status identifier of the target data is "false", it indicates that the target data exceeds the first effective duration.
[0070] Furthermore, after determining that the target data is in the first valid duration and before executing step S303, the method of the embodiment of the present invention further includes the following steps: updating the number of requests for the target data in the first-level cache pool. Specifically, the update operation may be to increase the number of requests by 1.
[0071] Step S303: Determine whether the number of requests for the target data is not greater than a first wear threshold. If yes, execute step S304; if no, execute step S305.
[0072] Step S304: Acquire target data from the first-level cache pool.
[0073] Step S305: Acquire the target data from the server, and update the target data in the first-level cache pool.
[0074] Specifically, when the number of requests for the target data within the first effective time is greater than the first wear threshold, the client may send a data query request to the server, and then receive the target data returned by the server. Next, the client may return the target data obtained from the server to the caller, and update the cache data of the first-level cache pool according to the target data returned by the server.
[0075] Step S306: Acquire the target data from the server, and delete the target data from the first-level cache pool.
[0076] Specifically, when the target data exceeds the first effective time, the client can send a data query request to the server, and then receive the target data returned by the server. Next, the client can return the target data obtained from the server to the caller, delete the target data corresponding to the data query request in the first-level cache pool, and write a statistical record of the request in the third cache pool.
[0077] In the embodiment of the present invention, through steps S301 to S306, the cache data in the first-level cache pool can be managed from multiple dimensions such as the first effective duration and the first wear threshold, and the cache data can be updated and deleted in a timely manner.
[0078] Figure 4 FIG. 1 is a schematic diagram of some steps of a cache-based processing method according to another embodiment of the present invention. Figure 4 As shown, the method of the embodiment of the present invention includes the following steps:
[0079] Step S401: Target data exists in the secondary cache pool. After step S401, step S402 is executed.
[0080] Step S402: Determine whether the target data is within the second valid time period. If yes, execute step S403; if no, execute step S407.
[0081] In an embodiment of the present invention, in addition to the request parameters and the target data corresponding to the request parameters, the secondary cache pool also includes: the second effective duration, the number of requests for the target data within the second effective duration, the second wear threshold, the transition statistical period, and the transition threshold. Moreover, the transition statistical period is less than the second effective duration. During specific implementation, the second effective duration, the transition statistical period, the second wear threshold, and the size of the transition threshold can be flexibly set as needed. For example, the second effective duration can be set to 2 minutes, the transition statistical period can be set to 30 seconds, the second wear threshold can be set to 1000 times, and the transition threshold can be set to 900 times.
[0082] In an optional embodiment, the secondary cache pool further includes: the effective deadline of the target data. In this optional embodiment, step S402 further includes: comparing the effective deadline of the target data obtained by the query with the current time. If the effective deadline is later than the current time, it is judged that the target data is in the second effective time; otherwise, it is judged that the target data exceeds the second effective time. In another optional embodiment, the secondary cache pool may also include: a status identifier of the target data. In this optional embodiment, step S402 further includes: when the value of the status identifier of the target data is "true", it indicates that the target data is in the second effective time; when the value of the status identifier of the target data is "false", it indicates that the target data exceeds the second effective time.
[0083] Step S403: Update the total number of requests for target data and the number of requests within the transition statistical period. After step S403, step S404 may be performed.
[0084] Specifically, the update operation in step S403 may be: adding 1 to the total number of requests for the target data and adding 1 to the number of requests within the transition statistical period.
[0085] Step S404: Determine whether the number of requests within the transition statistical period is not greater than the transition threshold. If so, execute step S405; if not, execute step S408.
[0086] Step S405: Determine whether the total number of requests is not greater than the second wear threshold. If so, execute step S406; if not, execute step S409.
[0087] Step S406: Acquire target data from the secondary cache pool.
[0088] Step S407: Acquire the target data from the server, and delete the target data from the secondary cache pool.
[0089] Specifically, when the target data exceeds the second effective time, the client can send a data query request to the server, and then receive the target data returned by the server. Next, the client can return the target data obtained from the server to the caller, delete the target data corresponding to the data query request in the secondary cache pool, and write a statistical record of the data query request in the third cache pool.
[0090] Step S408: write the target data obtained from the server into the primary cache pool, and delete the target data from the secondary cache pool.
[0091] Specifically, when the number of requests for the target data within the transition statistical period is greater than the transition threshold, the client can send a data query request to the server, and then receive the target data returned by the server. Next, the client can return the target data obtained from the server to the caller, write the target data returned by the server into the first-level cache pool, and delete the original target data in the second-level cache pool.
[0092] Step S409: Obtain target data from the server, and update the target data in the secondary cache pool.
[0093] Specifically, when the number of requests for the target data within the second effective time is greater than the second wear threshold, the client may send a data query request to the server, and then receive the target data returned by the server. Next, the client may return the target data obtained from the server to the caller, and update the cache data of the secondary cache pool according to the target data returned by the server.
[0094] In the embodiment of the present invention, through the above steps, the cache data in the secondary cache pool can be managed from multiple dimensions such as the second effective duration, the second wear threshold, and the transition threshold, and the grading of cache data and the timely updating and deletion of cache data can be realized.
[0095] Figure 5 FIG. 1 is a schematic diagram of the main modules of a cache-based processing device according to an embodiment of the present invention. Figure 5 As shown, the cache-based processing device 500 according to the embodiment of the present invention includes: an acquisition module 501 , a communication module 502 , and a cache startup module 503 .
[0096] The acquisition module 501 is used to query the local cache according to the data query request to obtain the target data.
[0097] Among them, the data query request can be a request format such as an RPC (remote procedure call) request or an Http request. In a specific example, the caller can make an RPC request through the parameters defined in the function interface provided by the server. After receiving the caller's RPC request, the acquisition module 501 can query the local cache according to the parameters in the RPC request. If the target data exists in the local cache, the acquisition module 501 directly obtains the target data from the local cache. The target data can be understood as "query result data". For example, the request parameter is a product identifier, and the target data is the detailed information of the product. For example, the request parameter is a merchant name, and the target data is the transaction information of the merchant.
[0098] The local cache may be set in the client memory and may cache data in the form of a key-value pair. Furthermore, the local cache may be a multi-level cache, including a first-level cache pool and a second-level cache pool. The first-level cache pool and the second-level cache pool are mainly used to cache target data with a high request frequency. Moreover, the request frequency of the cached data in the first-level cache pool is higher than the request frequency of the cached data in the second-level cache pool.
[0099] The communication module 502 is used to obtain the target data from the server when the target data does not exist in the local cache.
[0100] Specifically, when the target data does not exist in the local cache, the communication module 502 may send a data query request to the server, and then receive result data corresponding to the data query request, ie, the target data, returned by the server.
[0101] The cache startup module 503 is used to count the number of requests for the target data when the target data does not exist in the local cache; and when the number of requests for the target data exceeds the activation threshold, the cache startup module is also used to write the target data obtained from the server into the local cache.
[0102] The number of requests for the target data may be understood as the number of calls of the request parameter. For example, if the request parameter in the data query request is a product ID, the client counts the number of calls of the received request parameter "product ID".
[0103] In an embodiment of the present invention, by setting a local cache on the client, obtaining target data from the local cache through the acquisition module 501, and obtaining the target data from the server through the communication module 502 when the target data does not exist in the local cache, a large number of data query requests can be directly processed locally, which significantly reduces the number of requests transmitted to the server through the network, effectively alleviates the access pressure on the server caused by high-frequency network requests, and improves the response efficiency of data query requests. In addition, when the number of requests exceeds the activation threshold, the target data obtained from the server is written into the local cache through the cache startup module 503, which can automatically trigger the client's local cache mechanism according to the statistics of the number of requests, thereby improving the flexibility of the cache mechanism.
[0104] Figure 6 FIG. 1 is a schematic diagram of the composition of a local cache according to an embodiment of the present invention. Figure 6 As shown, the local cache 600 of the embodiment of the present invention includes: a first-level cache pool 601 , a second-level cache pool 602 , and a third-level cache pool 603 .
[0105] The first-level cache pool 601 is mainly used to cache target data with a high request frequency, which can also be called a "pressure sample pool". In addition, in addition to the request parameters and the target data corresponding to the request parameters, the first-level cache pool 601 also includes: the first effective duration, the number of requests for the target data within the first effective duration, and the first wear threshold. In specific implementation, the first effective duration and the size of the first wear threshold can be flexibly set as needed. For example, the first effective duration can be set to 5 minutes, and the first wear threshold can be set to 10,000 times.
[0106] The secondary cache pool 602 is mainly used to cache target data with a high request frequency, which can also be called an "active sample pool". In addition, in addition to the request parameters and the target data corresponding to the request parameters, the secondary cache pool also includes: the second effective duration, the number of requests for the target data within the second effective duration, the second wear threshold, the transition statistical period, and the transition threshold. Moreover, the transition statistical period is less than the second effective duration. During specific implementation, the second effective duration, the transition statistical period, the second wear threshold, and the size of the transition threshold can be flexibly set as needed. For example, the second effective duration can be set to 2 minutes, the transition statistical period can be set to 30 seconds, the second wear threshold can be set to 1000 times, and the transition threshold can be set to 900 times.
[0107] The third-level cache pool 603 is mainly used for caching statistical records of data query requests, which can also be called a "sample screening pool". The difference between the third-level cache pool 603 and the first-level cache pool and the second-level cache pool is that the third-level cache pool 603 does not save the target data of the request, while the first-level cache pool and the second-level cache pool save the target data of the request. Among them, the statistical records may include request parameters, the third effective time (or called "statistical cycle time"), the number of requests within the third effective time, and the activation threshold. In specific implementation, the third effective time and the size of the activation threshold can be flexibly set as needed. For example, the third effective time can be set to 5 minutes, and the activation threshold can be set to 100 times.
[0108] In an embodiment of the present invention, the first-level cache pool 601, the second-level cache pool 602, and the third-level cache pool 603 can cache data in the form of key-value pairs. Further, the first-level cache pool, the second-level cache pool, and the third-level cache pool adopt an LRU (least recently used) storage mechanism to ensure that the target data or statistical records requested recently are correctly recorded, and the target data or statistical records requested earlier are deleted. In addition, the first-level cache pool, the second-level cache pool, and the third-level cache pool can also adopt a FIFO (first-in, first-out queue) storage mechanism. In addition, in a specific implementation, the storage capacity of the first-level cache pool 601, the second-level cache pool 602, and the third-level cache pool 603 can be defined at the time of initialization. In a preferred embodiment, the storage capacity of the first-level cache pool, the second-level cache pool, and the third-level cache pool has the following proportional relationship, that is, 1:4:16. For example, the storage capacity of the first-level cache pool can be set to 128KB, the storage capacity of the second-level cache pool can be set to 512KB, and the capacity of the third-level cache pool can be set to 2048KB.
[0109] Figure 7 FIG. 1 is a schematic diagram of the main modules of a cache-based processing device according to another embodiment of the present invention. In the embodiment of the present invention, the local cache adopts Figure 6 As shown in the structure. Figure 7 As shown, the cache-based processing device 700 according to the embodiment of the present invention includes: an acquisition module 701 , a first confirmation module 702 , a cache management module 703 , a communication module 704 , a second confirmation module 705 , and a cache startup module 706 .
[0110] The acquisition module 701 is used to query the local cache according to the data query request to obtain the target data, specifically including: 1) the acquisition module 701 queries the first-level cache pool according to the data query request; when the target data exists in the first-level cache pool, and the first confirmation module 701 confirms that the target data is within the first effective time length, and the number of requests within the first effective time length is not greater than the first wear threshold, the acquisition module 701 obtains the target data from the first-level cache pool. 2) When the target data does not exist in the first-level cache pool, the acquisition module 701 queries the second-level cache pool according to the data query request; when the target data exists in the second-level cache pool, and the second confirmation module 705 confirms that the target data is within the second effective time length, and the number of requests within the second effective time length is not greater than the second wear threshold, the acquisition module 701 obtains the target data from the second-level cache pool.
[0111] The first confirmation module 702 is used to determine whether the target data in the first-level cache pool is in the first effective time length, and whether the number of requests within the first effective time length is not greater than the first wear threshold. In a preferred embodiment, the first confirmation module 702 may first execute the judgment logic of "whether the target data in the first-level cache pool is in the first effective time length", and after confirming that it is in the first effective time length, execute the judgment logic of "whether the number of requests within the first effective time length is not greater than the first wear threshold".
[0112] The cache management module 703 is used to delete the target data in the first-level cache pool and write the statistical record of the data query request in the third cache pool when the first confirmation module 702 determines that the target data in the first-level cache pool exceeds the first effective time. The cache management module 703 is also used to update the target data in the first-level cache pool when the first confirmation module 702 determines that the number of requests for the target data in the first-level cache pool within the first effective time is greater than the first wear threshold.
[0113] The second confirmation module 705 is used to determine whether the target data in the secondary cache pool is in the second effective duration and whether the number of requests in the second effective duration is not greater than the second wear threshold. In a preferred embodiment, the second confirmation module 705 may first execute the judgment logic of "whether the target data in the secondary cache pool is in the first effective duration", and after confirming that it is in the second effective duration, execute the judgment logic of "whether the number of requests in the second effective duration is not greater than the second wear threshold".
[0114] The cache management module 703 is also used to delete the target data in the secondary cache pool and write the statistical record of the data query request in the third cache pool when the second confirmation module 705 determines that the target data in the secondary cache pool exceeds the second effective time. The cache management module 703 is also used to update the target data in the secondary cache pool when the second confirmation module 705 determines that the number of requests for the target data in the secondary cache pool within the second effective time is greater than the second wear threshold.
[0115] In a preferred embodiment, the second confirmation module 705 is further used to determine whether the number of requests for the target data in the transition statistical period is greater than the transition threshold after confirming that the target data in the secondary cache pool is in the second effective time. In this preferred embodiment, the cache management module 703 is further used to write the target data obtained from the server into the primary cache pool and delete the target data in the secondary cache pool when the number of requests for the target data in the transition statistical period is greater than the transition threshold.
[0116] The communication module 704 is used to obtain the target data from the server when the target data does not exist in the local cache. The communication module 704 is also used to obtain the target data from the server when the first confirmation module 702 determines that the target data in the first-level cache pool exceeds the first effective time or the number of requests within the first effective time is greater than the first wear threshold. The communication module 704 is also used to obtain the target data from the server when the second confirmation module 705 determines that the target data in the second-level cache pool exceeds the second effective time or the number of requests within the second effective time is greater than the second wear threshold.
[0117] The cache startup module 706 is used to count the number of requests for the target data when the target data does not exist in the local cache. Furthermore, when the number of requests for the target data exceeds the activation threshold, the cache startup module 706 is also used to write the target data obtained from the server into the local cache.
[0118] Exemplarily, the cache startup module 706 counts the number of requests for the target data, including: the cache startup module 706 queries the three-level cache pool according to the data query request to obtain the corresponding statistical record; when the corresponding statistical record is within the third valid time period, the cache startup module 706 increases the number of requests in the corresponding statistical record by one; when the corresponding statistical record exceeds the third valid time period, the cache startup module 706 sets the number of requests in the corresponding statistical record to one.
[0119] In the embodiment of the present invention, the following technical effects can be achieved through the above device: 1) By setting a local cache including a first-level cache pool, a second-level cache pool, and a third-level cache pool on the client, and querying the local cache according to the data query request through the acquisition module, a large number of data query requests can be directly processed locally, which significantly reduces the number of requests transmitted to the server through the network, effectively alleviates the access pressure on the server caused by high-frequency network requests, and improves the response efficiency of data query requests. 2) By setting a cache startup module, the local cache mechanism of the client can be triggered in real time and automatically according to the statistics of the number of requests, so that there is no need to rely on manual configuration, which improves the flexibility of the cache mechanism. 3) By setting a cache management module, the data in the first-level cache pool and the second-level cache pool can be hierarchically managed from multiple dimensions, and updated and deleted in time. 4) By adopting the LRU storage mechanism in the first-level cache pool, the second-level cache pool and the third-level cache pool, it can be ensured that the cached data does not occupy a large amount of memory resources on the client.
[0120] Figure 8 An exemplary system architecture 800 is shown to which the cache-based processing method or cache-based processing device according to the embodiment of the present invention can be applied.
[0121] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0122] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages (such as data query requests), etc. Various client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0123] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0124] The server 805 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 801, 802, and 803. The background management server may analyze and process the received data such as the data query request, and feed back the processing result (such as the response data of the data query request) to the terminal device.
[0125] It should be noted that the cache-based processing method provided in the embodiment of the present invention is generally executed by a terminal device, and accordingly, the cache-based processing device is generally arranged in the terminal device.
[0126] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0127] Fig. 9 A schematic diagram of the structure of a computer system 900 suitable for implementing an electronic device of an embodiment of the present invention is shown. Fig. 9 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0128] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0129] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0130] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0131] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0132] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0133] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes an acquisition module, a communication module and a cache startup module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the acquisition module may also be described as "a module that queries the local cache according to a data query request to obtain target data".
[0134] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes the following process: querying the local cache according to the data query request to obtain the target data; when the target data does not exist in the local cache, obtaining the target data from the server, and counting the number of requests for the target data, and when the number of requests for the target data exceeds the activation threshold, writing the target data obtained from the server into the local cache.
[0135] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A cache-based processing method, It is characterized in that The method comprises: Query the local cache according to the data query request to obtain the target data; When the target data does not exist in the local cache, the target data is obtained from the server, and the number of requests for the target data is counted, and when the number of requests for the target data exceeds an activation threshold, the target data obtained from the server is written into the local cache; The local cache includes: a first-level cache pool and a second-level cache pool; The step of querying the local cache according to the data query request to obtain the target data includes: querying the first-level cache pool according to the data query request; when the target data exists in the first-level cache pool, obtaining the target data from the first-level cache pool; when the target data does not exist in the first-level cache pool, querying the second-level cache pool according to the data query request; when the target data exists in the second-level cache pool, obtaining the target data from the second-level cache pool; Before executing the step of acquiring the target data from the secondary cache pool, confirming that the target data in the secondary cache pool is within a second valid duration and the number of requests for the target data within the second valid duration is not greater than a second wear threshold; After executing the step of confirming that the target data in the secondary cache pool is within the second effective duration, determine whether the number of requests for the target data within the transition statistical period is greater than the transition threshold; if so, write the target data obtained from the server into the primary cache pool, and delete the target data in the secondary cache pool; wherein the transition statistical period is less than the second effective duration.
2. The method according to claim 1, It is characterized in that The method further comprises: Before executing the step of acquiring the target data from the first-level cache pool, it is confirmed that the target data in the first-level cache pool is within a first valid duration and the number of requests for the target data within the first valid duration is not greater than a first wear threshold.
3. The method according to claim 2, It is characterized in that The method further comprises: When the target data in the first-level cache pool exceeds the first effective time or the number of requests within the first effective time is greater than the first wear threshold, the target data is obtained from the server; and, When the target data in the first-level cache pool exceeds the first effective time, the target data in the first-level cache pool is deleted; when the number of requests for the target data in the first-level cache pool within the first effective time is greater than the first wear threshold, the target data in the first-level cache pool is updated.
4. The method according to claim 1, It is characterized in that The method further comprises: When the target data in the secondary cache pool exceeds the second effective time or the number of requests within the second effective time is greater than the second wear threshold, the target data is obtained from the server; and, When the target data in the secondary cache pool exceeds the second effective time, the target data in the secondary cache pool is deleted; when the number of requests for the target data in the secondary cache pool within the second effective time is greater than the second wear threshold, the target data in the secondary cache pool is updated.
5. The method according to any one of claims 1 to 4, It is characterized in that The local cache also includes a three-level cache pool; The step of counting the number of requests for the target data includes: querying the third-level cache pool according to the data query request to obtain corresponding statistical records; When the corresponding statistical record is within the third valid time period, the number of requests in the corresponding statistical record is increased by one; when the corresponding statistical record exceeds the third valid time period, the number of requests in the corresponding statistical record is set to one.
6. The method according to claim 5, It is characterized in that The first-level cache pool, the second-level cache pool and / or the third-level cache pool adopt an LRU storage mechanism.
7. A cache-based processing device, It is characterized in that The device comprises: The acquisition module is used to query the local cache according to the data query request to obtain the target data; A communication module, configured to obtain the target data from a server when the target data does not exist in the local cache; a cache startup module, configured to count the number of requests for the target data when the target data does not exist in the local cache; and, when the number of requests for the target data exceeds an activation threshold, the cache startup module is further configured to write the target data obtained from the server into the local cache; The local cache includes: a first-level cache pool and a second-level cache pool; The acquisition module is also used to: query the first-level cache pool according to the data query request; when the target data exists in the first-level cache pool, obtain the target data from the first-level cache pool; when the target data does not exist in the first-level cache pool, query the second-level cache pool according to the data query request; when the target data exists in the second-level cache pool, obtain the target data from the second-level cache pool; Before executing the step of acquiring the target data from the secondary cache pool, confirming that the target data in the secondary cache pool is within a second valid duration and the number of requests for the target data within the second valid duration is not greater than a second wear threshold; After executing the step of confirming that the target data in the secondary cache pool is within the second effective duration, determine whether the number of requests for the target data within the transition statistical period is greater than the transition threshold; if so, write the target data obtained from the server into the primary cache pool, and delete the target data in the secondary cache pool; wherein the transition statistical period is less than the second effective duration.
8. An electronic device, It is characterized in that include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Content inquiry method and device based on multiple stages of cache modules
CN104217019A
Cache management method and device
CN106815287A
