A caching method, device and medium

CN118277687BActive Publication Date: 2026-07-24TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
Filing Date
2024-04-25
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing technologies cannot automatically identify sudden surges in popular queries, leading to high downstream request pressure and affecting the stability of the search system.

Method used

By determining whether the search terms meet the preset hotspot conditions, the cache expiration time is extended and the cache is refreshed in a timely manner, allowing only one request to penetrate downstream, thus avoiding a large number of requests penetrating at the moment the cache expires.

Benefits of technology

It automatically responds to sudden surges in requests for trending search terms, preventing excessive pressure on downstream requests and improving the stability of the search system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277687B_ABST
    Figure CN118277687B_ABST
Patent Text Reader

Abstract

The application discloses a cache method, device and medium, comprising: when a search request is received, extracting a search word in the search request; if the search word meets a preset hot spot condition and the search word hits a local cache, determining whether a current time is less than a cache expiration time; the local cache is used for storing a search result meeting the preset hot spot condition; if the current time is less than the cache expiration time and the current time is greater than or equal to a cache refresh time, the cache expiration time is extended, the historical search result hitting in the local cache is returned, a search is initiated to obtain a search result, and the search result is written into the local cache; the cache expiration time is a time obtained by adding a first preset value to a cache write-in time, the cache refresh time is a time obtained by adding a second preset value to the cache write-in time, and the first preset value is greater than the second preset value. In this way, the sudden increase in the request quantity of the hot spot search word can be automatically coped with, the downstream request pressure is prevented from being too large, and the stability of the search system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of storage technology, and in particular to a caching method, device and medium. Background Technology

