CN115964391A - Cache management method, device, equipment and storage medium - Google Patents

Cache management method, device, equipment and storage medium Download PDF

Info

Publication number
CN115964391A
CN115964391A CN202211296229.5A CN202211296229A CN115964391A CN 115964391 A CN115964391 A CN 115964391A CN 202211296229 A CN202211296229 A CN 202211296229A CN 115964391 A CN115964391 A CN 115964391A
Authority
CN
China
Prior art keywords
data
cache
version number
memory space
determining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211296229.5A
Other languages
Chinese (zh)
Inventor
白建民
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202211296229.5A priority Critical patent/CN115964391A/en
Publication of CN115964391A publication Critical patent/CN115964391A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The present disclosure provides a cache management method, apparatus, device and storage medium, and relates to the technical field of data processing, in particular to the technical fields of data storage, data access, and the like. The specific implementation scheme is as follows: determining that the data cache of the memory space meets a data elimination condition, wherein the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data; determining data to be eliminated in the cache data according to the data version number of the cache data; and deleting the data to be eliminated from the memory space. Therefore, the management of the cache data is realized through the data version number, a bidirectional linked list does not need to be adopted and maintained, and the performance consumption of cache management on the memory space is reduced.

Description

Cache management method, device, equipment and storage medium
Technical Field
The present disclosure relates to the technical field of data storage and data access in the technical field of data processing, and in particular, to a cache management method, apparatus, device, and storage medium.
Background
Caching data in a memory space is a system optimization means in the design of a distributed system.
The cache management is limited by the size of the memory space, and cache management is generally performed by adopting some data elimination strategies to ensure that hot data which are frequently accessed can be stored in the cache, so that the cache hit rate is improved, and the performance of a distributed system is improved. Among them, the Least Recently Used (LRU) policy is a commonly Used data elimination policy. In the LRU policy, when reading or writing a certain data from or to the memory space, the node of the doubly linked list where the data is located is moved to the node of the doubly linked list, thereby maintaining the access order of the data through the doubly linked list.
However, the performance loss is high in the above manner.
Disclosure of Invention
The present disclosure provides a cache management method, apparatus, device, and storage medium for reducing performance loss caused by managing cache data.
According to a first aspect of the present disclosure, there is provided a cache management method, including:
determining that a data cache of a memory space meets a data elimination condition, wherein the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data;
determining data to be eliminated in the cache data according to the data version number of the cache data;
and deleting the data to be eliminated from the memory space.
According to a second aspect of the present disclosure, there is provided a cache management apparatus, including:
the device comprises a condition determining unit, a data elimination determining unit and a data elimination determining unit, wherein the condition determining unit is used for determining that a data cache of a memory space meets a data elimination condition, the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data;
the data determining unit is used for determining the data to be eliminated in the cache data according to the data version number of the cache data;
and the data elimination unit is used for deleting the data to be eliminated from the memory space.
According to a third aspect of the present disclosure, there is provided an electronic device comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor;
wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the cache management method of the first aspect.
According to a fourth aspect of the present disclosure, there is provided a non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the cache management method of the first aspect.
According to a fifth aspect of the present disclosure, there is provided a computer program product comprising: a computer program, stored in a readable storage medium, from which at least one processor of an electronic device can read the computer program, the execution of the computer program by the at least one processor causing the electronic device to perform the cache management method of the first aspect.
According to the technical scheme provided by the disclosure, the cache data and the data version number of the cache data are stored in the memory space, and the data version number of the cache data is increased along with the increase of the access times of the cache data. And under the condition that the data cache of the memory space meets the data elimination condition, namely under the condition that the cache data needs to be eliminated from the memory space, determining the data to be eliminated from the cache data based on the data version number of the cache data, and deleting the data to be eliminated from the memory space to realize the elimination of the cache data. Because the data version number of the cache data is positively correlated with the access times of the cache data, the cache data is eliminated based on the data version number of the cache data, so that the cache data eliminated from the memory space is the cache data with less access times, and the hot data which is accessed frequently is ensured to be cached in the memory space. Therefore, under the condition of not adopting a two-way linked list, accurate and reasonable cache management is realized, and the performance consumption of cache management on the memory space is reduced.
It should be understood that the statements in this section are not intended to identify key or critical features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 illustrates an exemplary diagram of implementing cache management using hash tables and doubly linked lists;
FIG. 2 is a schematic diagram of an application scenario in which embodiments of the present disclosure are applicable;
fig. 3 is a first flowchart illustrating a cache management method according to an embodiment of the present disclosure;
fig. 4 is a second flowchart illustrating a cache management method according to an embodiment of the disclosure;
fig. 5 is a schematic flowchart of a third method for cache management according to an embodiment of the present disclosure;
fig. 6 is a diagram of an example of cache management provided by an embodiment of the present disclosure;
fig. 7 is a first schematic structural diagram of a cache management apparatus according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of a cache management apparatus according to a second embodiment of the present disclosure;
fig. 9 is a schematic block diagram of an example electronic device 900 that may be used to implement embodiments of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the related art, the cache data is stored by a Hash table (Hash Map), and the access order of the cache data is maintained by a doubly linked list.
For example, FIG. 1 illustrates an exemplary diagram of implementing cache management using hash tables and doubly linked lists. In fig. 1, a plurality of cache data, data identifiers of the cache data, pointers to linked lists of the cache data, and next pointing addresses of the cache data are stored in a hash table; one side of the double linked list is a head, one side of the double linked list is a tail, a plurality of double linked list nodes are arranged between the head and the tail, each double linked list node corresponds to one cache data, and the node content of the double linked list node comprises a previous pointing address, the cache data and a next pointing address.
The data setting operation (i.e., the operation of caching data in the memory space) includes: storing the data identification and the data to be cached in a HASH table through a pseudo code SET (data identification and data to be cached) and a HASH (data identification); if the data identifier is stored in the hash table, namely the data identifier exists in the hash table, moving the node of the bidirectional linked list corresponding to the data identifier to the head of the bidirectional linked list in the bidirectional linked list; if the data identifier is not stored in the hash table, the data to be cached can be encapsulated into a doubly linked list node and placed at the head of the doubly linked list.
The data obtaining operation (i.e. an operation of caching data from a memory space) includes: reading cache data corresponding to the data identification from the HASH table through a pseudo code Get (data identification) and a HASH (data identification); firstly, judging whether the data identifier exists in the hash table, if not, returning to be empty, if so, returning to the cache data corresponding to the data identifier in the hash table, and then, moving the node of the double linked list corresponding to the data identifier to the head of the double linked list.
It can be seen that the above method has the following disadvantages: the bidirectional linked list needs to be moved for caching data and reading data in the memory space, and the performance loss is large; some memory space is consumed to maintain the doubly linked list, and when the data volume is large, the memory space occupied by the doubly linked list is large.
In order to solve the above defects, the present disclosure provides a cache management method, which is applied to the technical fields of data storage, data access, and the like in the technical field of data processing. In the cache management method, a memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data; determining data to be eliminated in the cache data according to the data version number of the cache data under the condition that the data cache of the memory space meets the data elimination condition; and deleting the data to be eliminated from the memory space. Therefore, the data version number is adopted to replace the double linked list, the memory space occupied by the data version number is small compared with the double linked list, and compared with the method that the node of the double linked list corresponding to the cache data is moved to the head node, the access times of the cache data can be fed back by increasing the data version number, and the performance loss of cache management is small. Therefore, the memory space of the cache management is effectively saved and the performance loss of the cache management is reduced.
Fig. 2 is a schematic diagram of an application scenario to which the embodiment of the present disclosure is applied. In an application scenario, the related device includes an electronic device 200, the electronic device 200 may include an interaction unit 201 (e.g., a display screen, a keyboard, etc.), a processor 202, a cache unit 203, and a memory space 204, and the cache unit 203 may cache data in the memory space 204 of the electronic device 200. The electronic device 200 is a server or a terminal, and fig. 2 exemplifies the electronic device 200 as a terminal.
For example, a user sends a data access request (e.g., a page access request, a document access request) to the processor 202 through the interaction unit 201, and the processor 202 obtains corresponding cache data from the memory space 104 through the cache unit 203 and returns the cache data to the interaction unit 201; the processor 202 may store data recently or frequently accessed by the user in the memory space 204 through the cache unit 203.
The server may be a centralized server, a distributed server, or a cloud server. The terminal may be a Personal Digital Assistant (PDA) device, a handheld device (e.g., a smart phone or a tablet computer) with a wireless communication function, a computing device (e.g., a Personal Computer (PC)), an in-vehicle device, a wearable device (e.g., a smart watch or a smart band), and a smart home device (e.g., a smart sound box or a smart display device).
The following describes the technical solutions of the present disclosure and how to solve the above technical problems in detail with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present disclosure will be described below with reference to the accompanying drawings.
Fig. 3 is a first flowchart illustrating a cache management method according to an embodiment of the present disclosure. As shown in fig. 3, the cache management method includes:
s301, determining that the data cache of the memory space meets a data elimination condition, wherein the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data.
The memory space can store one or more cache data and data version numbers corresponding to the one or more cache data respectively. Cache data such as cache pages, cache documents, cache pictures, etc. The data version number of the cache data can be increased along with the increase of the number of times of accessing the cache data, so that the data version number of the cache data can reflect the accessing condition of the cache data to a certain extent, and the more the cache data is accessed, the higher the accessing frequency is, the larger the data version number of the cache data is.
In this embodiment, it may be determined whether the data cache in the memory space meets the data elimination condition, that is, whether the cache data in the memory space needs to be eliminated is determined. In a case where it is determined that the data cache of the memory space satisfies the data elimination condition, S302 may be performed.
S302, determining the data to be eliminated in the cache data according to the data version number of the cache data.
Wherein, the data to be eliminated can be one or more.
In this embodiment, the data version number of the cache data may reflect an access condition of the cache data, and the more the cache data is accessed and the higher the access frequency is, the larger the data version number of the cache data is, so that the cache data with a smaller data version number may be selected from the cache data as the data to be eliminated based on the data version number of the cache data, so that the cache data with a smaller user access frequency is eliminated from the memory space, and it is ensured that the hot data frequently accessed in the cache data may be always stored in the memory space, thereby improving the hit rate of the cache data and improving the data access efficiency.
And S303, deleting the data to be eliminated from the memory space.
In this embodiment, after the data to be eliminated is determined, the data to be eliminated is deleted from the memory space.
In the embodiment of the disclosure, in the memory space, the cache data is eliminated and managed based on the data version number which is increased along with the increase of the access times of the cache data, the data version number of the cache data is increased when the cache data is accessed, and the data to be cached is determined based on the data version number of the cache data when the data is eliminated.
In the following, possible implementations of the various steps of the foregoing embodiments are provided:
in some embodiments, one possible implementation of S301 may include at least one of: determining that the data buffer amount of the memory space is greater than the buffer amount threshold value; determining the current moment as a data elimination moment according to the data elimination period; a data eviction request is received. Therefore, based on the data elimination conditions, the cache data in the memory space can be eliminated in time, and the memory occupation of the cache data is saved.
The data caching amount can be the amount of the cached data, the size of the memory space occupied by the cached data and other data related to the cached data, such as the data version number of the cached data.
The buffer amount threshold may be a preset threshold, or the buffer amount threshold may be determined according to the total size of the memory space, for example, the buffer amount threshold is a product of the memory space and a certain percentage value.
In one example, whether the data buffer amount of the memory space is greater than a buffer threshold value is detected, and if the data buffer amount of the memory space is greater than the buffer threshold value, it is determined that the data buffer of the memory space meets the data elimination condition. Therefore, the cache data are eliminated in time, and the memory space is prevented from being largely occupied by the cache data.
In another example, according to the data elimination cycle, whether the current time is the data elimination time is detected, and if yes, it is determined that the data cache of the memory space meets the data elimination condition. The data elimination cycle refers to data elimination performed on the memory space once every other data elimination cycle. Therefore, the cache data is eliminated periodically, and the memory space is prevented from being largely occupied by the cache data.
In another example, in a case where a data eviction request is received, it is determined that the data cache of the memory space satisfies the data eviction condition. The data elimination request may be triggered by a user, or may be triggered by a corresponding task (such as a memory cleaning task) when the corresponding task is executed.
In some embodiments, one possible implementation of S302 may include: randomly selecting a plurality of candidate data from the buffered data; and determining the data to be eliminated as the candidate data with the minimum data version number in the plurality of candidate data. Therefore, random sampling and the data version number are combined, the efficiency of determining the data to be eliminated is improved, and the data to be eliminated is guaranteed to be cache data with few accessed times.
In this implementation manner, N candidate data may be randomly obtained from the cache data, that is, N candidate data may be randomly sampled, where N may be a preset value, and N may also be determined according to the total number of the cache data. And determining the data to be eliminated as the candidate data with the minimum data version number in the N candidate data. Therefore, the bidirectional linked list nodes do not need to be frequently moved in the whole process, and the data elimination efficiency is improved. With the increase of the data elimination times, the random sampling times of the cache data are also increased, and under the condition that the random sampling times of the random data are more, all the cache data can be randomly sampled theoretically, so that the cache data with the least number of accessed times in the cache data are eliminated. Therefore, the mode can avoid that the cache data with the least number of accessed times occupies the cache space for a long time, improve the data elimination efficiency, and especially improve the data elimination efficiency in a scene with large data volume and large flow.
In addition to the above manner, the cached data with the minimum data version number can be obtained by comparing the data version numbers of all the cached data, and the data to be eliminated is determined to be the cached data with the minimum data version number. However, this approach is less efficient than the above implementation because all the cached data are compared.
In some embodiments, before determining that the data cache of the memory space satisfies the data elimination condition, the method further includes: receiving a data acquisition request; alternatively, a data caching request is received. That is, the trigger condition for executing the step of determining whether the data cache of the memory space satisfies the data elimination condition may be receiving a data acquisition request or receiving a data cache request. In other words, in the case of reading data from the memory space, it is determined whether the memory space needs to retire the cached data; or, under the condition of caching data into the memory space, determining whether the memory space needs to eliminate the cached data. Particularly, when data is cached into the memory space, the memory space faces a situation that the data caching amount is increased, and a situation that the data caching amount of the memory space is larger than the caching amount threshold value after the data is cached into the memory space may occur.
Fig. 4 is a second flowchart illustrating a cache management method according to an embodiment of the disclosure. As shown in fig. 4, the cache management method includes:
s401, a data acquisition request is received.
The data obtaining request is used for requesting to obtain first target data, where the first target data may be one or more cache data in the memory space, and the first target data may also be other data that is not located in the memory space, that is, uncached data.
In this embodiment, a data acquisition request input by a user may be received, a data acquisition request triggered by a related task may also be received, or a data acquisition request sent by another device may also be received.
S402, acquiring first target data from the memory space according to the data acquisition request.
In this embodiment, in response to the data obtaining request, whether the first target data exists in the memory space is searched, and if the first target data does not exist, the empty state may be returned, that is, a message that the first target data is not found in the memory space is returned, and the first target data may be searched in other memory spaces. And if the first target data exists in the memory space, acquiring the first target data from the memory space.
In some embodiments, the memory space further stores a data identifier of the first target data included in the data identifier data obtaining request of the cache data. Thus, one possible implementation of S402 includes: and searching whether the data identifier of the first target data exists in the memory space, and if so, acquiring the first target data from the memory space according to the data identifier of the first target data. Otherwise, determining that the first target data does not exist in the memory space. Therefore, the first target data is searched through the data identification, and the searching efficiency and accuracy of the first target data are improved.
In the memory space, the data identifications corresponding to different cache data are different, and the cache data and the data identifications of the cache data can be stored in the memory space in a one-to-one correspondence manner.
In some embodiments, the memory space also stores the expiration time of the cached data. At this time, one possible implementation manner of S402 includes: acquiring the failure time of the first target data according to the data acquisition request; and if the first target data are determined to be not invalid according to the invalidation time of the first target data, acquiring the first target data from the memory space. Therefore, whether the data is invalid or not is judged through the invalid time in consideration of the fact that the invalid data may be inaccurate, the invalid data is effectively prevented from being acquired from the memory space, and the data acquisition accuracy is improved.
In this implementation, the expiration time of the first target data may be obtained from the memory space according to the data obtaining request. Under the condition that the memory space also stores the data identifier of the cache data and the data acquisition request comprises the data identifier of the first target data, if the data identifier of the first target data exists in the memory space, the expiration time of the first target data can be acquired from the memory space according to the data identifier of the first target data. After obtaining the expiration time of the first target data, the current time of obtaining the first target data may be compared with the expiration time of the first target data, and if the current time is earlier than the expiration time, it is determined that the first target data is not expired, otherwise it is determined that the first target data is expired. And under the condition that the first target data is not invalid, acquiring the first target data from the memory space.
The cache data, the data identifier of the cache data and the invalidation time of the cache data can be stored in the memory space in a one-to-one correspondence manner. Therefore, the cache data and the invalidation time of the cache data can be accurately obtained from the inner space according to the data identification of the cache data.
Further, if the first target data is determined to be invalid according to the invalidation time of the first target data, deleting the first target data from the memory space. Therefore, invalid cache data can be deleted in time, and the situation that the invalid cache data still occupies the memory space is avoided.
S403, the data version number of the first target data is updated.
In this embodiment, after the first target data is obtained from the memory space, because the number of access times of the first target data is increased, the data version number of the first target data is updated, that is, the data version number of the first target data is increased. Therefore, the data version number of the cache data in the memory space is updated in time, and the accuracy of the data version number of the cache data is improved.
In one possible implementation, updating the data version number of the first target data may include: the data version number of the first target data is incremented by one. Therefore, the number of times of accessing the first target data is increased once, and the data version number of the first target data is increased by one, so that the number of times of accessing the first target data can be more accurately reflected by the data version number of the first target data.
In the embodiment of the disclosure, under the condition that the first target data is accessed, the data version number of the first target data is updated in time, the accuracy of the data version number of the cache data is improved, and the accuracy that the data version number of the cache data reflects the accessed condition of the cache data is improved, so that accurate cache management can be realized based on the data version number, and the cache management efficiency is improved.
In some embodiments, the memory space further stores a global version number, the global version number increases with an increase in the data version number of the cache data, and after the data version number of the first target data is updated, as shown in fig. 4, the cache management method further includes: and S404, updating the global version number. The global version number is used for determining an initial data version number of the cache data in the memory space, that is, the global version number is used as a reference version number for determining the initial data version number of the cache data. Therefore, when new data is cached to the memory space, a larger data version number can be determined for the new data based on the global version number in consideration of the fact that the new data is recently accessed data, and the LRU strategy is realized.
In one possible implementation, updating all version numbers may include: and adding one to all version numbers. Therefore, the global version number is increased by one every time the access frequency of the cache data in the memory space is increased, so that the access conditions of all the cache data are fed back more closely by all the version numbers, and the accuracy of cache management is improved.
Fig. 5 is a schematic flowchart of a third method for cache management according to an embodiment of the present disclosure. As shown in fig. 5, the cache management method includes:
s501, a data caching request is received.
The data caching request is used for requesting to cache second target data, and the second target data is data to be cached, which is requested to be cached by the data caching request.
S502, determining the data version number of the second target data.
In this embodiment, after receiving the data caching request, the second target data may be obtained from the data caching request, and the data version number of the second target data may be determined.
In some embodiments, one possible implementation of S502 includes: and in the memory space, determining the maximum value of the data version numbers of the cache data, and determining the data version number of the second target data according to the maximum value. Wherein the data version number of the second target data is greater than or equal to the maximum value. Therefore, considering that the new cache data is the data recently accessed by the user, the method can ensure that the data newly cached in the memory space has a larger data version number and is not easy to be eliminated quickly, the LRU strategy is met, and the cache hit rate is improved.
In some embodiments, the memory space also stores a global version number. One possible implementation manner of S502 includes: and determining the data version number of the second target data according to the global version number. The global version number may refer to the foregoing embodiments, and is not described in detail. The global version number is increased along with the increase of the data version numbers of all the cache data in the memory space, so that all the version numbers are larger than or equal to the data version numbers of all the cache data, the data version number of the second target data is determined based on the global version number, the second target data can be ensured to have the data version number with a larger value, the second target data are not easy to eliminate quickly, the LRU policy is met, and the cache hit rate is improved.
In the process of determining the data version number of the second target data according to the global version number, the data version number of the second target data can be determined to be the global version number. Thus, the second target data is ensured to have a data version number with a larger value. In addition, it may also be determined that the data version number of the second target data is the global version number minus a smaller value, and no one-to-one description is made here for other manners.
S503, caching the second target data and the data version number of the second target data in the memory space.
In this embodiment, after the data version number of the second target data is determined, the second target data and the data version number of the second target data are cached in the memory space.
In some embodiments, the data caching request includes the second target data and a data identifier of the second target data, and in this case, one possible implementation manner of S503 includes: and caching the second target data, the data identifier of the second target data and the data version number of the second target data into the memory space. Therefore, the reading efficiency of the second target data is improved conveniently through the data identification of the second target data.
In some embodiments, the data caching request includes the second target data and the expiration time of the second target data, and in this case, one possible implementation manner of S503 includes: and caching the second target data, the expiration time of the second target data and the data version number of the second target data into a memory space. Therefore, whether the second target data is valid or not is determined conveniently through the invalidation time of the second target data, and cache management is facilitated from the perspective of validity of the cache data.
With reference to the foregoing embodiments, in some embodiments, the data caching request includes the second target data, the data identifier of the second target data, and the expiration time of the second target data, where a possible implementation manner of S503 includes: and caching the second target data, the data identifier of the second target data, the expiration time of the second target data and the data version number of the second target data into a memory space.
In the embodiment of the present disclosure, in the process of caching the second target data, the second target data and the data version number of the second target data are cached in the memory space, which is convenient for implementing cache management in the memory space based on the data version number of the cached data, reduces performance consumption of cache management in the memory space, and reduces memory occupation of cache management in the memory space.
In some embodiments, as shown in fig. 5, the cache management method further includes:
s504, determining that the data cache of the memory space meets a data elimination condition, wherein the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data.
And S505, determining the data to be eliminated in the cache data according to the data version number of the cache data.
S506, deleting the data to be eliminated from the memory space.
Wherein, S504 may be executed after S501, and may also be executed after S503. The implementation principle and the technical effect of S504 to S506 can refer to the related description of the foregoing embodiments, and are not described herein again.
In some embodiments, the cached data and the data version number of the cached data may be stored in the memory space by a hash table. Each line in the hash table may correspond to one cache data, and each line in the hash table may store the cache data and a data version number of the cache data.
Under the condition that the memory space also stores the data identifier of the cache data, each line of the hash table can store the cache data, the data identifier of the cache data and the data version number of the cache data.
In the case that the memory space further stores the expiration time of the cached data, each row of the hash table may store the cached data, the expiration time of the cached data, and the data version number of the cached data.
Under the condition that the memory space also stores the data identifier of the cache data and the expiration time of the cache data, each row of the hash table can store the cache data, the data identifier of the cache data, the expiration time of the cache data and the data version number of the cache data.
By way of example, fig. 6 is a diagram of an example of cache management provided by an embodiment of the present disclosure. As shown in fig. 6, the hash table may store the data identifier of the cache data, the data version number of the cache data, and the next address of the cache data. Wherein the expiration time of the cache data (not shown in fig. 6) may be stored with the cache data in a serialized manner, and the next pointing address of the cache data may point to the next cache data in the hash table. As shown in fig. 6, the data to be cached can be cached in the HASH table by the pseudo code SET (data identifier, data to be cached) and HASH (data identifier), and the cached data can be obtained from the HASH table by the pseudo code Get (data identifier) and HASH (data identifier).
As shown in fig. 6, with the cache management method provided in the embodiment of the present disclosure, the size of the memory that needs to be occupied by a piece of cache data includes: the memory size occupied by the data identifier + the memory size occupied by the cache data + the memory size occupied by the data version number + the memory size occupied by the next pointer address. As shown in fig. 1, a hash table and a doubly linked list are used, and the size of a memory occupied by a piece of cache data includes: the memory size occupied by the data identifier + the memory size occupied by the cache data + the memory size occupied by the pointer to the linked list + the memory size occupied by the next pointer address + the memory size occupied by the previous pointer address. Therefore, the cache management method provided by the embodiment of the disclosure effectively saves the memory space.
Fig. 7 is a first schematic structural diagram of a cache management device according to an embodiment of the present disclosure. As shown in fig. 7, the cache management apparatus 700 includes:
a condition determining unit 701, configured to determine that a data cache of a memory space satisfies a data elimination condition, where the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data increases with an increase in the number of times the cache data is accessed;
a data determining unit 702, configured to determine, according to a data version number of the cached data, to-be-eliminated data in the cached data;
the data elimination unit 703 is configured to delete the data to be eliminated from the memory space.
Fig. 8 is a schematic structural diagram of a cache management apparatus according to a second embodiment of the present disclosure. As shown in fig. 8, the cache management apparatus 800 includes:
a condition determining unit 801, configured to determine that a data cache of a memory space satisfies a data elimination condition, where the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data increases with an increase in the number of times the cache data is accessed;
a data determining unit 802, configured to determine, according to a data version number of the cache data, to-be-eliminated data in the cache data;
and the data elimination unit 803 is used for deleting the data to be eliminated from the memory space.
In some embodiments, as shown in fig. 8, the data determination unit 802 includes: a data selecting module 8021, configured to randomly select multiple candidate data from the buffered data; the data determining module 8022 is configured to determine that the data to be eliminated is the candidate data with the smallest data version number in the multiple candidate data.
In some embodiments, the condition determining unit 801 includes at least one of: a buffer amount determining module (not shown in the figure) for determining that the data buffer amount of the memory space is greater than the buffer amount threshold; a time determining module (not shown in the figure) for determining the current time as a data elimination time according to the data elimination period; and the elimination request receiving module is used for receiving the data elimination request.
In some embodiments, as shown in fig. 8, the cache management apparatus 800 further includes: an acquisition request receiving unit 804 configured to receive a data acquisition request; or, the cache request receiving unit 805 is configured to receive a data cache request.
In some embodiments, the data obtaining request is for obtaining first target data, and the cache management apparatus 800 further includes: a data obtaining unit 806, configured to obtain first target data from a memory space according to the data obtaining request; a local version updating unit 807 for updating the data version number of the first target data.
In some embodiments, the memory space further stores the expiration time of the cache data, and the data obtaining unit 806 includes: a time obtaining module (not shown in the figure) for obtaining the expiration time of the first target data according to the data obtaining request; and a data obtaining module (not shown in the figure) for obtaining the first target data from the memory space if it is determined that the first target data is not invalid according to the invalidation time of the first target data.
In some embodiments, the cache management apparatus 800 further comprises: and a data invalidation unit (not shown in the figure) for deleting the first target data from the memory space if it is determined that the first target data is invalidated according to the invalidation time of the first target data.
In some embodiments, the memory space further stores a global version number, the global version number increases with an increase of the data version number of the cached data, and the cache management apparatus 800 further includes: and a global version updating unit 808, configured to update the global version number.
In some embodiments, the data caching request is for requesting caching of the second target data, and the cache management apparatus 800 further includes: a version determination unit 809 for determining a data version number of the second target data; the data caching unit 810 is configured to cache the second target data and the data version number of the second target data in the memory space.
In some embodiments, the memory space further stores a global version number, and the version determination unit 809 includes: and a version determining module (not shown in the figure) for determining the data version number of the second target data according to the global version number.
The cache management apparatus provided in fig. 7 to 8 may execute the corresponding method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
According to an embodiment of the present disclosure, the present disclosure also provides an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the aspects provided by any of the embodiments described above.
According to an embodiment of the present disclosure, there is also provided a non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the solution provided by any of the above embodiments.
According to an embodiment of the present disclosure, the present disclosure also provides a computer program product comprising: a computer program, stored in a readable storage medium, from which at least one processor of the electronic device can read the computer program, and the execution of the computer program by the at least one processor causes the electronic device to perform the solutions provided by any of the above embodiments.
Fig. 9 is a schematic block diagram of an example electronic device 900 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 9, the electronic device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) (e.g., ROM 902) or a computer program loaded from the storage unit 908 into a Random Access Memory (RAM) (e.g., RAM 903). In the RAM 903, various programs and data required for the operation of the electronic device 900 can also be stored. The calculation unit 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input/output (I/O) interface (e.g., I/O interface 905) is also connected to bus 904.
A number of components in the electronic device 900 are connected to the I/O interface 905, including: an input unit 906 such as a keyboard, a mouse, and the like; an output unit 907 such as various types of displays, speakers, and the like; a storage unit 908 such as a magnetic disk, optical disk, or the like; and a communication unit 909 such as a network card, a modem, a wireless communication transceiver, and the like. The communication unit 909 allows the electronic device 900 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
The computing unit 901 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of the computing Unit 901 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and the like. The computing unit 901 performs the respective methods and processes described above, such as a cache management method. For example, in some embodiments, the cache management method may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 908. In some embodiments, part or all of a computer program may be loaded onto and/or installed onto electronic device 900 via ROM 902 and/or communications unit 909. When the computer program is loaded into RAM 903 and executed by computing unit 901, one or more steps of the above described cache management methods may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to perform the cache management method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Parts (ASSPs), system On a Chip (SOC), complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 Compact Disc Read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Network (LAN), wide Area Network (WAN), and the internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The Server can be a cloud Server, also called a cloud computing Server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service ("Virtual Private Server", or simply "VPS"). The server may also be a server of a distributed system, or a server incorporating a blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel, sequentially or in different orders, and are not limited herein as long as the desired results of the technical aspects of the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

