Data caching method and device, equipment and storage medium
By dividing the data area and index area in the first-level cache and migrating across regions according to the access frequency and recent access time, the problem that high-frequency data in the first-level cache is difficult to retain for a long time, and the cache hit rate and data access efficiency are improved.
Patent Information
- Application Number
- CN202311571919.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-23
- Publication Date
- 2025-05-23
AI Technical Summary
High-frequency data in the first-level cache is difficult to retain for a long time, resulting in low cache hit rate and low data access efficiency.
By dividing the first-level cache into three areas: the first data area, the second data area and the index area, the access frequency and recent access time of the cached data are obtained, cross-region migration is carried out, and the storage location of high-frequency data in the cache is dynamically adjusted.
Improve the retention time of high-frequency data in the cache, improve the cache hit rate and data access efficiency.
Smart Images

Figure CN120029936A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data caching, and in particular to a data caching method, device, equipment and storage medium. Background Art
[0002] With the development of current data access technology and data storage technology, the amount of data access and storage is increasing. The CPU cache is a temporary storage located between the CPU and the memory. Its capacity is much smaller than that of the memory, but its exchange speed is much faster than that of the memory. The emergence of cache is mainly to solve the contradiction between the CPU operation speed and the memory read and write speed. Because the CPU operation speed is much faster than the memory read and write speed, it will take the CPU a long time to write data to the memory. The data in the cache is a small part of the memory, but this small part is the cache data that the CPU will access in a short time. When the CPU calls a large amount of data, it can call it from the cache first, thereby speeding up the reading speed.
[0003] When the CPU wants to read a piece of data, it first searches in the first-level cache. If it cannot find the data, it will continue to search in the second-level cache or other storage space in the computer. In the cache design, the replacement strategy of the first-level cache (L1Cache) mainly adopts the LRU (Least Recently Used) scheme to implement the cache data update and replacement functions. The LRU replacement algorithm is a replacement algorithm designed based on the recent characteristics of processor access. The idea is that when a new data block needs to enter the cache, if all available locations are occupied by existing data, the cache block that has not been accessed the longest will be selected for replacement.
[0004] As the mainstream replacement algorithm for current CPU cache, the LUR algorithm is no longer able to adapt to new workloads in many cases as the work domain changes and the data volume expands due to the application of multimedia files. It is difficult to distinguish high-frequency data in different data access modes, which reduces the hit rate of cache data and further reduces data access efficiency. Summary of the invention
[0005] The present invention provides a data caching method, device, equipment and storage medium. The method can solve the problems of high-frequency data being difficult to retain for a long time in the current first-level cache, low cache hit rate and low data access efficiency, thereby increasing the retention time of high-frequency data in the cache and improving the cache hit rate.
[0006] In a first aspect, the present invention provides a data caching method, which is applied to a first-level cache, wherein the first-level cache includes a first data area, a second data area, and an index area, wherein the first data area and the second data area include cached data and corresponding indexes, and the index area includes indexes corresponding to historical cached data, wherein the historical cached data represents cached data removed from the first-level cache;
[0007] Obtain an access request, and obtain, according to the access request, an access frequency of the cached data in the first data area and a most recent access time of the cached data in the second data area;
[0008] Migrating first target cache data in the first data area across areas according to the access frequency;
[0009] The second target cache data in the second data area is migrated across areas according to the most recent access time.
[0010] In a second aspect, the present invention provides a data cache device, applied to a first-level cache, the first-level cache comprising a first data area, a second data area and an index area, wherein the first data area and the second data area comprise cached data and corresponding indexes, the index area comprises indexes corresponding to historical cached data, wherein the historical cached data represents cached data removed from the first-level cache;
[0011] An access request acquisition module, used to acquire an access request, and acquire the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request;
[0012] A first data updating module, configured to perform cross-area migration of first target cache data in the first data area according to the access frequency;
[0013] The second data updating module is used to migrate the second target cache data in the second data area across areas according to the most recent access time.
[0014] In a third aspect, the present invention provides an electronic device, the electronic device comprising:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] 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 data caching method described in any one of the embodiments of the present invention.
[0018] The fourth invention is a computer-readable storage medium, comprising: the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement any one of the data caching methods in the embodiments of the present invention when executed.
[0019] A data caching method provided by an embodiment of the present invention is applied to a first-level cache through the method of the embodiment of the present invention, and the first-level cache data includes three areas, a first data area, a second data area and an index area. By obtaining the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area, the first target cache data is determined according to the access frequency adjustment, and then the first target cache data is migrated across areas; the second target cache data is determined according to the most recent access time, and then the second target cache data is migrated across areas. The method of the embodiment of the present invention can dynamically adjust the storage position of the first target cache data in the first data area in the first-level cache according to the access frequency of the cached data in the first data area; and dynamically adjust the storage position of the second target cache data in the first-level cache according to the most recent access time in the second data area, thereby increasing the storage time of high-frequency data in the first-level cache, thereby improving the hit rate of cache access requests, and improving data access efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 A flowchart of a data caching method provided in Embodiment 1 of the present invention;
[0022] Figure 2 A flowchart of a data caching method provided in Embodiment 2 of the present invention;
[0023] Figure 3 A flowchart of a data caching method provided in Embodiment 3 of the present invention;
[0024] Figure 4 A flowchart of a data caching method provided in Embodiment 4 of the present invention;
[0025] Figure 5 A schematic diagram of the structure of a data cache device provided in Embodiment 5 of the present invention;
[0026] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment 1
[0030] Figure 1 This is a flow chart of a data caching method provided in Embodiment 1 of the present invention. The embodiment of the present invention is applicable to the case of data storage and cache data access or extraction in the first-level cache. The method can be executed by a data caching device, which can be implemented in the form of hardware and / or software and configured in various CPU caches, such as server cache or mobile computer cache, and the embodiment of the present invention does not limit this.
[0031] like Figure 1 As shown, including:
[0032] Step 110: Obtain an access request, and obtain the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request.
[0033] The method of an embodiment of the present invention is applied to a first-level cache, wherein the first-level cache includes a first data area, a second data area, and an index area, wherein the first data area and the second data area include cached data and corresponding indexes, and the index area includes indexes corresponding to historical cached data, wherein the historical cached data represents cached data moved out of the first-level cache.
[0034] Optionally, the first data area can be characterized as a storage area for cache data with a regular access frequency, the second data area can be characterized as a storage area for high-frequency cache data with a higher access frequency, and the index in the index area can be an index of cache data eliminated from the first data and second data areas.
[0035] Furthermore, the cache data in the first-level cache can be adjusted across regions based on the access frequency of the cache data in the first data region and the most recent access time of the cache data in the second data region, so as to achieve the purpose of retaining high-frequency cache data in the first-level cache for a long time, thereby improving the hit rate of access requests to cache data and improving the efficiency of data access.
[0036] Among them, the access request can be the extraction, access or processing of cached data in the cache by a user or application. The access frequency of cached data represents the frequency of access to the cached data per unit time, and the last access time of the cached data is the time when the cached data was last accessed.
[0037] Specifically, the access frequency of cached data can be determined by (the number of times the cached data is accessed per unit time / the total number of access requests in the first-level cache per unit time); the most recent access time can be determined by the time difference between the most recent access time of the cached data and the current time. If the current access request hits cached data A in the second data area, the most recent access time of cached data A is 0.
[0038] Step 120: Migrate the first target cache data in the first data area across areas according to the access frequency.
[0039] Among them, the storage location can be a storage block, a register block, etc. in the storage space of the first-level cache. Furthermore, the cached data in the first-level cache can be continuously stored in the first data area and the second data area, and the cached data can be accessed by accessing the index corresponding to the cached data.
[0040] Specifically, when an access request is obtained, the access frequency of each cache data in the first data zone can be recalculated and determined, and the first target cache data can be determined, and then the first target cache data can be migrated across zones.
[0041] Step 130: Migrate the second target cache data in the second data area across areas according to the most recent access time.
[0042] Specifically, when an access request is obtained, the most recent access time of each cache data in the second data area can be recalculated and determined, and the second target cache data can be determined, and then the second target cache data can be migrated across areas.
[0043] The method of the embodiment of the present invention is applied to the first-level cache, and the first-level cache data is divided into three areas, a first data area, a second data area and an index area. The method of the embodiment of the present invention can determine the first target cache data according to the access frequency adjustment, and then migrate the first target cache data across areas; determine the second target cache data according to the most recent access time, and then migrate the second target cache data across areas, thereby increasing the storage time of high-frequency data in the first-level cache, thereby improving the hit rate of cache access requests and improving data access efficiency.
[0044] Embodiment 2
[0045] Figure 2 A flowchart of a data caching method provided in Embodiment 2 of the present invention is provided. This embodiment is based on the above embodiments and specifically optimizes the method of performing cross-area migration of the first target cache data in the first data area according to the access frequency, and can be applied to the above embodiments, specifically as follows Figure 2 As shown, including:
[0046] Step 210: Obtain an access request, and obtain the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request.
[0047] Step 220: Determine the cache data in the first data area that meets the cross-area frequency condition as the first target cache data.
[0048] The cross-zone frequency condition is used to determine whether the access frequency of the cache data in the first data zone can be updated across zones, and the cross-zone frequency condition may include an upper threshold and a lower threshold.
[0049] Step 230: Update the cross-region location of the first target cache data.
[0050] Optionally, first target cache data that meets an upper threshold in the cross-zone frequency condition is determined as first data to be migrated, and the first data to be migrated is migrated to the second data area, and if the second data area is full, the location update is suspended;
[0051] The first target cache data that meets the lower threshold of the cross-zone frequency condition is determined as the second data to be migrated, the second data to be migrated is deleted, and the index of the second data to be migrated is migrated to the index area.
[0052] Among them, the first data to be migrated is the first target cache data whose access frequency is greater than the upper limit threshold. When the access frequency of the cache data is greater than the upper limit threshold, it can be considered that the access frequency of the cache data in unit time is too high, that is, it is high-frequency cache data, and can be moved to the second data area, wherein the cache data in the second data area can be considered as high-frequency data.
[0053] Specifically, due to the limitation of the storage space in the first-level cache, the size of the storage space in the second data area is fixed. When the second data area is full, the cache data for cross-area updates in the first data area cannot be stored. Therefore, the location update will be paused and the location update will continue when there is sufficient storage space in the second data area.
[0054] Among them, the second data to be migrated is the first target cache data whose access frequency is less than the lower limit threshold. When the access frequency of the cache data is less than the lower limit threshold, it can be considered that the access frequency of the cache data in unit time is too low, and the number of times it is accessed will also be low, that is, it is low-frequency data.
[0055] Specifically, due to the limitation of storage space in the first-level cache, the size of the storage space of the first data area is fixed. In order to save storage space in the first data area in the first-level cache, the second data to be migrated can be deleted and its index can be moved to the index area to save storage space in the first data area and facilitate subsequent access requests to quickly determine the index of the second data to be migrated, and then access the second data to be migrated.
[0056] Optionally, if the index of the second target cache data and the index of the second data to be migrated are migrated to the index area at the same time, the priority of the second target cache data and the second data to be migrated is determined according to the modification bit of the second data to be migrated, wherein the modification bit indicates whether the second data to be migrated is modified;
[0057] The third target cache data is determined according to the priority, and the index of the third target cache data is updated to the index area.
[0058] Among them, since data access requests are often accompanied by data modification, in order to characterize whether the cached data is modified, a modification bit is introduced to characterize whether the cached data is modified. Therefore, it can be determined whether the cached data is modified based on the modification bit.
[0059] Specifically, the update of the cache data location may be a simultaneous data update between multiple different areas to one area, such as the index of the second target cache data and the index of the second data to be migrated are migrated to the index area at the same time. Therefore, in order to ensure the smoothness and security of the cache data location update, it can be determined whether the cache data has been modified based on the modification bit, and then the cache data that should be processed first can be determined. For example, if the cache data is modified, it can be considered that it may be currently important data, so it should be processed first.
[0060] Step 240: Migrate the second target cache data in the second data area across areas according to the most recent access time.
[0061] The embodiment of the present invention obtains access requests and adjusts the storage location of cache data in the first data area according to the access frequency. Specifically, for cache data in the first target cache data that is higher than the upper threshold in the cross-zone frequency condition, its location is updated to the second data area. This method helps to improve the retention time of high-frequency data in the first-level cache; for cache data in the first target cache data that is lower than the lower threshold in the cross-zone frequency condition, its location is updated to the first data area. This method helps to reduce the retention time of low-frequency and infrequently used cache data in the first-level cache. Furthermore, if the index of the second target cache data and the index of the second data to be migrated are migrated to the index area at the same time, the index of the modified second data to be migrated will be moved in first, ensuring the smoothness and security of the cache data location update. Therefore, the method of the embodiment of the present invention helps to improve the retention time of high-frequency data in the first-level cache, reduce the retention time of low-frequency and infrequently used data in the first-level cache, and thus improve the data access hit rate and improve the efficiency of data access.
[0062] Embodiment 3
[0063] Figure 3 This is a flow chart of a data caching method provided in Embodiment 3 of the present invention. This embodiment is based on the above embodiments and further optimizes the method of performing cross-area migration of the second target cache data in the second data area according to the most recent access time, and can be applied to the above embodiments. Specifically, Figure 3 As shown, including:
[0064] Step 310: Obtain an access request, and obtain the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request.
[0065] Step 320: Migrate the first target cache data in the first data area across areas according to the access frequency.
[0066] Step 330: Determine the cache data in the second data area that meets the cross-area time condition as the second target cache data.
[0067] Step 340: Update the cross-region location of the second target cache data.
[0068] Among them, the cross-zone time condition is used to determine whether the cached data in the second data zone can be updated across zones. If the most recent access time of the cached data is less than the cross-zone time condition, it can be understood that the cached data has been frequently accessed recently and is very likely to be accessed in the future. Therefore, the hit rate of access requests to high-frequency cached data can be increased by retaining the data in the second data zone for a long time.
[0069] Optionally, if the first data area is not full, migrating the second target cache data to the first data area;
[0070] If the first data area is full, the second target cache data is deleted, and the index of the second target cache data is migrated to the index area.
[0071] Specifically, if the most recent access time of the cached data in the second data area is greater than the cross-area time condition, that is, the second target cached data, it can be considered that the data has not been accessed for a long time and is less likely to be accessed in the future. Therefore, it can be moved out of the second data area to save storage space in the second data area, so that new high-frequency data can enter the second data area for long-term retention. Furthermore, the second target cached data can be moved into the unfull first data area, but due to limited storage space, if the first data area is full, the second target cached data can be deleted and the index of the second target cached data can be migrated to the index area, so that if future access requests still need to access the second target cached data, its index can be quickly determined, and the required data can be quickly determined based on the index.
[0072] Optionally, when the access request hits the index of the historical cache data in the index area, obtaining the target historical cache data corresponding to the index of the historical cache data;
[0073] If the target historical cache data and the third cache data are migrated to the same storage block in the first data area, the target historical cache data is preferentially updated to the storage block in the first data area.
[0074] Specifically, since the location update of cache data can be a simultaneous update between cache data in multiple areas, if the target historical cache data and the second target cache data are migrated to the same storage block in the first data area, since the target historical cache data is the cache data hit by the current access request and is the important data currently needed, the target historical cache data can be preferentially updated to the storage block in the first data area, and the target historical cache data can be accessed in the first data area.
[0075] The embodiment of the present invention obtains an access request and performs cross-region migration of the second target cache data in the second data area according to the most recent access time. Specifically, the cache data in the second data area that meets the cross-region time condition, that is, the second target cache data, performs a cross-region location update. This cache location update method can transfer the cache data in the second data area that has not been accessed for a long time, ensuring that the cache data in the second data area are all high-frequency data that have been accessed in a short period of time. Furthermore, if the first data area is not full, the second target cache data is migrated to the first data area; if the first data area is full, the second target cache data is deleted, and the index of the second target cache data is migrated to the index area. The method of the embodiment of the present invention can increase the retention time of high-frequency data in the first-level cache, increase the cache hit rate, and thus improve the efficiency of data access by updating the location of the cache data in the first-level cache according to preset conditions.
[0076] Embodiment 4
[0077] Embodiment 4 of the present invention provides a flow chart of a data caching method. This embodiment further optimizes each step of the data caching method based on the above embodiments. Figure 4 .
[0078] like Figure 4 As shown, including:
[0079] Step 401: Get a data access request.
[0080] Step 402: Whether the data access request hits the first-level cache.
[0081] The first-level cache includes a regular data area, a high-frequency data area, and a historical queue area. Further, the regular data area may be the first data area, the high-frequency data area may be the second data area, and the historical queue area may be the index area. The regular data area stores regular cache data and corresponding indexes, the high-frequency data area stores high-frequency data and its index, and the historical queue area stores the indexes of historical cache data removed from the first-level cache area.
[0082] Specifically, if the data access request hits the first-level cache, step 406 is executed, otherwise step 403 is executed.
[0083] Step 403: Check whether the regular data area is full.
[0084] Specifically, if the regular data area is full, execute step 404, otherwise execute step 405.
[0085] Step 404: Move the cache data index with the lowest access frequency into the history queue area.
[0086] Step 405: The target cache data hit by the data access is transferred to the regular data area.
[0087] Specifically, if the data access request does not hit the first-level cache, it means that the target cache data hits the second-level cache or other storage space of the system. Therefore, the target cache data needs to be moved to the regular data area. Furthermore, before moving to the regular data area, it is necessary to determine whether the storage space of the regular data area is sufficient, that is, whether the regular data area is full. If the storage space is insufficient, the cache data with the lowest access frequency in the regular data area needs to be deleted, and the corresponding index is moved to the historical queue area; if the regular data area is not full, the target cache data can be directly moved to the regular data area.
[0088] Exemplarily, when the regular data area of the first-level cache is full, the cache data with the lowest access frequency can be moved to the end of the historical queue area according to the rules of the LRU replacement algorithm. When the regular data area of the first-level cache is not full, the target cache data will be taken out from the next-level memory and stored in the storage block of the regular data area according to the rules of the LRU replacement algorithm, and the access frequency value of the cache data in the regular data area will be adjusted.
[0089] Step 406: Whether the data access request hits the history queue area.
[0090] Specifically, if the data access request hits the history queue area, step 407 is executed, otherwise step 410 is executed.
[0091] Step 407: Check whether the regular data area is full.
[0092] Specifically, if the regular data area is full, execute step 408, otherwise execute step 409.
[0093] Step 408: Move the cache data index with the lowest access frequency into the history queue area.
[0094] Step 409: Determine the target cache data according to the index of the historical queue area, and move the target cache data into the regular data area.
[0095] Specifically, if the data access request hits the target index of the historical queue area, the target cache data needs to be obtained from the secondary cache or other storage space of the system according to the target index. Therefore, the target cache data needs to be moved into the regular data area. Furthermore, before moving into the regular data area, it is necessary to determine whether the storage space of the regular data area is sufficient, that is, whether the regular data area is full. If the storage space is insufficient, the cache data with the lowest access frequency in the regular data area needs to be deleted, and the corresponding index needs to be moved into the historical queue area; if the regular data area is not full, the target cache data can be directly moved into the regular data area.
[0096] Optionally, both the cache data in the regular data area and the cache data in the high-frequency data area may be moved into the historical queue area. Therefore, there may be a situation where the above two types of data are simultaneously moved into the unified storage space of the historical queue area. At this time, the priority of the cache data can be judged. The modified cache data in the regular data area has a higher priority, followed by the cache data in the high-frequency data area.
[0097] Step 410: Whether the data access request hits the high-frequency data area.
[0098] Specifically, if the data hits the high-frequency data area, step 411 is executed; otherwise, the access request hits the regular data area, and step 413 is executed.
[0099] Step 411: Re-determine the most recent access time of the cached data.
[0100] Step 412: Update the cached data that meets the cross-zone time condition to the regular data area.
[0101] Specifically, when the cached data in the high-frequency data area is hit, the most recent access time of the block will be cleared and the timing will be restarted. Furthermore, if the most recent access time of the cached data in the high-frequency data area meets the cross-zone time condition, such as being greater than the cross-zone data condition, it will be moved into the regular data area.
[0102] Optionally, the target cache data determined by the target index of the historical queue area and the cache data of the high-frequency data area may both be moved into the regular data area. Therefore, it is possible that the above two types of data may be simultaneously moved into the regular data area to unify the storage space. At this time, the target cache data will be moved into the regular data area first and the cache data in the high-frequency data area will be deleted, and the corresponding index will be moved into the historical queue area.
[0103] Step 413: Re-determine the access frequency of the cache data.
[0104] Step 414: Update the cached data that meets the cross-zone frequency condition to the high-frequency data area.
[0105] Exemplarily, when an access request hits the cached data in the regular data area, it is determined whether its access frequency meets the upper threshold of the cross-zone frequency condition. If the upper threshold of the cross-zone frequency condition is met and the high-frequency data area is not full, it is moved into the high-frequency data area; otherwise, the movement is paused and the movement is continued when there is sufficient storage space in the high-frequency data area.
[0106] Step 415: Access the target cache data hit by the data access request.
[0107] The embodiment of the present invention divides the first-level cache into a regular data area, a high-frequency data area and a historical queue area, records the access frequency and the most recent access time of each cached data, and extends the residence time of the high-frequency data in the first-level cache by performing cross-zone position updates on the data that meets the cross-zone time condition or the cross-zone frequency condition, thereby improving the cache's adaptability to data access scenarios with high-frequency data and improving the cache hit rate.
[0108] Embodiment 5
[0109] Figure 5 A structural schematic diagram of a data cache device provided in Embodiment 5 of the present invention, the device is applied to a first-level cache, the first-level cache includes a first data area, a second data area and an index area, wherein the first data area and the second data area include cached data and corresponding indexes, the index area includes indexes corresponding to historical cached data, wherein the historical cached data represents cached data removed from the first-level cache, such as Figure 5 As shown, the device comprises:
[0110] An access request acquisition module 510, configured to acquire an access request, and acquire the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request;
[0111] A first data updating module 520, configured to perform cross-area migration of first target cache data in the first data area according to the access frequency;
[0112] The second data updating module 530 is used to migrate the second target cache data in the second data area across areas according to the most recent access time.
[0113] A data caching method provided by an embodiment of the present invention is applied to a first-level cache through the method of the embodiment of the present invention, and the first-level cache data includes three areas, a first data area, a second data area and an index area. By obtaining the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area, the first target cache data is determined according to the access frequency adjustment, and then the first target cache data is migrated across areas; the second target cache data is determined according to the most recent access time, and then the second target cache data is migrated across areas. The method of the embodiment of the present invention can dynamically adjust the storage position of the first target cache data in the first data area in the first-level cache according to the access frequency of the cached data in the first data area; and dynamically adjust the storage position of the second target cache data in the first-level cache according to the most recent access time in the second data area, thereby increasing the storage time of high-frequency data in the first-level cache, thereby improving the hit rate of cache access requests, and improving data access efficiency.
[0114] Optionally, the first data updating module 520 includes a cross-zone frequency updating unit.
[0115] The cross-zone frequency updating unit is used to determine the cache data in the first data zone that meets the cross-zone frequency condition as the first target cache data; and perform cross-zone position updating on the first target cache data.
[0116] Furthermore, the cross-zone frequency updating unit further includes an upper threshold judgment subunit and a lower threshold judgment subunit.
[0117] The upper threshold judgment subunit is used to determine the first target cache data that meets the upper threshold in the cross-zone frequency condition as the first data to be migrated, migrate the first data to be migrated to the second data area, and suspend the location update if the second data area is full;
[0118] The lower threshold judgment subunit is used to determine the first target cache data that meets the lower threshold of the cross-zone frequency condition as the second data to be migrated, delete the second data to be migrated, and migrate the index of the second data to be migrated to the index area.
[0119] Optionally, the cross-zone frequency update unit further includes a first priority determination unit, configured to determine the priority of the second target cache data and the second data to be migrated according to a modification bit of the second data to be migrated if the index of the second target cache data and the index of the second data to be migrated are migrated to the index area at the same time, wherein the modification bit indicates whether the second data to be migrated is modified;
[0120] The target cache data is determined according to the priority, and the index of the target cache data is updated to the index area.
[0121] Optionally, the second data updating module 530 includes: a cross-zone time updating unit,
[0122] The cross-zone time updating unit is used to determine the cache data in the second data zone that meets the cross-zone time condition as the second target cache data; and perform cross-zone location update on the second target cache data.
[0123] Further, the cross-zone time update unit includes a judgment subunit, which is used to migrate the second target cache data to the first data zone if the first data zone is not full;
[0124] If the first data area is full, the second target cache data is deleted, and the index of the second target cache data is migrated to the index area.
[0125] Optionally, the cross-zone time update unit further includes a second priority judgment subunit, which is used to obtain target historical cache data corresponding to the index of the historical cache data when the access request hits the index of the historical cache data in the index zone;
[0126] If the target historical cache data and the second target cache data are migrated to the same storage block in the first data area, the target historical cache data is preferentially updated to the storage block in the first data area.
[0127] A data caching device provided in an embodiment of the present invention can execute a data caching method provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method.
[0128] Embodiment 6
[0129] Figure 6 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0130] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0131] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange data / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0132] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as a data caching method.
[0133] In some embodiments, the data caching method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the data caching method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the data caching method in any other appropriate manner (e.g., by means of firmware).
[0134] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0135] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0136] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0137] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying data to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0138] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0139] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0140] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0141] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A data caching method, It is characterized in that Applied to a first-level cache, the first-level cache includes a first data area, a second data area, and an index area, wherein the first data area and the second data area include cached data and corresponding indexes, and the index area includes indexes corresponding to historical cached data, wherein the historical cached data represents cached data removed from the first-level cache; Obtain an access request, and obtain, according to the access request, an access frequency of the cached data in the first data area and a most recent access time of the cached data in the second data area; Migrating first target cache data in the first data area across areas according to the access frequency; The second target cache data in the second data area is migrated across areas according to the most recent access time.
2. The method according to claim 1, It is characterized in that The step of performing cross-area migration of the first target cache data in the first data area according to the access frequency comprises: Determine the cache data in the first data area that meets the cross-area frequency condition as the first target cache data; The first target cache data is updated in a cross-region location.
3. The method according to claim 2, It is characterized in that The performing cross-region location updating on the first target cache data includes: Determine the first target cache data that meets the upper threshold of the cross-zone frequency condition as the first data to be migrated, migrate the first data to be migrated to the second data area, and suspend the location update if the second data area is full; The first target cache data that meets the lower threshold of the cross-zone frequency condition is determined as the second data to be migrated, the second data to be migrated is deleted, and the index of the second data to be migrated is migrated to the index area.
4. According to the method of claim 3, It is characterized in that Also includes: If the index of the second target cache data and the index of the second data to be migrated are migrated to the index area at the same time, determining the priority of the second target cache data and the second data to be migrated according to the modification bit of the second data to be migrated, wherein the modification bit indicates whether the second data to be migrated is modified; The third target cache data is determined according to the priority, and the index of the third target cache data is updated to the index area.
5. The method according to claim 1, It is characterized in that The step of performing cross-area migration of the second target cache data in the second data area according to the most recent access time includes: Determine the cache data in the second data area that meets the cross-area time condition as the second target cache data; The second target cache data is updated in a cross-region location.
6. The method according to claim 5, It is characterized in that The performing cross-region location updating on the second target cache data includes: If the first data area is not full, migrating the second target cache data to the first data area; If the first data area is full, the second target cache data is deleted, and the index of the second target cache data is migrated to the index area.
7. The method according to claim 6, It is characterized in that include: In the case where the access request hits the index of the historical cache data in the index area, obtaining the target historical cache data corresponding to the index of the historical cache data; If the target historical cache data and the second target cache data are migrated to the same storage block in the first data area, the target historical cache data is preferentially updated to the storage block in the first data area.
8. A data caching device, It is characterized in that Applied to a first-level cache, the first-level cache includes a first data area, a second data area, and an index area, wherein the first data area and the second data area include cached data and corresponding indexes, and the index area includes indexes corresponding to historical cached data, wherein the historical cached data represents cached data removed from the first-level cache; An access request acquisition module, used to acquire an access request, and acquire the access frequency of the cached data in the first data area and the most recent access time of the cached data in the second data area according to the access request; A first data updating module, configured to perform cross-area migration of first target cache data in the first data area according to the access frequency; The second data updating module is used to migrate the second target cache data in the second data area across areas according to the most recent access time.
9. An electronic device, It is 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 data caching method according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data caching method according to any one of claims 1 to 7 when executed.
Citation Information
Cited By
Data migration method and device, computer equipment, readable storage medium and program product
CN120407545A