[0002] In order to update the search cache results of hot queries (i.e., users' search terms) in a timely manner, the following common methods for updating search cache results are: (1) periodically sorting the search results of specific search terms and refreshing the search results cache; (2) after a certain index is updated, notifying the upstream to mark the cache of the relevant search terms as invalid, and then performing a search sort to update the cache.

[0003] While existing technologies can meet the requirements for updating search cache results, they each have their own drawbacks: (1) Periodically sorting specific search terms. This method is equivalent to active elimination, but its drawback is that it requires known search terms and cannot automatically identify sudden hot query scenarios. In addition, since a certain number of search terms need to be searched periodically, it is difficult to avoid causing certain request pressure on downstream systems, and the faster the update frequency, the greater the system pressure; (2) After a certain index is updated, the upstream is notified to mark the cache invalid for the relevant search terms. This method does not require periodically refreshing a large number of query search results. However, it also requires known search terms, and a large number of requests will penetrate to downstream systems instantly when the cache is invalidated. In summary, in the process of implementing this application, the inventors have found that existing technologies have the problem that the search system cannot automatically identify sudden hot query scenarios, causing high downstream request pressure and affecting system stability. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a caching method, device, and medium that can automatically handle sudden increases in request volume for popular search terms, avoid excessive downstream request pressure, and improve the stability of the search system. The specific solution is as follows:

[0005] Firstly, this application discloses a caching method, including:

[0006] When a search request is received, the search terms in the search request are extracted;

[0007] If the search term meets the preset hotspot conditions and the search term hits the local cache, then it is determined whether the current time is less than the cache expiration time; the local cache is used to store search results that meet the preset hotspot conditions.

[0008] If the current time is less than the cache expiration time and the current time is greater than or equal to the cache refresh time, then extend the cache expiration time, return the historical search results that were hit in the local cache, initiate a search to obtain the search results, and write the search results into the local cache.

[0009] The cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time, wherein the first preset value is greater than the second preset value.

[0010] Optional, also includes:

[0011] Count the number of system requests for the target of the search term within one second;

[0012] If the number of system requests to the target within one second is greater than the target threshold, then the search term is determined to meet the preset hotspot condition; otherwise, the search term is determined not to meet the preset hotspot condition.

[0013] Optionally, the number of system requests for the target search term within one second is counted, including:

[0014] Get the number of servers deploying the caching service;

[0015] Count the number of system requests for the search term on a single server within one second;

[0016] The product of the number of servers and the number of system requests per second for the search term on a single server is determined as the target number of system requests per second for the search term.

[0017] Accordingly, the preset global system request count threshold within one second is used as the target threshold.

[0018] Optionally, the number of system requests for the target search term within one second is counted, including:

[0019] The number of system requests for the search term within one second on a single server where the caching service is deployed is counted, and this count is taken as the target number of system requests for the search term within one second.

[0020] Accordingly, the target threshold is the ratio of the preset global system request count threshold per second to the total number of servers deploying the caching service.

[0021] Optional, also includes:

[0022] If the search term meets the preset hotspot conditions and the search term does not hit the local cache, a search is initiated to obtain the search result, and the search result is written to the local cache, updating the cache write time, cache refresh time, and cache expiration time.

[0023] Optional, also includes:

[0024] If the search term does not meet the preset hotspot conditions, a search is initiated to obtain the search result, but the search result is not cached in the local cache.

[0025] Optionally, if the search term meets preset hotspot conditions and the search term hits the local cache, the method further includes:

[0026] If the current time is greater than or equal to the cache expiration time, a search is initiated to obtain the search result, which is then written to the local cache, and the cache write time, cache refresh time, and cache expiration time are updated.

[0027] Optionally, if the current time is greater than or equal to the cache expiration time, after initiating the search, the following steps are also included:

[0028] If the request fails, the historical search results that were hit in the local cache will be returned.

[0029] Optionally, if the current time is less than the cache refresh time, the method further includes: returning the historical search results hit in the local cache without initiating a search.

[0030] Secondly, this application discloses an electronic device, including a memory and a processor, wherein:

[0031] The memory is used to store computer programs;

[0032] The processor is used to execute the computer program to implement the aforementioned caching method.

[0033] Thirdly, this application discloses a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned caching method when executed by a processor.

[0034] As can be seen from the above scheme, the present invention provides a caching method, including: when a search request is received, extracting the search terms in the search request; if the search terms meet preset hotspot conditions and the search terms hit the local cache, determining whether the current time is less than the cache expiration time; the local cache is used to store search results that meet the preset hotspot conditions; if the current time is less than the cache expiration time and the current time is greater than or equal to the cache refresh time, extending the cache expiration time, returning the historical search results hit in the local cache, initiating a search to obtain the search results, and writing the search results into the local cache; wherein, the cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time, and the first preset value is greater than the second preset value.

[0035] As can be seen, the beneficial effects of this application are as follows: it automatically determines whether the search terms meet the preset hot search conditions, and saves the search results of hot search terms through local caching. By recording the cache write time and setting the cache refresh time and cache expiration time, when the current time is greater than or equal to the cache refresh time but less than the cache expiration time, i.e. when the current time is close to the cache expiration time, it promptly initiates a search to refresh the cache and extends the cache expiration time. Only one request is allowed to penetrate downstream to refresh, avoiding a large number of requests penetrating downstream at the moment of cache expiration, which could lead to system failure. In this way, it can automatically cope with the sudden increase in the number of requests for hot search terms, avoid excessive downstream request pressure, and improve the stability of the search system.

[0036] Correspondingly, the device and readable storage medium provided in this application also have the above-mentioned technical effects. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0038] Figure 1 A schematic diagram illustrating the process of reading and forcibly updating cached results in cache-aside mode, provided as an embodiment of this application;

[0039] Figure 2 A flowchart of a caching method provided in an embodiment of this application;

[0040] Figure 3 This is a schematic diagram illustrating the determination of hot search terms provided in an embodiment of this application;

[0041] Figure 4 A specific cache diagram is provided for an embodiment of this application;

[0042] Figure 5 A schematic diagram illustrating the system load effect of an application caching method provided in this embodiment of the application;

[0043] Figure 6 A schematic diagram of a cache device structure provided in an embodiment of this application;

[0044] Figure 7 A system architecture diagram of an application caching method provided in this application embodiment;