Claims (23)

1. A cache management method, comprising:
determining that a data cache of a memory space meets a data elimination condition, wherein the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data;
determining data to be eliminated in the cache data according to the data version number of the cache data;
and deleting the data to be eliminated from the memory space.
2. The cache management method according to claim 1, wherein the determining, according to the data version number of the cache data, to-be-evicted data in the cache data comprises:
randomly selecting a plurality of candidate data from the cache data;
and determining the data to be eliminated as the candidate data with the minimum data version number in the plurality of candidate data.
3. The cache management method according to claim 1, wherein the determining that the data cache of the memory space satisfies the data eviction condition includes at least one of:
determining that the data buffer amount of the memory space is greater than a buffer amount threshold value;
determining the current moment as a data elimination moment according to the data elimination period;
a data eviction request is received.
4. The cache management method according to any one of claims 1 to 3, before determining that the data cache of the memory space satisfies the data elimination condition, further comprising:
receiving a data acquisition request;
alternatively, a data caching request is received.
5. The cache management method according to claim 4, wherein the data obtaining request is for obtaining first target data, and after receiving the data obtaining request, the method further comprises:
acquiring the first target data from the memory space according to the data acquisition request;
and updating the data version number of the first target data.
6. The cache management method according to claim 5, wherein the memory space further stores expiration time of the cache data, and the obtaining the first target data from the memory space according to the data obtaining request includes:
acquiring the failure time of the first target data according to the data acquisition request;
and if the first target data are determined to be not invalid according to the invalidation time of the first target data, acquiring the first target data from the memory space.
7. The cache management method of claim 6, further comprising:
and if the first target data are determined to be invalid according to the invalidation time of the first target data, deleting the first target data from the memory space.
8. The cache management method according to claim 5, wherein the memory space further stores a global version number, the global version number increases with an increase of a data version number of the cached data, and after the updating of the data version number of the first target data, the method further comprises:
and updating the global version number.
9. The cache management method according to claim 4, wherein the data cache request is used for requesting to cache the second target data, and after receiving the data cache request, the method further comprises:
determining a data version number of the second target data;
and caching the second target data and the data version number of the second target data to the memory space.
10. The cache management method according to claim 9, wherein the memory space further stores a global version number, and the determining the data version number of the second target data includes:
and determining the data version number of the second target data according to the global version number.
11. A cache management apparatus, comprising:
the device comprises a condition determining unit, a data elimination determining unit and a data elimination determining unit, wherein the condition determining unit is used for determining that a data cache of a memory space meets a data elimination condition, the memory space stores cache data and a data version number of the cache data, and the data version number of the cache data is increased along with the increase of the access times of the cache data;
the data determining unit is used for determining data to be eliminated in the cache data according to the data version number of the cache data;
and the data elimination unit is used for deleting the data to be eliminated from the memory space.
12. The cache management device according to claim 11, wherein the data determination unit comprises:
the data selection module is used for randomly selecting a plurality of candidate data from the cache data;
and the data determining module is used for determining the data to be eliminated as the candidate data with the minimum data version number in the plurality of candidate data.
13. The cache management apparatus according to claim 11, wherein the condition determining unit comprises at least one of:
the buffer memory determining module is used for determining that the data buffer memory of the memory space is greater than a buffer memory threshold;
the time determining module is used for determining the current moment as the data elimination moment according to the data elimination period;
and the elimination request receiving module is used for receiving the data elimination request.
14. The cache management device according to any of claims 11-13, further comprising:
an acquisition request receiving unit configured to receive a data acquisition request;
or, the cache request receiving unit is configured to receive a data cache request.
15. The cache management device according to claim 14, wherein the data fetch request is for requesting to fetch first target data, the cache management device further comprising:
a data obtaining unit, configured to obtain the first target data from the memory space according to the data obtaining request;
and the local version updating unit is used for updating the data version number of the first target data.
16. The cache management device according to claim 15, wherein the memory space further stores expiration times of the cache data, and the data obtaining unit comprises:
the time acquisition module is used for acquiring the failure time of the first target data according to the data acquisition request;
and the data acquisition module is used for acquiring the first target data from the memory space if the first target data is determined to be invalid according to the invalidation time of the first target data.
17. The cache management device of claim 16, further comprising:
and the data invalidation unit is used for deleting the first target data from the memory space if the first target data is determined to be invalid according to the invalidation time of the first target data.
18. The cache management device according to claim 15, wherein the memory space further stores a global version number, the global version number increasing with an increase in a data version number of the cache data, the cache management device further comprising:
and the global version updating unit is used for updating the global version number.
19. The cache management device of claim 14, the data cache request requesting caching of second target data, the cache management device further comprising:
a version determination unit configured to determine a data version number of the second target data;
and the data caching unit is used for caching the second target data and the data version number of the second target data to the memory space.
20. The cache management apparatus according to claim 19, wherein the memory space further stores a global version number, and the version determining unit comprises:
and the version determining module is used for determining the data version number of the second target data according to the global version number.
21. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor;
wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the cache management method of any one of claims 1-10.
22. A non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the cache management method of any one of claims 1-10.
23. A computer program product comprising a computer program which, when executed by a processor, carries out the steps of the cache management method of any one of claims 1 to 10.
CN202211296229.5A 2022-10-21 2022-10-21 Cache management method, device, equipment and storage medium Pending CN115964391A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211296229.5A CN115964391A (en) 2022-10-21 2022-10-21 Cache management method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211296229.5A CN115964391A (en) 2022-10-21 2022-10-21 Cache management method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115964391A true CN115964391A (en) 2023-04-14

