Cache access method and device, equipment, storage medium and program product
By recording keywords and policies in cache query records, calculating hit weights and selecting target policies, the problem of low hit rate of existing cache access methods is solved, and cache access efficiency and resource utilization are improved.
Patent Information
- Application Number
- CN202410732997.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-12-17
AI Technical Summary
The existing cache access method is relatively single and cannot adapt to the actual usage of the cache, resulting in a low hit rate when querying cache.
By recording the keywords in the cache query record, query results and cache policies used, calculate the cache policy hit weight corresponding to each record, and automatically select the most appropriate target cache policy for access.
Improves the hit rate when querying cache, saves cache resources, and adapts to the real usage of cache.
Smart Images

Figure CN119149447A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a cache access method, device, equipment, storage medium and program product. Background Art
[0002] Cache is a storage medium located between the application and the storage backend. It has the characteristics of fast access speed and helps to reduce the time of data access. At present, the way to access the cache is relatively simple and cannot adapt to the actual usage of the cache, which leads to a low hit rate when querying the cache. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a cache access method, apparatus, device, storage medium and program product, which are used to improve the hit rate when querying the cache and save cache resources.
[0004] In order to achieve the above objectives, the present application embodiment adopts the following technical solutions:
[0005] In a first aspect, an embodiment of the present application provides a cache access method, including:
[0006] Obtain at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache;
[0007] Based on each cache query record, determining a hit weight of the first cache strategy corresponding to each cache query record;
[0008] Determine a first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record;
[0009] The cache is accessed based on the first target cache policy.
[0010] In a second aspect, an embodiment of the present application provides a cache access device, including:
[0011] An acquisition unit, configured to acquire at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache;
[0012] A first determining unit, configured to determine, based on each cache query record, a hit weight of the first cache strategy corresponding to each cache query record;
[0013] A second determining unit, configured to determine a first target cache strategy based on a hit weight of the first cache strategy corresponding to each cache query record;
[0014] An access unit is used to access the cache based on the first target cache policy.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0016] processor;
[0017] a memory for storing instructions executable by the processor;
[0018] The processor is configured to execute the instructions to implement the cache access method as described in the first aspect.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the cache access method described in the first aspect.
[0020] In a fifth aspect, an embodiment of the present application provides a computer program product, characterized in that the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps in the method described in the first aspect.
[0021] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:
[0022] Since the keywords recorded in the cache query record, the query results of the keywords, and the cache strategies used when querying the cache can reflect the actual usage of the cache, based on each cache query record, the hit weight of the cache strategy corresponding to each cache query record is determined, which can reflect which cache strategy can have a higher hit rate; based on the hit weight of the cache strategy corresponding to each cache query record, the most appropriate first target cache strategy that is adapted to the actual usage of the cache is automatically selected, and then the cache is accessed based on the first target cache strategy, which helps to improve the hit rate when querying the cache and save cache resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0024] Figure 1 A schematic diagram of an implementation environment applicable to a cache access method provided in an embodiment of the present application;
[0025] Figure 2A schematic diagram of a flow chart of a cache access method provided for an embodiment of the present application;
[0026] Figure 3 A flowchart of a cache access method provided for another embodiment of the present application;
[0027] Figure 4 A schematic diagram of the structure of a cache method device provided by an embodiment of the present application;
[0028] Figure 5 A schematic diagram of the structure of an electronic device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0030] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally represents that the objects associated with each other are in an "or" relationship.
[0031] Some concept descriptions:
[0032] FIFO: First in First out. The first data to enter the cache is replaced each time according to the order in which the data enters the cache, regardless of the frequency of previous access.
[0033] LRU: Least Recently Used. It replaces the data in the cache that has not been accessed for the longest time each time. It is widely used in practical applications.
[0034] LFU: Least Frequently Used. Each time the cache is replaced with the data with the least number of accesses, it is a single-dimension consideration for data access reviews.
[0035] 2Q: Two Queue. It is an extension of LRU. 2Q uses two cache queues, one is a FIFO queue and the other is an LRU queue.
[0036] KEY: The keyword used to query the cache.
[0037] Cache is a storage medium located between the application and the storage backend, which has the characteristic of fast access speed. In order to reduce data access time, some commonly used data of the storage backend is usually written into the cache. When the application reads data, it usually searches the cache for the required data first. If the required data exists in the cache, the application can directly read the data from the cache; if the required data does not exist in the cache, the application searches the storage backend for the required data. It can be seen that the hit rate when querying the cache is particularly important for improving data access speed.
[0038] However, the current cache access method is relatively simple and cannot adapt to the actual usage of the cache, which in turn leads to a low hit rate when querying the cache.
[0039] In order to solve the above technical problems, an embodiment of the present application proposes a caching method. Since the keywords recorded in the cache query record, the query results of the keywords, and the cache strategies used when querying the cache can reflect the actual usage of the cache, based on each cache query record, the hit weight of the cache strategy corresponding to each cache query record is determined, which can reflect which cache strategy can have a higher hit rate; based on the hit weight of the cache strategy corresponding to each cache query record, the most appropriate first target cache strategy that is adapted to the actual usage of the cache is automatically selected, and then the cache is accessed based on the first target cache strategy, which helps to improve the hit rate when querying the cache and save cache resources.
[0040] It should be understood that the cache access method provided in the embodiment of the present application can be executed by an electronic device, specifically by a processor of the electronic device. The electronic device referred to herein may include a terminal device, such as but not limited to a smart phone, a tablet computer, a laptop computer, a desktop computer, an intelligent voice interaction device, a smart home appliance, a smart watch, a vehicle terminal, an aircraft, etc.; or, the electronic device may also include a server, such as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0041] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0042] In order to facilitate the understanding of the technical solutions provided by the embodiments of the present application, firstly Figure 1 The implementation environment applicable to the cache access method provided in the embodiment of the present application is described. It should be understood that the cache access method provided in the embodiment of the present application is applicable to Figure 1The implementation environment shown is only an exemplary description and should not be understood as a limitation on the implementation environment to which the method is applicable.
[0043] like Figure 1 As shown, an implementation environment applicable to the cache access method provided in an embodiment of the present application includes: an application, a cache, a server, and a storage backend.
[0044] An application can be any application (APP) that provides services. A cache is a storage medium located between an application and a storage backend, such as a local memory located in an application, which has the characteristic of fast access speed. A storage backend is a storage unit located in the backend, which can include, but is not limited to, a database, etc. The server serves as a transit hub, responsible for the collaboration of the application, cache, and storage backend.
[0045] In order to improve the hit rate of query cache and reduce data access time, n cache strategies are set in the server, including but not limited to FIFO strategy, LRU strategy, LFU strategy and 2Q strategy. Figure 2 As shown, initially, the server selects a cache strategy to access and manage the cache. Specifically, the server adopts a default cache strategy to write some commonly used data in the storage backend into the cache for application access. When the application reads data, it first searches the cache for the required data. If the cache contains the data required by the application, the application can directly read the data from the cache. If the cache does not contain the required data, the application initiates a backend query request to the server. In response to the backend query request, the server queries the storage backend for the data required by the application and returns it to the application.
[0046] In addition, the server also monitors the query records for the cache in real time, including but not limited to the keywords used each time the cache is queried, the query results each time the cache is queried, and the cache strategy used, etc., and periodically evaluates the cache hit situation when accessing the cache using each cache strategy based on the cache query records before the current period. If the cache hit situation of the currently used cache strategy does not meet the requirements, a cache strategy with the best cache hit situation is reselected for the current period, and then in the current period, the cache is accessed based on the best cache strategy, that is, the data in the storage backend is written into the cache according to the best cache strategy, and some data in the cache is deleted, etc. Among them, the granularity of the period can be set according to actual needs, such as one minute, one hour, one day, one week, etc., and the embodiments of the present application are not limited to this.
[0047] In actual applications, the above functions of the server can be integrated into the SDK (Software Development Kit) to provide it to applications. In the SDK, the group cache can be configured by annotation or coding to intercept the interface or method that needs to be cached. At the same time, the SDK also provides a keyword pre-initialization interface. In this way, when the application queries the cache through a keyword, the SDK can intercept the keyword through the annotation and asynchronously pass it to the server for corresponding processing.
[0048] Based on the above implementation environment, the present application embodiment provides a cache access method. Figure 3 , is a flow chart of a cache access method provided by an embodiment of the present application, the method comprising the following steps:
[0049] S302: Obtain at least one cache query record.
[0050] In an embodiment of the present application, each time the application queries the cache, the server will record the keywords used in this query, the query results of this query (such as whether it hits the cache), and the current cache strategy for the cache, obtain the cache query record of this query and store it in the database for subsequent use.
[0051] As an example, at least one cache query record before the current time period can be periodically obtained. Each cache query record includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache. The query result of the keyword indicates whether the data corresponding to the keyword is queried from the cache. In practical applications, keywords and their corresponding data are usually stored in the form of key-value pairs, where the keyword is the key and the data corresponding to the keyword is the value.
[0052] In order to make the cache query record better reflect the actual usage of the cache, the cache query record obtained in the above S302 may include the query record of the application on the cache in the first historical period before the current period. The first historical period may be a historical period in the same period as the current period, for example, the current period is 11:00-12:00 on Monday, and the first historical period is 11:00-12:00 last Monday. Alternatively, the first historical period may also be a historical period adjacent to the current period, for example, the current period is 11:00-12:00 on February 1, and the first historical period includes 10:00-11:00 on February 1, 9:00-10:00 on February 1, etc.
[0053] The first cache strategy may be one of the following cache strategies: FIFO strategy, LRU strategy, LFU strategy, 2Q strategy, etc.
[0054] S304: Based on each cache query record, determine a hit weight of the first cache strategy corresponding to each cache query record.
[0055] The hit weight of the first cache strategy is used to represent the hit rate of the cache when the corresponding first cache strategy is used to access the cache. As an example, the larger the hit weight of the first cache strategy, the larger the hit rate of the cache when the first cache strategy is used to access the cache.
[0056] Since at least one cache query record can reflect the actual usage of the cache to a certain extent, determining the hit weight of the first cache strategy corresponding to each cache query record based on at least one cache query record can accurately reflect which cache strategy can have a higher hit rate.
[0057] In one implementation, the above S304 may include the following steps:
[0058] S341, determining multiple reference keywords from the keywords in at least one cache query record, and determining the proportion of each reference keyword in the query times of the multiple reference keywords.
[0059] For each reference keyword, the proportion of the reference keyword in the query times of multiple query keywords is also referred to as the query time proportion of the reference keyword.
[0060] As an example, all used keywords can be used as reference keywords; then, based on the reference keywords in at least one cache query record, the query times of each reference keyword are counted; for each reference keyword, the ratio between the query times of the reference keyword and the sum of the query times of all keywords is used as the query times ratio of the reference keyword.
[0061] As another example, in the case where the cache query record includes query records of querying the cache in the first period, the above S341 may include the following steps: adding the first keyword used in each cache query in the first period to a keyword set; obtaining the number of queries for each keyword in the keyword set in the second period; and selecting a keyword from the keyword set whose number of queries in the second period meets a preset screening condition as a reference keyword. The preset screening condition includes: the difference between the number of queries for the keyword in the second period and the number of queries for the keyword in the first period does not exceed the preset difference.
[0062] Furthermore, the number of queries for each reference keyword is counted; for each reference keyword, the ratio between the number of queries for the reference keyword and the sum of the number of queries for all keywords is taken as the ratio of the number of queries for the reference keyword.
[0063] In practical applications, the first period and the second historical period can be set according to actual needs. For example, the first period can be the first historical period mentioned above, and the second period can be a historical period concurrent with the first period, or a historical period before and adjacent to the first period.
[0064] For example, the keywords used in the query cache in the first period include A to F, and a keyword set {A, B, C, D, E, F} is obtained based on these keywords. In the keyword set, if the difference between the number of queries for keyword A in the second period and the number of queries for keyword A in the first period exceeds a preset difference, keyword A is deleted from the keyword set, and the remaining keywords B to F are used as reference keywords.
[0065] It is understandable that if the difference in the number of queries for a keyword between the first period and the second period exceeds a preset difference, it can be determined that this situation is caused by malicious cache query using the keyword or a sudden special event (such as a holiday event) in the first period. Since such malicious cache query situations are somewhat accidental and sudden, by clearing the keywords in such special situations, the interference of such special situations on subsequent cache strategy decisions can be eliminated.
[0066] S342: Determine a hit rate of a query using the second cache strategy based on the query result of the reference keyword and the second cache strategy used when the reference keyword is used to query the cache.
[0067] It is worth noting that, for each of the above-mentioned multiple reference keywords, the above-mentioned step S342 is executed, and the hit rate of the second cache strategy used when using each reference keyword to query the cache can be obtained.
[0068] As an example, by counting the second cache strategy used when querying the cache with each reference keyword, n cache strategies are obtained; for each cache strategy, based on the query results of the reference keyword and the second cache strategy used when querying the cache with the reference keyword, the number of times the reference keyword is used to query the cache (i.e., the number of queries corresponding to the reference keyword in the cache strategy) and the number of times the reference keyword is used to query the required data from the cache (i.e., the number of hits corresponding to the reference keyword in the cache strategy) are counted; then, the hit rate of the cache strategy query is determined by the ratio between the number of hits corresponding to the reference keyword in the cache strategy and the number of queries corresponding to the reference keyword in the cache strategy. The hit rate can represent the hit rate of the cache query using the reference keyword when the cache strategy is used.
[0069] For example, when the FIFO strategy is used, the cache is queried 20 times using keyword B, and the required data is found in the cache 10 times. It can be determined that when the cache is FIFO-enabled, the cache hit rate is 50%.
[0070] Here, only one example of the above S342 is shown. Of course, it should be understood that the above S342 can also be implemented in other ways, and the embodiment of the present application does not limit this.
[0071] S343: Determine a hit weight of the second cache strategy based on the query times ratio of the reference keyword and the hit rate of the second cache strategy query.
[0072] As an example, based on the product of the proportion of query times of the reference keyword and the hit rate of the second cache strategy query, the hit weight of the reference keyword using the second cache strategy is determined; the sum of the hit weights of all reference keywords using the second cache strategy is determined as the hit weight of the second cache strategy.
[0073] The hit weight of the reference keyword using the second cache strategy is used to indicate that, when the cache strategy is used for the cache, the reference keyword is used to query the hit status of the cache.
[0074] For example, Table 1 shows the query times of some reference keywords and the hit rate of querying the cache using the reference keywords when three cache strategies are used for the cache.
[0075] Table 1
[0076]
[0077] For cache strategy 1, taking reference keyword A as an example, the hit weight of reference keyword A using cache strategy 1 is: [15 / (15+20+30+40+50+66)]×80%=0.053. Similarly, the hit weights of other reference keywords using cache strategy 1 can be obtained. Further, the hit weights of reference keywords A to F in cache strategy 1 are summed to obtain the hit weight of cache strategy 1.
[0078] In this implementation, the reference keywords before the current time period, the proportion of query times of the reference keywords, and the hit rate of the reference keywords corresponding to each cache strategy can more accurately reflect the actual usage of the cache, such as the cache hit situation when each cache strategy is used to access the cache. Using these data to determine the hit weight of each cache strategy can more accurately reflect which cache strategy can have a higher hit rate in the current time period, thereby providing reliable data support for subsequent cache strategy decisions.
[0079] In another embodiment, the above S304 can also be implemented by deep learning technology. Specifically, at least one cache query record is input into a pre-trained weight prediction model to obtain a hit weight of a cache strategy corresponding to each cache query record, wherein the weight prediction model is trained based on sample cache query records and sample hit weights of cache strategies corresponding to the sample cache query records.
[0080] The embodiment of the present application shows some implementation methods of the above S304. Of course, it should be understood that the above S304 can also be implemented in other ways, and the embodiment of the present application does not limit this.
[0081] S306: Determine a first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record.
[0082] As an example, when at least one cache query record includes a cache query record before the current period, the first target cache strategy is used to access the cache in the current period.
[0083] As an example, the first cache strategy corresponding to at least one cache query record is counted to obtain multiple first cache query records, and the first cache strategy corresponding to the maximum hit weight can be selected from the multiple first cache strategies as the first target cache strategy. In this way, the highest hit rate of the query cache in the current period can be ensured.
[0084] As another example, a first cache strategy whose hit weight exceeds a preset weight, such as 50%, may be selected from multiple first cache strategies as the first target cache strategy. Of course, if there are multiple first cache strategies whose hit weight exceeds the preset weight, any first cache strategy may be randomly selected as the first target cache strategy.
[0085] In another embodiment of the present application, when the first cache strategy with the maximum hit weight is used as the first target cache strategy, the above-mentioned cache access method may also include: if the maximum hit weight is not less than the preset weight, the first cache strategy corresponding to the maximum hit weight is also determined as the second target cache strategy, and the second target cache strategy is used to access the cache within a third time period.
[0086] The third time period may be any time period after the current time period, such as a time period concurrent with the current time period, or a time period adjacent to the current time period.
[0087] For example, if the above-mentioned multiple first cache strategies include FIFO strategy, LRU strategy, LFU strategy and 2Q strategy, and the current time period is 21:00-22:00 on February 1, then 22:00-24:00 on February 1 can be used as the third time period. If the hit weight of the LRU strategy is calculated to be the largest based on at least one cache query record before the current time period, and exceeds the preset weight, then not only the LRU strategy is used as the first target cache strategy for the current time period, but also the LRU strategy is used as the second target cache strategy from 22:00 to 24:00 on February 1, and then when the third time period arrives, the LRU strategy is used to access the cache.
[0088] In this embodiment, after the maximum hit weight of multiple first cache strategies reaches the preset weight, the first cache strategy with the maximum hit weight can already ensure a high cache hit rate and cache utilization. In this case, continuing to use the first cache strategy corresponding to the maximum hit weight in the current period and the period thereafter can avoid repeatedly executing the above cache access method in the next period, thereby saving computing resources and improving cache access efficiency.
[0089] S308: Access the cache based on the first target cache strategy.
[0090] As an example, if a cache write request from a first application is received, the first target data included in the cache write request is written into the cache based on the first target cache policy. For example, taking the first target cache policy as a FIFO policy, if a cache write request from an application is received, the first target data is written into the cache; if the size of the first target data exceeds the remaining available capacity of the cache, the earliest written data in the cache is deleted, and then the first target data is sequentially written into the cache.
[0091] If a query request from the first application is received, the second target data is obtained from the storage backend based on the target keyword included in the query request, and the second target data is written into the cache based on the first target cache policy. The query request is sent when the application does not find data matching the target keyword from the cache.
[0092] For example, taking the first target cache strategy as the LRU strategy, when the first application fails to find the second target data corresponding to the target keyword from the cache, it sends a query request carrying the target keyword to the server. The server reads the second target data corresponding to the target keyword from the storage backend and returns the second target data to the first application. In addition, in order to facilitate the application to quickly read the second target data during subsequent operation, the server also writes the second target data to the cache based on the LRU strategy; if the size of the second target data exceeds the remaining available capacity of the cache, the least recently used data in the cache is deleted, and then the second target data is sequentially written to the cache.
[0093] Considering that in actual applications, multiple applications may query the cache at the same time, and the keywords carried by different applications when querying the cache may be the same, but the demand data corresponding to the same keyword in different applications may be different. In this case, if the application from which the keyword comes is not distinguished, the query result will be inaccurate, for example, the demand data corresponding to the keyword from application A will be returned to application B as the query result.
[0094] In order to avoid interference between different applications in the process of querying the cache, in another embodiment of the present application, the keywords, cache strategies, etc. used to query the cache are distinguished according to the application. Specifically, the cache query record obtained by the server also includes the application identifier of the application that queries the cache, and the first target cache strategy includes a first sub-strategy, and the first sub-strategy corresponds to an application. Correspondingly, in the above S304, based on the application identifier, the at least one cache query record is divided into k groups of cache query records, each group of cache query records corresponds to an application; based on each group of cache query records, the hit weight of the application using the first cache strategy is determined. Further, in the above S306, based on the hit weight of the application using the first cache strategy, the first sub-strategy corresponding to the application is determined. Further, in the above S308, based on the first sub-strategy corresponding to the application, the data of the application in the cache is accessed.
[0095] For example, assuming that data of three applications are stored in the cache, the value of k is 3, and the multiple first cache strategies include a FIFO strategy, an LRU strategy, and an LFU strategy. At least one cache query record is shown in Table 2 below.
[0096] Table 2
[0097]
[0098] By grouping the cache query records 1 to 4 based on the application identifier, the following three groups can be obtained:
[0099] Group 1: Cache query record 1, Cache query record 2
[0100] Group 2: Cache query record 3
[0101] Group 3: Cache query record 4
[0102] For group 1, the above steps S304 to S306 are executed based on the cache query records in the group to obtain the first sub-strategy corresponding to application 1. For group 2, the above steps S304 to S306 are executed based on the cache query records in the group to obtain the first sub-strategy corresponding to application 2. For group 3, the above steps S304 to S306 are executed based on the cache query records in the group to obtain the first sub-strategy corresponding to application 3.
[0103] One or more embodiments of the present application provide a cache access method. Since the keywords recorded in the cache query record, the query results of the keywords, and the cache strategies used when querying the cache can all reflect the actual usage of the cache, based on each cache query record, the hit weight of the cache strategy corresponding to each cache query record is determined, which can reflect which cache strategy can have a higher hit rate. Based on the hit weight of the cache strategy corresponding to each cache query record, the most appropriate first target cache strategy that is adapted to the actual usage of the cache is automatically selected, and then the cache is accessed based on the first target cache strategy, which helps to improve the hit rate when querying the cache and save cache resources.
[0104] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0105] Based on the same inventive concept, the present application embodiment also provides an application processing device. Figure 4 , is a schematic diagram of a cache access device 400 provided in an embodiment of the present application. In a software implementation, the device 400 includes: an acquisition unit 410 , a first determination unit 420 , a second determination unit 430 , and an access unit 440 .
[0106] The acquisition unit 410 is configured to acquire at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache.
[0107] The first determining unit 420 is used to determine, based on each cache query record, a hit weight of the first cache strategy corresponding to each cache query record.
[0108] The second determining unit 430 is configured to determine a first target cache strategy based on a hit weight of the first cache strategy corresponding to each cache query record.
[0109] The access unit 440 is configured to access the cache based on the first target cache policy.
[0110] In another embodiment, the first determining unit is used to:
[0111] Determine, from the keywords in the at least one cache query record, a plurality of reference keywords and a proportion of each reference keyword in the query times of the plurality of reference keywords;
[0112] Determine a hit rate of querying using the second cache strategy based on a query result of the reference keyword and a second cache strategy used when querying the cache using the reference keyword;
[0113] The hit weight of the second cache strategy is determined based on the query frequency ratio of the reference keyword and the hit rate of the query of the second cache strategy.
[0114] In another embodiment, when determining the hit weights of the n cache strategies based on the query times proportions of the m reference keywords and the hit rates of the m reference keywords corresponding to the n cache strategies, the first determining unit performs the following steps:
[0115] Determining a hit weight of the reference keyword using the second cache strategy based on the product of the query count ratio of the reference keyword and the hit rate of the second cache strategy query;
[0116] The sum of the hit weights of all the reference keywords using the second cache policy is determined as the hit weight of the second cache policy.
[0117] In another embodiment, the cache query record includes a query record of querying the cache within a first period of time;
[0118] The multiple reference keywords are determined in the following manner:
[0119] Adding the first keyword used in each query of the cache during the first time period to a keyword set;
[0120] Obtaining the number of queries for each keyword in the keyword set within the second time period;
[0121] Selecting from the keyword set a keyword whose query times in the second time period meet a preset screening condition to obtain the reference keyword;
[0122] The preset screening condition includes: the difference between the number of queries for the historical keyword in the second time period and the number of queries for the first time period does not exceed a preset difference.
[0123] In another embodiment, the cache query record further includes an application identifier of the application querying the cache; the first target cache policy includes a first sub-policy, and the first sub-policy corresponds to an application;
[0124] The first determining unit is used for:
[0125] Based on the application identifier, the cache query record is divided into k groups of cache query records, each group of cache query records corresponding to an application;
[0126] Determining, based on each group of cache query records, a hit weight of the application using the first cache strategy;
[0127] The second determining unit is used for:
[0128] Based on the hit weight of the application using the first cache policy, a first sub-policy corresponding to the application is determined.
[0129] In another embodiment, the access unit is used to:
[0130] If a cache write request of a first application is received, writing the first target data included in the cache write request into the cache based on the first target cache policy;
[0131] If a query request from a first application is received, second target data is obtained from the storage backend based on the target keyword included in the query request, and the second target data is written into the cache based on the first target cache strategy. The query request is sent by the application when no data matching the target keyword is found in the cache.
[0132] In another embodiment, the second determining unit is used to:
[0133] Determine a first cache strategy corresponding to the maximum hit weight as the first target cache strategy;
[0134] The second determining unit is further configured to:
[0135] After determining the first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record, if the maximum hit weight is not less than the preset weight, the first cache strategy corresponding to the maximum hit weight is determined as the second target cache strategy, and the second target cache strategy is used to access the cache within a third time period.
[0136] Obviously, the cache access device 400 provided in the embodiment of the present application can be used as the above Figure 3 The execution body of the cache access method shown in FIG. Figure 3 The functions realized are as follows. Since the principles are the same, they will not be described in detail.
[0137] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. Figure 5 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0138] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0139] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.
[0140] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a cache access device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations:
[0141] Obtain at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache;
[0142] Based on each cache query record, determining a hit weight of the first cache strategy corresponding to each cache query record;
[0143] Determine a first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record;
[0144] The cache is accessed based on the first target cache policy.
[0145] The above application Figure 3 The method performed by the cache access device disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in software form. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0146] The electronic device may also perform Figure 3 The method and the cache access device are implemented in Figure 3 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.
[0147] Of course, in addition to software implementation methods, the electronic device of the present application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0148] The embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 3 The method of the embodiment shown is specifically used to perform the following operations:
[0149] Obtain at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache;
[0150] Based on each cache query record, determining a hit weight of the first cache strategy corresponding to each cache query record;
[0151] Determine a first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record;
[0152] The cache is accessed based on the first target cache policy.
[0153] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps in the cache access method provided in the embodiment of the present application.
[0154] In short, the above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0155] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0156] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0157] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0158] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
Claims
1. A cache access method, characterized in that: include: Obtain at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache; Based on each cache query record, determining a hit weight of the first cache strategy corresponding to each cache query record; Determine a first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record; The cache is accessed based on the first target cache policy.
2. The method according to claim 1, characterized in that The step of determining the hit weight of the cache policy corresponding to each cache query record based on each cache query record includes: Determine a plurality of reference keywords from the keywords in the at least one cache query record, and determine a proportion of the query times of each of the reference keywords in the query times of the plurality of reference keywords; Determine a hit rate of querying using the second cache strategy based on a query result of the reference keyword and a second cache strategy used when querying the cache using the reference keyword; The hit weight of the second cache strategy is determined based on the query frequency ratio of the reference keyword and the hit rate of the second cache strategy query.
3. The method according to claim 2, characterized in that The determining the hit weight of the second cache strategy based on the query frequency ratio of the reference keyword and the hit rate of the query of the second cache strategy includes: Determining a hit weight of the reference keyword using the second cache strategy based on the product of the query count ratio of the reference keyword and the hit rate of the second cache strategy query; The sum of the hit weights of all the reference keywords using the second cache policy is determined as the hit weight of the second cache policy.
4. The method according to claim 2, characterized in that: The cache query record includes a query record of querying the cache within a first period; Determining a plurality of reference keywords from the keywords in the at least one cache query record comprises: Adding the first keyword used in each query of the cache during the first time period to a keyword set; Obtaining the number of queries for each keyword in the keyword set within the second time period; Selecting from the keyword set a keyword whose query times in the second time period meet a preset screening condition to obtain the reference keyword; The preset screening condition includes: the difference between the number of queries for the keyword in the second time period and the number of queries for the keyword in the first time period does not exceed a preset difference.
5. The method according to claim 1, characterized in that The cache query record also includes an application identifier of the application that queries the cache; the first target cache policy includes a first sub-policy, and the first sub-policy corresponds to an application; The determining, based on each cache query record, a hit weight of the first cache strategy corresponding to each cache query record includes: Based on the application identifier, the cache query record is divided into k groups of cache query records, each group of cache query records corresponding to an application; Determining, based on each group of cache query records, a hit weight of the application using the first cache strategy; The determining of the first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record includes: Based on the hit weight of the application using the first cache policy, a first sub-policy corresponding to the application is determined.
6. The method according to claim 1, characterized in that Accessing the cache based on the first target cache policy includes: If a cache write request of a first application is received, writing the first target data included in the cache write request into the cache based on the first target cache policy; If a query request from a first application is received, second target data is obtained from the storage backend based on the target keyword included in the query request, and the second target data is written into the cache based on the first target cache strategy. The query request is sent by the application when no data matching the target keyword is found in the cache.
7. The method according to any one of claims 1 to 6, characterized in that The determining of the first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record includes: Determine a first cache strategy corresponding to the maximum hit weight as the first target cache strategy; After determining the first target cache strategy based on the hit weight of the first cache strategy corresponding to each cache query record, the method further includes: If the maximum hit weight is not less than the preset weight, the first cache strategy corresponding to the maximum hit weight is determined as the second target cache strategy, and the second target cache strategy is used to access the cache within a third time period.
8. A cache access device, characterized in that: include: An acquisition unit, configured to acquire at least one cache query record, each of which includes a keyword used to query the cache, a query result of the keyword, and a first cache strategy used when querying the cache; A first determining unit, configured to determine, based on each cache query record, a hit weight of the first cache strategy corresponding to each cache query record; A second determining unit, configured to determine a first target cache strategy based on a hit weight corresponding to each cache query record and based on the first cache strategy; An access unit is used to access the cache based on the first target cache policy.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the cache access method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the cache access method as claimed in any one of claims 1 to 7.
11. A computer program product, characterized in that The computer program product comprises a non-transitory computer-readable storage medium storing a computer program, wherein the computer program is operable to cause a computer to execute part or all of the steps in the method according to any one of claims 1 to 7.