[0045] Figure 8 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0047] In search systems, as the amount of search data increases and the number of search requests grows, search caching becomes a crucial component for improving the performance and stability of search services. This is especially true in scenarios where there are occasional spikes in search requests (qps, or queries per second, the number of system requests per second), such as sudden hot topics or the launch of new events. This can lead to increased requests to the search system and its downstream modules, causing high loads on downstream modules or even system unavailability. Therefore, it is necessary to cache the final search results to protect the stability of the search system and other downstream modules. Existing caching methods generally fall into three categories: (1) Cache Aside update mode: updating both the cache and the database simultaneously; (2) Read / Write Through update mode: updating the cache first, with the cache synchronously updating the database; (3) Write Behind Caching update mode: updating the cache first, with the cache periodically and asynchronously updating the database. For search scenarios, only cache aside is applicable among these three modes, requiring simultaneous updates to both the cache and the index. Index updates only update a single document; how this affects the sorted results list can only be determined through a single search. In other words, the index must be updated first, followed by a complete search to update the cache. See [link to relevant documentation]. Figure 1 As shown, Figure 1 This diagram illustrates the reading and forced update process of cached results in a cache-aside mode, as provided in an embodiment of this application. The reading steps include: 1) reading from the cache; 2) requesting downstream if a cache miss or expires. The writing steps include: 1) updating the data in storage; 2) invalidating the corresponding data in the cache.

[0048] In order to update the search cache results of hot queries in a timely manner, the following search cache result update methods are commonly used in the industry: (1) Periodically sort the search results of specific search terms and refresh the search results cache; (2) After an index is updated, notify the upstream to mark the cache invalid for the relevant search terms, and then perform a search sort to update the cache. Although the existing technologies can meet the requirements for updating search cache results, they each have their own disadvantages: (1) Periodically sort the search results of specific search terms. This method is equivalent to active elimination. Its disadvantage is that it requires the search terms to be known and cannot automatically identify the scenario of sudden hot queries. In addition, since a certain number of search terms need to be searched periodically, it is difficult to avoid causing a certain amount of request pressure to the downstream. The faster the update frequency, the greater the system pressure; (2) After an index is updated, notify the upstream to mark the cache invalid for the relevant search terms. This method does not require periodically refreshing a large number of query search results. However, it also requires the search terms to be known. If the search terms entered by the user are not marked invalid, the system can only wait for the cache results to expire automatically or be eliminated. In addition, a large number of requests will also penetrate to the downstream at the moment the cache expires. Cache breakdown occurs when a business application experiences several frequently accessed data points, such as those from flash sales. This frequently accessed data is known as "hot data." If a piece of hot data in the cache expires, a large number of requests will attempt to access it, but the data cannot be retrieved from the cache and will instead be accessed directly from the database. This can easily overwhelm the database due to the high concurrency, resulting in cache breakdown. To address this, this application provides a caching solution that automatically handles sudden surges in requests for hot search terms, preventing excessive pressure on downstream requests and improving the stability of the search system.

[0049] See Figure 2 As shown in the figure, this application discloses a caching method, including:

[0050] Step S11: When a search request is received, extract the search terms from the search request.

[0051] In this embodiment, a unique key can also be generated based on the request parameters in the search request, including search terms, client characteristics, etc., and the search results corresponding to the request parameters can be retrieved from the cache using this key. Client characteristics may include: client request protocol, client version number, etc. These parameters affect the parsing of front-end and back-end protocols, or the search result list. For example, in a music search scenario, this includes the music client request protocol and music client version number.

[0052] Step S12: If the search term meets the preset hotspot conditions and the search term hits the local cache, then determine whether the current time is less than the cache expiration time; the local cache is used to store search results that meet the preset hotspot conditions.

[0053] In this embodiment of the application, the number of system requests for the target term within one second can be counted; if the number of system requests for the target term within one second is greater than the target threshold, it is determined that the search term meets the preset hotspot condition; otherwise, it is determined that the search term does not meet the preset hotspot condition.

[0054] In one implementation, the number of servers deploying the caching service can be obtained; the number of system requests per second for the search term on a single server can be counted; the product of the number of servers and the number of system requests per second for the search term on a single server can be determined as the target number of system requests per second for the search term; correspondingly, a preset global threshold for the number of system requests per second can be used as the target threshold. The caching service is used to execute a caching method; that is, in a specific implementation, the caching service can be deployed on multiple servers to execute the caching method, and counting the number of system requests per second for the search term on a single server can be equivalent to counting the number of system requests per second for the search term on the local server.

[0055] For example, in a music search scenario, when a popular query occurs, each machine in the search service will be requested a large number of identical queries. To calculate the global query QPS of popular queries in a low-cost manner, this application embodiment automatically obtains the number of cache service machines by counting the single-machine query QPS, thereby approximating the global query QPS. For counting the single-machine query QPS, this application uses a Bloom filter. A Bloom filter consists of a contiguous storage space and a series of hash functions, used to check whether an element is in a set. When an element is added to the set, it is mapped to K points in a bit array using K hash functions, and these points are set to 1. During retrieval, it is only necessary to check whether all these points are 1 to determine whether the corresponding element exists in the set: if any of these points are 0, the retrieved element is definitely not present. Its advantages are that its space efficiency and query time far exceed those of general algorithms, while its disadvantage is that it has a certain false positive rate, but this is acceptable in a music search scenario. For queries with a QPS exceeding a specified threshold, their search results are written to local memory for caching. This enables caching of search results for a very small number of frequently accessed queries under specific circumstances (such as new song releases or event premieres). In this embodiment, the Bloom filter used can count the QPS of a massive number of queries with a small capacity. The counting method involves taking the cache key as input and outputting the current count value mapped to the Bloom filter for that cache key. This value determines whether to enable the caching function subsequently.

[0056] In another implementation, the number of system requests for the search term within one second on a single server deploying the caching service can be counted as the target number of system requests for the search term within one second; correspondingly, the ratio of a preset global threshold for the number of system requests within one second to the total number of servers deploying the caching service is used as the target threshold. Specifically, the number of system requests for the search term within one second on a local server can be counted. For example, see... Figure 3 As shown, Figure 3 This is a schematic diagram illustrating a method for determining hot search terms disclosed in an embodiment of this application. The method involves determining whether the local query QPS reaches the globally allocated threshold to enable caching: assuming there are 3 servers deploying the caching service.

[0057] Step S13: If the current time is less than the cache expiration time and the current time is greater than or equal to the cache refresh time, then extend the cache expiration time, return the historical search results hit in the local cache, initiate a search to obtain the search results, and write the search results into the local cache.

[0058] In this embodiment, if the search term meets preset hotspot conditions and the search term does not hit the local cache, a search is initiated to obtain the search result, which is then written to the local cache. The cache write time, cache refresh time, and cache expiration time are then updated. The cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time. The first preset value is greater than the second preset value. The cache write time is the time it takes to write the search result to the local cache. Both the first and second preset values ​​are empirical values, for example, the first preset value is 0.5 seconds and the second preset value is 1 second. The extension duration of the cache expiration time is also an empirical value, such as 0.5 seconds. It is understood that each time a search result is written to the cache, the cache write time, cache refresh time, and cache expiration time are recorded. It should be noted that existing caching solutions do not distinguish between hot and non-hot data when caching. In order to avoid the cache from expiring too quickly and causing excessive pressure on downstream devices, the cache expiration time is usually set to be relatively long, such as 5 minutes. This application only caches hot data, and only allows one request to penetrate downstream when the cache is about to expire. This allows for a shorter cache expiration time, which also facilitates the timely removal of search results that have not been refreshed.

[0059] In this embodiment, cached search results are stored in memory using a key-value storage structure. The cache key is a unique key generated based on the user request parameters, and the sorted result list (i.e., search results) is then written to it. The cache key can be used to check whether the corresponding search result is cached in memory.

[0060] Furthermore, if the search term does not meet the preset hotspot conditions, a search is initiated to obtain the search result, but the search result is not cached in the local cache. In this way, the local cache only caches search results for hotspot search terms, and does not store search results for non-hotspot search terms in the local cache. For non-hotspot queries, this avoids affecting personalized ranking and experimental ranking, because personalized ranking and experimental ranking functions are implemented in the search server. If the search results for non-hotspot queries are also stored in the local cache, the search will not be initiated downstream after a local cache hit, and search results cannot be obtained based on user profiles.

[0061] If the search term meets preset hotspot conditions and the search term hits the local cache, the method further includes: if the current time is greater than or equal to the cache expiration time, initiating a search to obtain a search result, writing the search result to the local cache, and updating the cache write time, cache refresh time, and cache expiration time. Furthermore, if the current time is greater than or equal to the cache expiration time, after initiating the search, the method further includes: if the request fails, returning the historical search results that were hit in the local cache.

[0062] If the current time is less than the cache refresh time, the historical search results found in the local cache will be returned without initiating a search. In other words, the data in the current local cache is relatively new and can be used.

[0063] Furthermore, this application embodiment can also utilize external storage devices to store the search results for all search terms, including search results for both hot and non-hot search terms. When the load on the search server cluster exceeds a preset threshold, the system uses both local cache and data stored in external storage devices to first search in the local cache. If no results are found, the system searches from the external storage devices, thereby improving system stability.

[0064] As can be seen, the embodiments of this application automatically determine whether the search terms meet the preset hot spot conditions, and save the search results of hot search terms through local caching. By recording the cache write time and setting the cache refresh time and cache expiration time, when the current time is greater than or equal to the cache refresh time but less than the cache expiration time, i.e. when the current time is close to the cache expiration time, the search refresh cache is initiated in a timely manner, and the cache expiration time is extended. Only one request is allowed to penetrate downstream to refresh, avoiding a large number of requests penetrating downstream at the moment of cache expiration, which could lead to system failure. In this way, it can automatically cope with the sudden increase in the number of requests for hot search terms, avoid excessive downstream request pressure, and improve the stability of the search system.

[0065] The following example, a music search scenario, further illustrates the caching solution provided in this application. In music search, due to the personalized or experimental sorting functions of the music search system, even with the same search terms, different users may obtain different sorting results. Therefore, caching the final search results under normal circumstances is not suitable, as it would result in all sorted results being identical. Furthermore, search results need to be real-time, meaning new content needs to be displayed to users promptly, such as users needing to listen to or purchase new albums on time. Therefore, long-term caching of search results is also unsuitable, otherwise new albums might not be found by users on time. Due to these two limitations, currently, the business temporarily expands the capacity of various downstream interface modules of the search system before the launch of an event or after a surge in popularity to support sudden traffic increases. However, this operation is lagging and cannot cope with unknown sudden traffic surges. If the sudden surge in requests has reached the system's limit, the system may have already crashed and unable to maintain service. See also... Figure 4 As shown, Figure 4 This is a specific caching diagram provided for an embodiment of this application. To automatically handle sudden increases in requests for trending queries and ensure the stability of the search system while meeting the requirements of daily personalized sorting and timely updates of trending content, this application provides a near real-time trending caching scheme for the search system:

[0066] Based on the characteristics of hot queries in the music search service and the timeliness characteristics of music search results, (1) Characteristics of hot queries in the music search service: When a hot query appears, a large number of the same queries are requested to each machine of the search service. In order to statistically calculate the global QPS of hot queries in a low-cost manner, this application approximately calculates the global query QPS by statistically calculating the single-machine query QPS and automatically obtaining the number of cache service machines. For statistically calculating the single-machine query QPS, a Bloom filter is used to statistically calculate the query QPS. For queries with a QPS exceeding the specified threshold, their search results are written into the local memory for caching, realizing the caching of search results for a very small number of hot queries in specific cases. (2) Timeliness characteristics of music search results: The music search service belongs to a quasi-real-time scenario facing users, not requiring precise real-time. A delay of 1 second can be approximately considered imperceptible to users. Accordingly, this application proposes a cache asynchronous update strategy. Its basic idea is as follows: Set the cache refresh time, which is between the cache write time and the cache expiration time. This time is defined as being relatively close to the cache expiration time but still within the time range acceptable to the service. At this time, it is allowed for requests to penetrate downstream for search updates, and the cache results are first returned to the user. In addition, to avoid cache breakdown, the cache expiration time is briefly extended, and it is restricted that a query can only be refreshed once. Based on the above strategy, three variables are defined: cache write time Ta, cache refresh time Tb, and cache expiration time Tc. The magnitude relationship of the three values is: Ta < Tb < Tc. When the cache result is obtained according to the cache key (i.e., the unique key generated based on the user request parameters), record the current time as t. If t is between Ta and Tb, directly return the cache result to the user; if t is between Tb and Tc, first return the cache result to the user, then request the downstream to refresh the cache result of the hot query, and restrict that a cache key can only be refreshed once; if t is after Tc, no longer use the cache result and definitely request the downstream to perform cache refresh. Based on the actual empirical values in the music search scenario, the cache refresh time can be set to Ta + 0.5 seconds, and the cache expiration time Tc can be set to Ta + 1 second. This can perform near-real-time asynchronous refreshing of the cache results for hot queries while withstanding sudden traffic.

[0067] Additionally, if t is after Tc, a cache refresh request will definitely be sent downstream. Furthermore, to avoid a surge in downstream requests due to refresh failures, cached results can be reused to provide disaster recovery capabilities in the event of request failures or timeouts, thereby better protecting the stability of the search system. It should be noted that request failures and timeouts generally occur when the search system experiences faults or internal errors while providing external services, making it unable to respond to client search requests. In such cases, cached results can be used as a disaster recovery measure and returned to the client.

[0068] Based on the characteristics of popular queries in the music field, a Bloom filter is used to count query QPS. For queries with QPS exceeding a certain threshold, their search results are cached, achieving the goal of counting massive query QPS with a small capacity. Furthermore, only popular queries are cached, thus not affecting daily personalized ranking. Given the time-sensitive nature of the music field, cache refresh and expiration times are set. When a popular query hits the cache, if it falls between the cache refresh and expiration times, the cached result is refreshed, and the expiration time is briefly extended to limit a cache key to only one refresh, achieving near real-time cache refresh and preventing cache breakdown. In addition to meeting daily personalized ranking needs, a local memory caching component is used to automatically handle sudden surges in requests for popular queries in a low-cost manner, and to promptly refresh the cached results for popular queries, improving search system stability while ensuring user experience. The solution provided in this application is not limited to the music search field and can be extended to search systems in other fields.

[0069] See Figure 5 As shown in the diagram, this application embodiment provides a system load effect diagram of an application caching method. After deploying the caching solution provided in this application on an online system, it can automatically cope with the surge in requests for hot queries in a low-cost manner while meeting daily personalized sorting needs, and promptly update the cached results of hot queries, thereby improving the stability of the search system while ensuring user experience. Figure 5 The horizontal axis represents time, and the vertical axis represents the number of requests. At 19:30, the number of requests reached 255,737, and the system was still able to run stably.

[0070] See Figure 6 As shown, Figure 6 A caching device provided in this application embodiment includes:

[0071] The search term extraction module 11 is used to extract the search terms in the search request when a search request is received;

[0072] The first judgment module 12 is used to determine whether the search term meets the preset hot spot conditions;

[0073] The cache matching module 13 is used to match search results from the local cache when the first condition judgment module determines that the search term meets the preset hot spot conditions; the local cache is used to store search results that meet the preset hot spot conditions.

[0074] The second judgment module 14 is used to determine whether the current time is less than the cache expiration time if the search term does not hit the local cache.

[0075] The third judgment module 15 is used to determine whether the current time is less than the cache refresh time if the second judgment module determines that the current time is less than the cache expiration time.

[0076] The cache expiration time extension module 16 is used to extend the cache expiration time if the third judgment module determines that the current time is greater than or equal to the cache refresh time.

[0077] The search module 17 is used to return the historical search results hit in the local cache after the third judgment module determines that the current time is greater than or equal to the cache refresh time, and to initiate a search to obtain the search results and write the search results into the local cache.

[0078] The cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time, wherein the first preset value is greater than the second preset value.

[0079] As can be seen, the embodiments of this application automatically determine whether the search terms meet the preset hot spot conditions, and save the search results of hot search terms through local caching. By recording the cache write time and setting the cache refresh time and cache expiration time, when the current time is greater than or equal to the cache refresh time but less than the cache expiration time, i.e. when the current time is close to the cache expiration time, the search refresh cache is initiated in a timely manner, and the cache expiration time is extended. Only one request is allowed to penetrate downstream to refresh, avoiding a large number of requests penetrating downstream at the moment of cache expiration, which could lead to system failure. In this way, it can automatically cope with the sudden increase in the number of requests for hot search terms, avoid excessive downstream request pressure, and improve the stability of the search system.

[0080] In a specific implementation, the first determination module specifically includes:

[0081] The target system request count submodule is used to count the target system request count for the search term within one second.

[0082] The threshold judgment submodule is used to determine that the search term meets the preset hotspot condition if the number of system requests within one second of the target is greater than the target threshold, otherwise it is determined that the search term does not meet the preset hotspot condition.

[0083] In one implementation, the target system request count submodule is specifically used for: obtaining the number of servers deploying the caching service; counting the number of system requests per second for the search term on a single server; determining the product of the number of servers and the number of system requests per second for the search term on a single server as the target system request count for the search term; and correspondingly, using a preset global system request count threshold as the target threshold.

[0084] In another implementation, the target system request count submodule is specifically used to: count the number of system requests for the search term within one second for a single server that deploys the caching service, and use this count as the target system request count for the search term; correspondingly, the ratio of a preset global system request count threshold within one second to the total number of servers that deploy the caching service is used as the target threshold.

[0085] The search module is also used for:

[0086] If the search term meets the preset hotspot conditions and the search term does not hit the local cache, a search is initiated to obtain the search result, and the search result is written to the local cache, updating the cache write time, cache refresh time, and cache expiration time.

[0087] If the search term does not meet the preset hotspot conditions, a search is initiated to obtain the search result, but the search result is not cached in the local cache.

[0088] If the search term meets the preset hotspot conditions and the search term hits the local cache, and if the current time is greater than or equal to the cache expiration time, a search is initiated to obtain the search result, and the search result is written to the local cache, updating the cache write time, cache refresh time, and cache expiration time.

[0089] If the current time is greater than or equal to the cache expiration time, then after initiating a search, if the request fails, the historical search results that were hit in the local cache will be returned.

[0090] If the current time is less than the cache refresh time, the historical search results hit in the local cache will be returned, and no search will be initiated.

[0091] Further, see Figure 7 As shown, Figure 7This application provides a system architecture diagram for an application caching method. Specifically, it may include: a cache server cluster, a search server cluster, and a number of user terminals that establish communication connections with the cache server cluster. The cache server cluster includes several servers deploying caching services, the search server cluster includes several servers deploying search services, and the user terminals include, but are not limited to, tablets, laptops, smartphones, and personal computers (PCs). A music app is installed on each user terminal.

[0092] In this application, the user terminal is used to obtain the search terms entered by the user, generate a search request, send it to the cache server cluster, and obtain the search results returned by the servers in the cache server cluster;

[0093] The steps performed by the servers in the cache server cluster include: when a search request is received, extracting the search terms from the search request; if the search terms meet preset hotspot conditions and the search terms hit the local cache, determining whether the current time is less than the cache expiration time; the local cache is used to store search results that meet the preset hotspot conditions; if the current time is less than the cache expiration time and the current time is greater than or equal to the cache refresh time, extending the cache expiration time, returning the historical search results that hit the local cache, initiating a search to obtain the search results, and writing the search results into the local cache; wherein, the cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time, and the first preset value is greater than the second preset value.