Family

ID=87357719

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211296229.5A Pending CN115964391A (en) 2022-10-21 2022-10-21 Cache management method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115964391A (en)

Similar Documents

Publication Publication Date Title
CN110275841B (en) Access request processing method and device, computer equipment and storage medium
US11288210B2 (en) Method, device and computer program product for managing storage system
CN109977129A (en) Multi-stage data caching method and equipment
US9665658B2 (en) Non-blocking queue-based clock replacement algorithm
US11593268B2 (en) Method, electronic device and computer program product for managing cache
US11113195B2 (en) Method, device and computer program product for cache-based index mapping and data access
CN113934655B (en) Method and apparatus for solving ambiguity problem of cache memory address
CN115599821A (en) Cache control method, device, equipment and medium
CN113127382A (en) Data reading method, device, equipment and medium for additional writing
CN113961510A (en) File processing method, device, equipment and storage medium
CN113010535B (en) Cache data updating method, device, equipment and storage medium
CN113094392A (en) Data caching method and device
CN107748649B (en) Method and device for caching data
CN113742131B (en) Method, electronic device and computer program product for storage management
CN113495854A (en) Method and system for implementing or managing cache coherence in a host-device system
CN112214178A (en) Storage system, data reading method and data writing method
CN110737397B (en) Method, apparatus and computer program product for managing a storage system
US8447934B2 (en) Reducing cache probe traffic resulting from false data sharing
CN112631517B (en) Data storage method and device, electronic equipment and storage medium
CN114528229A (en) Cache data access method and device and electronic equipment
CN115712388A (en) Data storage method, device and equipment of solid-state disk and storage medium
CN115964391A (en) Cache management method, device, equipment and storage medium
CN115981555A (en) Data processing method and device, electronic equipment and medium
CN110889053B (en) Interface data caching method and device and computing equipment
CN113076067B (en) Method and device for eliminating cache data

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination