Browser multi-level cache strategy management method and device and medium
Through the dynamic adjustment of multi-level cache levels and weight attributes, the problem of low cache management accuracy in the existing technology is solved, the flexible response to complex access patterns and the reduction of cache jitter are achieved, and the cache hit rate and efficiency are improved.
Patent Information
- Application Number
- CN202411088559.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-10-18
AI Technical Summary
Existing data caching technologies, such as the least recently used policy and the first-in-first-out policy, are difficult to effectively manage frequently accessed hotspot data, resulting in cache jitter and low accuracy, and cannot flexibly cope with complex access patterns.
Adopting a multi-level cache strategy, by creating hot, warm, and cold cache levels, each level has different capacity and priority, and attaches weight attributes to cache items, and dynamically adjusts the cache level according to access frequency and data importance to improve caching. Hit rate and management accuracy.
Effectively reduce cache jitter caused by frequent data access, improve the accuracy and efficiency of cache management, flexibly respond to complex and changing access patterns, and achieve efficient and intelligent cache management.
Smart Images

Figure CN118797201A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of front-end processing technology, and in particular to a browser multi-level cache strategy management method, device and medium. Background Art
[0002] As the amount of data increases, the importance and application scenarios of data caching are also expanding and evolving. According to the increase in data volume, some data may become hot data, that is, data that is frequently accessed. In other words, data cache can effectively manage and store hot data, but in order to be able to flexibly adapt to complex access patterns, it is necessary to manage data caching strategies through multi-level cache.
[0003] Most existing data cache technologies use the least recently used strategy or the first-in-first-out strategy. In practical applications, the least recently used strategy cannot handle frequently accessed data well, which may cause cache jitter, cannot distinguish the popularity and importance of data, and is difficult to deal with complex access patterns. The first-in-first-out strategy cannot consider the access frequency and popularity of data, and is easy to clear important data, which may lead to an overly single data cache management method, resulting in low accuracy in data cache management. Summary of the invention
[0004] The present invention provides a browser multi-level cache strategy management method, device and medium, the main purpose of which is to solve the problem of low accuracy when performing data cache management.
[0005] To achieve the above object, the present invention provides a browser multi-level cache strategy management method, comprising:
[0006] Creating a hot cache of a high-level access frequency according to a preset first cache capacity, creating a warm cache of a medium-level access frequency according to a preset second cache capacity, creating a cold cache of a low-level access frequency according to a preset third cache capacity, and generating a three-level cache through the hot cache, the warm cache, and the cold cache;
[0007] When the browser receives a data write request, it extracts the data value and data weight of the write data item corresponding to the data write request, and determines whether the write data item is written into any cache level in the three-level cache according to the data value and the data weight;
[0008] When the write data item is written into any cache level in the three-level cache, the final cache level in the three-level cache into which the write data item is written is determined according to the cache capacity of the write cache level corresponding to the write data item, and the write data item is written into the final cache level;
[0009] When the browser receives a data read request, the cache data corresponding to the data read request in the third-level cache is read according to the key value of the target data corresponding to the data read request.
[0010] Optionally, the step of creating a hot cache of a high-access frequency according to a preset first cache capacity includes:
[0011] Configure the storage key name of the hot cache and initialize the cache objects in the configured hot cache;
[0012] Determining the number of cache objects according to a preset first cache capacity;
[0013] A hot cache with high access frequency is created by using the storage key name and the number of cache objects.
[0014] Optionally, generating a three-level cache by using the hot cache, the warm cache, and the cold cache includes:
[0015] Using the hot cache as a first-level cache, using the warm cache as a second-level cache, and using the cold cache as a third-level cache;
[0016] A three-level cache is generated according to the cache order of the first-level cache, the second-level cache, and the third-level cache.
[0017] Optionally, extracting a data value and a data weight of a write data item corresponding to the data write request includes:
[0018] Extracting write request parameters corresponding to the data write request;
[0019] Determine the key value corresponding to the write data item according to the write request parameter;
[0020] The data value and data weight of the written data item are extracted according to the key value.
[0021] Optionally, determining whether the write data item is written into any cache level in the three-level cache according to the data value and the data weight includes:
[0022] Determining whether the data weight corresponding to the data value of the written data item is a high weight;
[0023] When the data weight of the written data item is a high weight, determining the cache level of the written data item to be a hot cache in the three-level cache;
[0024] When the data weight of the written data item is not a high weight, determining whether the data weight of the written data item is a medium weight;
[0025] When the data weight of the written data item is a medium weight, determining that the cache level of the written data item is a warm cache in the three-level cache;
[0026] When the data weight of the write data item is not a medium weight, it is determined that the cache level of the write data item is a cold cache in the three-level cache.
[0027] Optionally, determining the final cache level of the written data item in the three-level cache according to the cache capacity of the written cache level corresponding to the written data item includes:
[0028] When the write cache level is a hot cache, judging whether the cache capacity of the hot cache is full according to the cache capacity of the hot cache, and when the cache capacity of the hot cache is not full, determining the hot cache in the three-level cache as the final cache level of the write data item;
[0029] When the cache capacity of the hot cache is full, cache data with the smallest data weight in the hot cache is moved to the warm cache in the three-level cache, and the moved hot cache is determined as the final cache level of the written data item;
[0030] When the write cache level is a warm cache, judging whether the cache capacity of the warm cache is full according to the cache capacity of the warm cache, and when the cache capacity of the warm cache is not full, determining the warm cache in the three-level cache as the final cache level of the write data item;
[0031] When the cache capacity of the warm cache is full, the cache data with the smallest data weight in the warm cache is moved to the cold cache in the three-level cache, and the moved warm cache is determined as the final cache level of the written data item;
[0032] When the write cache level is a cold cache, judging whether the cache capacity of the cold cache is full according to the cache capacity of the cold cache, and when the cache capacity of the cold cache is not full, determining the cold cache in the three-level cache as the final cache level of the write data item;
[0033] When the cache capacity of the cold cache is full, cache data with the smallest data weight in the cold cache is deleted, and the deleted warm cache is determined as the final cache level of the written data item.
[0034] Optionally, reading cache data corresponding to the data read request in the third-level cache according to the key value of the target data corresponding to the data read request includes:
[0035] Extracting the cache key value corresponding to each cache level in the three-level cache;
[0036] Comparing the cache key value with the key value of the target data corresponding to the data read request;
[0037] Determine the cache level corresponding to the target data according to the compared key value;
[0038] The data weight corresponding to the cache level is superimposed with a preset data threshold, and it is determined whether the superimposed data weight reaches the preset cache weight;
[0039] When the weight of the superimposed data reaches a preset cache weight, the cache level is updated to a cache level corresponding to the preset cache weight;
[0040] The cache data corresponding to the data read request is read in the updated cache level.
[0041] Optionally, reading cache data corresponding to the data read request in the updated cache level includes:
[0042] Extract the data weight corresponding to each data in the updated cache level;
[0043] Sort the data weights in descending order;
[0044] The data with the largest weight after the read sorting is the cache data corresponding to the data read request.
[0045] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0046] at least one processor; and,
[0047] a memory communicatively connected to the at least one processor; wherein,
[0048] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the above-mentioned browser multi-level cache policy management method.
[0049] In order to solve the above problems, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned browser multi-level cache policy management method.
[0050] The embodiment of the present invention is divided into hot, warm and cold cache levels, each level has different capacity and priority. Through multi-level cache level management, the cache jitter problem caused by frequent data access can be effectively reduced; each cache item is accompanied by a weight attribute, and the weight is dynamically adjusted according to the access frequency and data importance. The data level is dynamically adjusted based on the access frequency and data heat to improve cache hits. Through the multi-dimensional priority model, the cache strategy can flexibly respond to complex and changeable access patterns. Using multiple levels and weights, the cache is dynamically managed, which is efficient and intelligent. Therefore, the browser multi-level cache strategy management method, device and medium proposed in the present invention can solve the problem of low accuracy when managing data cache. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 A flowchart of a browser multi-level cache strategy management method provided by an embodiment of the present invention;
[0052] Figure 2 A schematic diagram of a process for initializing a cache according to an embodiment of the present invention;
[0053] Figure 3 A schematic diagram of a process of writing data into a cache according to an embodiment of the present invention;
[0054] Figure 4 A schematic diagram of a process of reading data cache provided by an embodiment of the present invention;
[0055] Figure 5 A schematic diagram of the structure of an electronic device for implementing the browser multi-level cache policy management method provided by an embodiment of the present invention.
[0056] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0057] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0058] The embodiment of the present application provides a browser multi-level cache policy management method. The execution subject of the browser multi-level cache policy management method includes but is not limited to at least one of the electronic devices such as the server, the terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the browser multi-level cache policy management method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
[0059] Reference Figure 1 FIG. 1 is a flow chart of a browser multi-level cache policy management method provided by an embodiment of the present invention. In this embodiment, the browser multi-level cache policy management method includes:
[0060] S1. Create a hot cache of high-level access frequency according to a preset first cache capacity, create a warm cache of medium-level access frequency according to a preset second cache capacity, create a cold cache of low-level access frequency according to a preset third cache capacity, and generate a three-level cache through the hot cache, the warm cache and the cold cache.
[0061] In the embodiment of the present invention, the hot cache refers to data that is recently accessed or frequently accessed and has a fast response speed, and the first cache capacity refers to the cache capacity of the hot cache.
[0062] In the embodiment of the present invention, the step of creating a hot cache with a high access frequency according to a preset first cache capacity includes:
[0063] Configure the storage key name of the hot cache and initialize the cache objects in the configured hot cache;
[0064] Determining the number of cache objects according to a preset first cache capacity;
[0065] A hot cache with high access frequency is created by using the storage key name and the number of cache objects.
[0066] In detail, first define the key name used to store hot cache data in localStorage, such as const CACHE_HOT = 'hotCache', and initialize an empty hot cache object, that is, create an empty pair of items to store hot cache data, such as const hotCache = {}, and configure the storage capacity of the hot cache according to the preset cache capacity of the hot cache, that is, the number of cache objects included, and finally create a hot cache according to the storage key name and the number of cache objects.
[0067] Specifically, the steps of creating a warm cache according to a preset second cache capacity and creating a cold cache according to a preset third cache capacity are consistent with the steps of creating a hot cache according to a preset first cache capacity, and are not repeated here. The warm cache refers to data that is relatively infrequently accessed, but is not as frequently accessed as the data in the hot cache, and has a slower response speed. The cold cache refers to data that is rarely accessed and has a slower access speed. The second cache capacity refers to the cache capacity of the warm cache, and the third cache capacity refers to the cache capacity of the cold cache.
[0068] Furthermore, in order to enable the cache strategy to flexibly respond to complex and changeable access patterns and effectively reduce cache jitter problems caused by frequent data access, it is necessary to implement multi-level cache hierarchy management. Therefore, a multi-level cache hierarchy is constructed based on hot cache, warm cache and cold cache.
[0069] In an embodiment of the present invention, the three-level cache refers to a cache constructed based on a hot cache, a warm cache, and a cold cache, wherein the hot cache is used as a first-level cache, the warm cache is used as a second-level cache, and the cold cache is used as a third-level cache, aiming to maximize overall performance and efficiency by achieving a balance between different speeds and capacities.
[0070] In the embodiment of the present invention, generating a three-level cache by using the hot cache, the warm cache, and the cold cache includes:
[0071] Using the hot cache as a first-level cache, using the warm cache as a second-level cache, and using the cold cache as a third-level cache;
[0072] A three-level cache is generated according to the cache order of the first-level cache, the second-level cache, and the third-level cache.
[0073] In detail, Hot Cache is used as the first-level cache to store the most frequently accessed data, with a capacity of 1,000 items; Warm Cache is used as the second-level cache to store data that is relatively infrequently but still frequently accessed, with a capacity of 5,000 items; Cold Cache is used as the third-level cache to store data that is infrequently accessed and has a large data volume, with a capacity of 10,000 items, thereby building a three-level cache based on different levels of cache. Each cache level manages data according to its own capacity and access frequency, ensuring that frequently accessed data is kept up to date and quickly accessed in the hot cache, while less frequent and large-capacity data is stored in the cold cache.
[0074] Specifically, Figure 2 As shown, it is a flow chart of initializing cache, firstly, hot cache, warm cache and cold cache are defined, and the upper limits of cache capacity of hot cache, warm cache and cold cache are set, then it is judged whether hot cache has been created in advance, if not, hot cache is created, if hot cache has been created or after hot cache is created, it is judged whether warm cache has been created in advance, if not, warm cache is created, if warm cache has been created or after warm cache is created, it is judged whether cold cache has been created in advance, if not, cold cache is created, if cold cache has been created or after cold cache is created, thus obtaining the three-level cache corresponding to hot cache, warm cache and cold cache after initialization.
[0075] Furthermore, through multi-level cache hierarchy management, the cache jitter problem caused by frequent data access can be effectively reduced. When receiving data write or read requests, the data hierarchy can be dynamically adjusted based on the access frequency and data heat to improve cache hits.
[0076] S2. When the browser receives a data write request, it extracts the data value and data weight of the write data item corresponding to the data write request, and determines whether the write data item is written to any cache level in the three-level cache based on the data value and the data weight.
[0077] In an embodiment of the present invention, when the browser receives a data write request, it customizes the data value data of the cache item corresponding to the write request and the weight weight of the cache item. The weight of the cache item is used to represent the importance of the data or frequently accessed data. The higher the weight, the more frequently the data is accessed.
[0078] In the embodiment of the present invention, extracting the data value and the data weight of the write data item corresponding to the data write request includes:
[0079] Extracting write request parameters corresponding to the data write request;
[0080] Determine the key value corresponding to the write data item according to the write request parameter;
[0081] The data value and data weight of the written data item are extracted according to the key value.
[0082] In detail, the key value corresponding to the write data item corresponding to the data write request can be determined according to the write request parameters (writeRequestParams) corresponding to the data write request, that is, the corresponding data value and data weight are customized for the write data item, that is, data: value, weight: weight, where the key value is an identifier corresponding to each write data item, and each write data item has a data value and data weight, so that the cache strategy can be dynamically adjusted according to the access frequency and data importance, thereby realizing intelligent cache management.
[0083] Furthermore, according to the data weight corresponding to the write data item, it can be determined into which level of cache in the three-level cache the value of the cache item should be written, so that high-frequency access and high-weight data can be cached first, thereby improving the cache hit rate and access speed.
[0084] In the embodiment of the present invention, the initial cache level refers to determining, based on the data weight of the cache item, in which cache of the hot cache, the warm cache, and the cold cache the written data item should be stored.
[0085] In the embodiment of the present invention, determining whether the written data item is written into any cache level in the three-level cache according to the data value and the data weight includes:
[0086] Determining whether the data weight corresponding to the data value of the written data item is a high weight;
[0087] When the data weight of the written data item is a high weight, determining the cache level of the written data item to be a hot cache in the three-level cache;
[0088] When the data weight of the written data item is not a high weight, determining whether the data weight of the written data item is a medium weight;
[0089] When the data weight of the written data item is a medium weight, determining that the cache level of the written data item is a warm cache in the three-level cache;
[0090] When the data weight of the write data item is not a medium weight, it is determined that the cache level of the write data item is a cold cache in the three-level cache.
[0091] In detail, first determine whether the data weight corresponding to the write data item is a high weight, and the high weight can be a data weight greater than 5, so the high weight can be custom configured. If the data weight of the write data item is greater than 5, the data weight corresponding to the write data item is a high weight, and the initial cache level of the write data item is determined to be a hot cache; when the data weight of the write data item is not a high weight, that is, the data weight is less than 5, then determine whether the data weight of the write data item is a medium weight, and the medium weight can be a data weight greater than 2 and less than 5. When the data weight of the write data item is greater than 2 and less than 5, the data weight corresponding to the write data item is a medium weight, and the initial cache level of the write data item is determined to be a warm cache; when the data weight of the write data item is not a medium weight, that is, the data weight is less than 2, then the initial cache level of the write data item is determined to be a cold cache.
[0092] Furthermore, the data weight of the cache item can be used to determine at which cache level of the three-level cache the written data item should be located. Since the number of caches in each cache level is limited, it is also necessary to determine the final cache level to which the written data item will be written based on the cache number and the determined initial cache level.
[0093] S3. When the write data item is written into any cache level in the three-level cache, the final cache level in the three-level cache into which the write data item is written is determined according to the cache capacity of the write cache level corresponding to the write data item, and the write data item is written into the final cache level.
[0094] In the embodiment of the present invention, the final cache level refers to the target cache level to which the write data item corresponding to the data write request is written, such as the target cache level being a hot cache, a warm cache or a cold cache.
[0095] In the embodiment of the present invention, determining the final cache level of the written data item in the three-level cache according to the cache capacity of the written cache level corresponding to the written data item includes:
[0096] When the write cache level is a hot cache, judging whether the cache capacity of the hot cache is full according to the cache capacity of the hot cache, and when the cache capacity of the hot cache is not full, determining the hot cache in the three-level cache as the final cache level of the write data item;
[0097] When the cache capacity of the hot cache is full, cache data with the smallest data weight in the hot cache is moved to the warm cache in the three-level cache, and the moved hot cache is determined as the final cache level of the written data item;
[0098] When the write cache level is a warm cache, judging whether the cache capacity of the warm cache is full according to the cache capacity of the warm cache, and when the cache capacity of the warm cache is not full, determining the warm cache in the three-level cache as the final cache level of the write data item;
[0099] When the cache capacity of the warm cache is full, the cache data with the smallest data weight in the warm cache is moved to the cold cache in the three-level cache, and the moved warm cache is determined as the final cache level of the written data item;
[0100] When the write cache level is a cold cache, judging whether the cache capacity of the cold cache is full according to the cache capacity of the cold cache, and when the cache capacity of the cold cache is not full, determining the cold cache in the three-level cache as the final cache level of the write data item;
[0101] When the cache capacity of the cold cache is full, cache data with the smallest data weight in the cold cache is deleted, and the deleted warm cache is determined as the final cache level of the written data item.
[0102] In detail, when the write cache level is hot cache, that is, the data weight of the write data item is high weight, then determine whether the cache capacity of the hot cache is full. If the cache capacity of the hot cache is not full, use the hot cache as the final write cache for the cache item corresponding to the data write request; if the cache capacity of the hot cache is full, it is necessary to clean up the oldest data in the hot cache and move the selected data to the next level of cache. The oldest data is the data with the smallest data weight in the hot cache, and the selected data with the smallest data weight is moved to the warm cache. At this time, the cache capacity in the hot cache is not full, and the moved hot cache is used as the final write cache for the cache item corresponding to the data write request.
[0103] Specifically, when the write cache level is a warm cache, that is, the data weight of the write data item is a medium weight, then determine whether the cache capacity of the warm cache is full. If the cache capacity of the warm cache is not full, use the warm cache as the final write cache for the cache item corresponding to the data write request; if the cache capacity of the warm cache is full, it is necessary to clean up the oldest data in the warm cache and move the selected data to the next cache layer. The oldest data is the data with the smallest data weight in the warm cache, and the selected data with the smallest data weight is moved to the cold cache. At this time, the cache capacity in the warm cache is not full, and the moved warm cache is used as the final write cache for the cache item corresponding to the data write request; when the write cache level is a cold cache, determine whether the cache capacity of the cold cache is full. If the cache capacity of the cold cache is not full, use the cold cache as the final write cache for the cache item corresponding to the data write request; if the cache capacity of the cold cache is full, delete the data with the smallest data weight in the cold cache. At this time, the cache capacity in the cold cache is not full, and the deleted cold cache is used as the final write cache for the cache item corresponding to the data write request.
[0104] Exemplarily, when a data write request is received, firstly, the data of hotCache, warmCache and coldCache are obtained from LocalStorage (a persistent storage mechanism provided by the browser, which allows key-value pair data to be stored in the browser. This data is shared between pages under the same domain name and can be persisted. It will not be lost even if the user closes the browser until it is explicitly deleted or the browser storage limit is exceeded). If there is no corresponding cache data, the default is an empty object {}, and then a cacheItem object is created according to the passed parameters key, value and weight, which includes the data value to be cached and the weight weight of the cache item, that is, const cacheItem = {data:value,weight:weight}, so according to the size of weight, decide in which cache area the cache item is stored. If weight>5, store the cache item in hotCache. If the number of hotCache items is less than MAX_HOT_CACHE_SIZE, add the cache item directly to hotCache and update the data in LocalStorage. Otherwise, call evictAndMoveToNextCache function to eliminate the data in hotCache and move it to warmCache, and then add the new cache item to hotCache. If weight>2 and weight<=5, Then store the cache item in warmCache, and check whether the number of items in warmCache exceeds MAX_WARM_CACHE_SIZE. If so, perform elimination and move operations, otherwise directly add new cache items to warmCache; if weight <= 2, store the cache item in coldCache; and check whether the number of items in coldCache exceeds MAX_COLD_CACHE_SIZE. If so, directly delete the data with the smallest weight, and then add new cache items to coldCache, that is, distribute data to different cache areas according to the weight value passed in, and execute the elimination strategy when each cache area reaches the maximum capacity to ensure the effective management and utilization of cache data. It is necessary to ensure that the evictAndMoveToNextCache function correctly implements the logic of cache elimination and movement to maintain the efficiency and correctness of the cache.
[0105] Further, when a data write request is received, the write cache tier and the final write cache tier are determined, such as Figure 3As shown, it is a flow chart of writing data into cache. First, two attributes are set for the cache item, namely, the value of the cache item and the weight of the cache item, and it is determined whether the cache item is of high weight. If so, it is determined whether the hot cache is full. If not, it is written into the hot cache. If so, the oldest data in the hot cache is cleared and moved to the next cache layer. If the cache item is not of high weight, it is determined whether the cache item is of medium weight. If so, it is determined whether the warm cache is full. If not, it is written into the warm cache. If so, the oldest data in the hot cache is cleared and moved to the next cache layer. If the cache item is not of medium weight, it is determined whether the cold cache is full. If not, it is written into the cold cache. If so, the minimum weight data in the cold cache is deleted and the data is written into the cold cache.
[0106] Furthermore, when a data write request is received, the data is written into the cache; when a data read request is received, the data is read from the cache, and therefore, the data read from the cache needs to be analyzed.
[0107] S4. When the browser receives a data read request, the browser reads cache data corresponding to the data read request in the third-level cache according to the key value of the target data corresponding to the data read request.
[0108] In an embodiment of the present invention, when the browser receives a data read request, it first determines in which cache area the data will be stored, and then extracts the request cache item corresponding to the data read request in the determined cache area, wherein the cache item refers to the request data corresponding to the data read request.
[0109] In the embodiment of the present invention, the step of reading cache data corresponding to the data read request in the third-level cache according to the key value of the target data corresponding to the data read request includes:
[0110] Extracting the cache key value corresponding to each cache level in the three-level cache;
[0111] Comparing the cache key value with the key value of the target data corresponding to the data read request;
[0112] Determine the cache level corresponding to the target data according to the compared key value;
[0113] The data weight corresponding to the cache level is superimposed with a preset data threshold, and it is determined whether the superimposed data weight reaches the preset cache weight;
[0114] When the weight of the superimposed data reaches a preset cache weight, the cache level is updated to a cache level corresponding to the preset cache weight;
[0115] The cache data corresponding to the data read request is read in the updated cache level.
[0116] In detail, whether the target data is in the hot cache in the three-level cache is determined according to the key value of the target data corresponding to the data read request; when the target data is in the hot cache, the data weight of the target data in the hot cache is superimposed with the preset data threshold, the hot cache is updated according to the superimposed data weight, and the cache item corresponding to the data read request is read in the updated hot cache; when the target data is not in the hot cache, whether the target data is in the warm cache is determined; when the target data is in the warm cache, the data weight of the target data in the warm cache is superimposed with the preset data threshold, and it is determined whether the data weight of the superimposed target data reaches the pre-set cache weight of the hot cache; when the data weight of the superimposed target data reaches the pre-set cache weight of the hot cache, the target data is moved to the hot cache, and the hot cache is updated according to the data weight of the target data after the move, and the cache item corresponding to the data read request is read in the updated hot cache; when the data weight of the superimposed target data is not When the preset cache weight of the hot cache is reached, the warm cache is updated according to the data weight of the superimposed target data, and the cache item corresponding to the data read request is read in the updated warm cache; when the target data is not in the warm cache, it is determined whether the target data is in the cold cache; when the target data is in the cold cache, the data weight of the target data in the cold cache is superimposed with a preset data threshold, and it is determined whether the data weight of the superimposed target data reaches the preset cache weight of the warm cache; when the data weight of the superimposed target data reaches the preset cache weight of the warm cache, the target data is moved to the warm cache, and the warm cache is updated according to the data weight of the target data after the move, and the cache item corresponding to the data read request is read in the updated warm cache; when the data weight of the superimposed target data does not reach the preset cache weight of the warm cache, the warm cache is updated according to the data weight of the superimposed target data, and the cache item corresponding to the data read request is read in the updated cold cache.
[0117] Specifically, the key value of the target data corresponding to the data read request is compared with the data key value in the third-level cache to determine whether the target data is in the hot cache. When it is found that the target data is in the hot cache, the data weight corresponding to the target data is increased by 1 (data threshold), and the hot cache is updated in descending order of data weight based on the target data after the increase by 1, so that the data can be read from the updated hot cache.
[0118] In the embodiment of the present invention, the step of reading cache data corresponding to the data read request in the updated cache level includes:
[0119] Extract the data weight corresponding to each data in the updated cache level;
[0120] Sort the data weights in descending order;
[0121] The data with the largest weight after the read sorting is the cache data corresponding to the data read request.
[0122] In detail, updatedHotCache is an updated hot cache object, which contains multiple cache items. Each cache item has a value and weight attribute. The weight attributes of all cache items are extracted from updatedHotCache and stored in the weights array. Then, the weights array is sorted from large to small using the sort method. The updatedHotCache is traversed to find the cache item whose weight is equal to the first element in the weights array (that is, the maximum weight). Once found, its data value and data weight are output, that is, the data value of the cache item with the largest data weight is read and returned from the updated hot cache.
[0123] Specifically, when the target data is not in the hot cache, determine whether the target data is in the warm cache. When it is found that the target data is in the warm cache, add 1 (data threshold) to the data weight corresponding to the target data in the warm cache, and determine whether the data weight at this time reaches the cache weight set for the hot cache based on the data weight of the target data after adding 1. When the data weight of the superimposed target data reaches the preset cache weight of the hot cache, move the target data to the hot cache according to the size of the data weight of the target data, and re-sort the data in the hot cache according to the size of the data weight of the target data after the move, so as to obtain an updated hot cache, and read the data from the updated hot cache; when the data weight of the superimposed target data does not reach the preset cache weight of the hot cache, re-sort the data in the warm cache according to the data weight, and read the cache item corresponding to the data read request in the updated warm cache; when the target data is not in the warm cache, determine whether the target data Whether it is in the cold cache. When it is queried that the target data is in the warm cache, the data weight corresponding to the target data in the warm cache is increased by 1 (data threshold), and the data weight of the target data after the increase by 1 is used to determine whether the data weight at this time reaches the cache weight set for the hot cache. When the data weight of the superimposed target data reaches the preset cache weight of the warm cache, the target data is moved to the warm cache according to the size of the data weight of the target data, and the data in the warm cache is re-sorted according to the size of the data weight of the target data after the move, so as to obtain an updated warm cache, and the data is read out from the updated warm cache; when the data weight of the superimposed target data does not reach the preset cache weight of the warm cache, the data in the cold cache is re-sorted according to the data weight, and the cache item corresponding to the data read request is read in the updated cold cache, wherein the target data can be extracted from the cache area through a computer statement with a data crawling function (such as a Java statement, a Python statement, etc.).
[0124] Exemplarily, when a data read request is received, three different types of cache data are first obtained from LocalStorage: hotCache, warmCache, and coldCache. If there is no relevant data in LocalStorage, the default is an empty object {}, and then the data of the specified key is searched from these three caches. If a cache item with the corresponding key is found in hotCache, the weight of the item is increased, the data in LocalStorage is updated, and the data of the cache item is returned; if a cache item with the corresponding key is found in warmCache, the weight is also increased. If the weight exceeds the set threshold (set to 5 here), the moveCache function is called to move the cache item from warmCache to hotCache, and update the warmCache data in LocalStorage; if a cache item with the corresponding key is found in coldCache, the weight is also increased. If the weight exceeds the set threshold (here set to 2), the moveCache function is called to move the cache item from coldCache to warmCache, and the coldCache data in LocalStorage is updated; if the cache item with the corresponding key is not found in all cache areas, null is returned, indicating that the cache data is not found, that is, the cache data is checked by priority and dynamically adjusted according to the weight of the cache item to achieve cache management and data access control.
[0125] Furthermore, when a data read request is received, data queries are performed in sequence according to the order of the three-level cache, such as Figure 4 As shown, it is a flowchart of reading data cache. First, determine whether the data is in the hot cache. If so, the hot cache weight is increased by 1 and the hot cache is updated. If not, determine whether the data is in the warm cache. If so, the warm cache weight is increased by 1, and it is determined whether the weight reaches the hot cache. If so, move to the hot cache and update the hot cache. If not, update the warm cache. If the data is not in the warm cache, the cold cache weight is increased by 1, and it is determined whether the weight reaches the warm cache. If so, move to the warm cache and update the warm cache. If not, update the cold cache.
[0126] Furthermore, after the target data corresponding to the data read request is read, the corresponding cache area will be updated to ensure that the cache hit rate and access speed can be improved during the next data read request, so as to realize dynamic management of the cache by utilizing multiple levels and weights, which is efficient and intelligent.
[0127] The embodiment of the present invention is divided into hot, warm and cold cache levels, each level has different capacity and priority. Through multi-level cache level management, the cache jitter problem caused by frequent data access can be effectively reduced; each cache item is accompanied by a weight attribute, and the weight is dynamically adjusted according to the access frequency and data importance. The data level is dynamically adjusted based on the access frequency and data heat to improve cache hits. Through the multi-dimensional priority model, the cache strategy can flexibly respond to complex and changeable access patterns. Using multiple levels and weights, the cache is dynamically managed, which is efficient and intelligent. Therefore, the browser multi-level cache strategy management method, device and medium proposed in the present invention can solve the problem of low accuracy when managing data cache.
[0128] like Figure 5 , which is a schematic diagram of the structure of an electronic device for implementing a browser multi-level cache policy management method provided by an embodiment of the present invention.
[0129] The electronic device may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a browser multi-level cache policy management program.
[0130] The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing a browser multi-level cache strategy management program, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0131] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 can also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 can also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can not only be used to store application software and various types of data installed in the electronic device, such as the code of the browser multi-level cache strategy management program, but also can be used to temporarily store data that has been output or is to be output.
[0132] The communication bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0133] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0134] The figure only shows an electronic device with components. Those skilled in the art will understand that the structure shown in the figure does not constitute a limitation on the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0135] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0136] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0137] The browser multi-level cache policy management program stored in the memory 11 in the electronic device is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0138] Creating a hot cache of a high-level access frequency according to a preset first cache capacity, creating a warm cache of a medium-level access frequency according to a preset second cache capacity, creating a cold cache of a low-level access frequency according to a preset third cache capacity, and generating a three-level cache through the hot cache, the warm cache, and the cold cache;
[0139] When the browser receives a data write request, it extracts a data value and a data weight of a write data item corresponding to the data write request, and determines whether the write data item is in any cache level in the three-level cache according to the data value and the data weight;
[0140] When the write data item is written into any cache level in the three-level cache, the final cache level in the three-level cache into which the write data item is written is determined according to the cache capacity of the write cache level corresponding to the write data item, and the write data item is written into the final cache level;
[0141] When the browser receives a data read request, the cache data corresponding to the data read request in the third-level cache is read according to the key value of the target data corresponding to the data read request.
[0142] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0143] Furthermore, if the module / unit integrated in the electronic device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0144] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0145] Creating a hot cache of a high-level access frequency according to a preset first cache capacity, creating a warm cache of a medium-level access frequency according to a preset second cache capacity, creating a cold cache of a low-level access frequency according to a preset third cache capacity, and generating a three-level cache through the hot cache, the warm cache, and the cold cache;
[0146] When the browser receives a data write request, it extracts the data value and data weight of the write data item corresponding to the data write request, and determines whether the write data item is written into any cache level in the three-level cache according to the data value and the data weight;
[0147] When the write data item is written into any cache level in the three-level cache, the final cache level in the three-level cache into which the write data item is written is determined according to the cache capacity of the write cache level corresponding to the write data item, and the write data item is written into the final cache level;
[0148] When the browser receives a data read request, the cache data corresponding to the data read request in the third-level cache is read according to the key value of the target data corresponding to the data read request.
[0149] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, media and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0150] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0152] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0153] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is not limited only according to the above description, and it is intended that all changes within the meaning and scope of equivalent elements within the scope of protection are included in the present invention.
[0154] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0155] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the system can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A browser multi-level cache strategy management method, characterized in that: The method comprises: Creating a hot cache of a high-level access frequency according to a preset first cache capacity, creating a warm cache of a medium-level access frequency according to a preset second cache capacity, creating a cold cache of a low-level access frequency according to a preset third cache capacity, and generating a three-level cache through the hot cache, the warm cache, and the cold cache; When the browser receives a data write request, it extracts the data value and data weight of the write data item corresponding to the data write request, and determines whether the write data item is written into any cache level in the three-level cache according to the data value and the data weight; When the write data item is written into any cache level in the three-level cache, the final cache level in the three-level cache into which the write data item is written is determined according to the cache capacity of the write cache level corresponding to the write data item, and the write data item is written into the final cache level; When the browser receives a data read request, the cache data corresponding to the data read request in the third-level cache is read according to the key value of the target data corresponding to the data read request.
2. The browser multi-level cache strategy management method according to claim 1, characterized in that: The step of creating a hot cache with a high access frequency according to a preset first cache capacity includes: Configure the storage key name of the hot cache and initialize the cache objects in the configured hot cache; Determining the number of cache objects according to a preset first cache capacity; A hot cache with high access frequency is created by using the storage key name and the number of cache objects.
3. The browser multi-level cache strategy management method according to claim 1, characterized in that: Generating a three-level cache by using the hot cache, the warm cache, and the cold cache includes: Using the hot cache as a first-level cache, using the warm cache as a second-level cache, and using the cold cache as a third-level cache; A three-level cache is generated according to the cache order of the first-level cache, the second-level cache, and the third-level cache.
4. The browser multi-level cache strategy management method according to claim 1, characterized in that: The extracting the data value and the data weight of the write data item corresponding to the data write request includes: Extracting write request parameters corresponding to the data write request; Determine the key value corresponding to the write data item according to the write request parameter; The data value and data weight of the written data item are extracted according to the key value.
5. The browser multi-level cache strategy management method according to claim 1, characterized in that: The determining, according to the data value and the data weight, whether the written data item is written into any cache level in the three-level cache comprises: Determining whether the data weight corresponding to the data value of the written data item is a high weight; When the data weight of the written data item is a high weight, determining the cache level of the written data item to be a hot cache in the three-level cache; When the data weight of the written data item is not a high weight, determining whether the data weight of the written data item is a medium weight; When the data weight of the written data item is a medium weight, determining that the cache level of the written data item is a warm cache in the three-level cache; When the data weight of the write data item is not a medium weight, it is determined that the cache level of the write data item is a cold cache in the three-level cache.
6. The browser multi-level cache strategy management method according to claim 5, characterized in that: The step of determining the final cache level at which the written data item is written into the three-level cache according to the cache capacity of the written cache level corresponding to the written data item comprises: When the write cache level is a hot cache, judging whether the cache capacity of the hot cache is full according to the cache capacity of the hot cache, and when the cache capacity of the hot cache is not full, determining the hot cache in the three-level cache as the final cache level of the write data item; When the cache capacity of the hot cache is full, cache data with the smallest data weight in the hot cache is moved to the warm cache in the three-level cache, and the moved hot cache is determined as the final cache level of the written data item; When the write cache level is a warm cache, judging whether the cache capacity of the warm cache is full according to the cache capacity of the warm cache, and when the cache capacity of the warm cache is not full, determining the warm cache in the three-level cache as the final cache level of the write data item; When the cache capacity of the warm cache is full, the cache data with the smallest data weight in the warm cache is moved to the cold cache in the three-level cache, and the moved warm cache is determined as the final cache level of the written data item; When the write cache level is a cold cache, judging whether the cache capacity of the cold cache is full according to the cache capacity of the cold cache, and when the cache capacity of the cold cache is not full, determining the cold cache in the three-level cache as the final cache level of the write data item; When the cache capacity of the cold cache is full, cache data with the smallest data weight in the cold cache is deleted, and the deleted warm cache is determined as the final cache level of the written data item.
7. The browser multi-level cache strategy management method according to claim 1, characterized in that: The step of reading cache data corresponding to the data read request in the third-level cache according to the key value of the target data corresponding to the data read request includes: Extracting the cache key value corresponding to each cache level in the three-level cache; Comparing the cache key value with the key value of the target data corresponding to the data read request; Determine the cache level corresponding to the target data according to the compared key value; The data weight corresponding to the cache level is superimposed with a preset data threshold, and it is determined whether the superimposed data weight reaches the preset cache weight; When the weight of the superimposed data reaches a preset cache weight, the cache level is updated to a cache level corresponding to the preset cache weight; The cache data corresponding to the data read request is read in the updated cache level.
8. The browser multi-level cache strategy management method according to claim 7, characterized in that: The reading of cache data corresponding to the data read request in the updated cache level includes: Extract the data weight corresponding to each data in the updated cache level; Sort the data weights in descending order; The data with the largest weight after the read sorting is the cache data corresponding to the data read request.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the browser multi-level cache policy management method as described in any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the browser multi-level cache strategy management method as described in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Method for implementing multi-level caches in distributed file system
CN104317736A
Keyword matching query method, system and equipment based on multi-level cache and medium
CN117216093A
Multi-level file system and construction method thereof
CN117807045A
Differential storage and eviction for information resources from a browser cache
US8417892B1