[0094] The servers in the search server cluster are used to perform searches after the cache server initiates a search, and obtain search results. The search service can provide personalized search results based on user profiles.

[0095] Furthermore, embodiments of this application also provide an electronic device. Figure 8 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be considered as any limitation on the scope of this application.

[0096] Figure 8 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the caching method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be a server.

[0097] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0098] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include the operating system 221, computer programs 222 and data 223 involved in the caching method, etc., and the storage method can be temporary storage or permanent storage.

[0099] The operating system 221 manages and controls the various hardware devices on the electronic device 20 and the computer program 222 to enable the processor 21 to perform operations and processing on the data 223 in the memory 22. The operating system 221 can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the caching method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0100] Furthermore, embodiments of this application also disclose a storage medium storing a computer program, which, when loaded and executed by a processor, implements the caching method steps disclosed in any of the foregoing embodiments.

[0101] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0102] Finally, it should be noted that in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0103] The above provides a detailed description of a caching method, device, and medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A caching method, characterized in that, include: When a search request is received, the search terms in the search request are extracted; If the search term meets the preset hotspot conditions and the search term hits the local cache, then determine whether the current time is less than the cache expiration time; The local cache is used to store search results that meet the preset hotspot conditions; If the current time is less than the cache expiration time and the current time is greater than or equal to the cache refresh time, then extend the cache expiration time, return the historical search results that were hit in the local cache, initiate a search to obtain the search results, and write the search results into the local cache. The cache expiration time is the time obtained by adding a first preset value to the cache write time, and the cache refresh time is the time obtained by adding a second preset value to the cache write time, wherein the first preset value is greater than the second preset value.

2. The caching method according to claim 1, characterized in that, Also includes: Count the number of system requests for the target of the search term within one second; If the number of system requests to the target within one second is greater than the target threshold, then the search term is determined to meet the preset hotspot condition; otherwise, the search term is determined not to meet the preset hotspot condition.

3. The caching method according to claim 2, characterized in that, The number of system requests for the target search term within one second is counted, including: Get the number of servers deploying the caching service; Count the number of system requests for the search term on a single server within one second; The product of the number of servers and the number of system requests per second for the search term on a single server is determined as the target number of system requests per second for the search term. Accordingly, the preset global system request count threshold within one second is used as the target threshold.

4. The caching method according to claim 2, characterized in that, The number of system requests for the target search term within one second is counted, including: The number of system requests for the search term within one second on a single server where the caching service is deployed is counted, and this count is taken as the target number of system requests for the search term within one second. Accordingly, the target threshold is the ratio of the preset global system request count threshold per second to the total number of servers deploying the caching service.

5. The caching method according to claim 1, characterized in that, Also includes: If the search term meets the preset hotspot conditions and the search term does not hit the local cache, a search is initiated to obtain the search result, and the search result is written to the local cache, updating the cache write time, cache refresh time, and cache expiration time.

6. The caching method according to claim 1, characterized in that, Also includes: If the search term does not meet the preset hotspot conditions, a search is initiated to obtain the search result, but the search result is not cached in the local cache.

7. The caching method according to claim 1, characterized in that, If the search term meets preset hotspot conditions and the search term hits the local cache, the method further includes: If the current time is greater than or equal to the cache expiration time, a search is initiated to obtain the search result, which is then written to the local cache, and the cache write time, cache refresh time, and cache expiration time are updated.

8. The caching method according to claim 7, characterized in that, If the current time is greater than or equal to the cache expiration time, the search will be followed by: If the request fails, the historical search results that were hit in the local cache will be returned.

9. The caching method according to claim 1, characterized in that, If the current time is less than the cache refresh time, the method further includes: Return the historical search results that were hit in the local cache, without initiating a search.

10. An electronic device, characterized in that, Includes memory and processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program to implement the caching method as described in any one of claims 1 to 9.

11. A computer-readable storage medium, characterized in that, Used to store computer programs, wherein the computer programs, when executed by a processor, implement the caching method as described in any one of claims 1 to 9.