CN114461681A - Cache content management method and device, electronic equipment and storage medium - Google Patents

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

Info

Publication number
CN114461681A
CN114461681A CN202210074411.XA CN202210074411A CN114461681A CN 114461681 A CN114461681 A CN 114461681A CN 202210074411 A CN202210074411 A CN 202210074411A CN 114461681 A CN114461681 A CN 114461681A
Authority
CN
China
Prior art keywords
data
cache
accessed
heat value
current heat
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
CN202210074411.XA
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.)
Tibet Ningsuan Technology Group Co ltd
Original Assignee
Tibet Ningsuan Technology Group 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 Tibet Ningsuan Technology Group Co ltd filed Critical Tibet Ningsuan Technology Group Co ltd
Priority to CN202210074411.XA priority Critical patent/CN114461681A/en
Publication of CN114461681A publication Critical patent/CN114461681A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Abstract

The invention provides a cache content management method, a cache content management device, an electronic device and a storage medium, wherein the cache content management method comprises the following steps: receiving a data access request; if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full; if the cache is full, deleting the data with the lowest current heat value in the cache, then writing the data to be accessed in the database into the cache, and determining the current heat value of the data to be accessed. The cache content management method, the cache content management device, the electronic equipment and the storage medium can improve the cache hit rate and the data access speed.

Description

Cache content management method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of caching, and in particular, to a method and an apparatus for managing cached content, an electronic device, and a storage medium.
Background
When a certain hardware needs to read data, the required data is searched from the Cache, if the data is found, the data is directly executed, and if the data is not found, the data is searched from the memory. Since caches run much faster than memory, the role of caches is to help the hardware run faster.
When the cache is full, the data in the memory cannot be written into the cache, so that the data in the cache needs to be eliminated, and new data can be written into the cache after partial cache space is released. However, in the prior art, when cache data is eliminated, the determination of the cache content to be eliminated is not accurate enough, which further causes a low hit rate of the cache, and affects the access speed of the data.
Disclosure of Invention
The invention aims to: in view of the above existing problems, a cache content management method, an apparatus, an electronic device, and a storage medium are provided to improve the hit rate of a cache and the data access speed.
The technical scheme adopted by the invention is as follows:
a cache content management method, the method comprising:
receiving a data access request;
if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full;
if the cache is full, deleting the data with the lowest current heat value in the cache, then writing the data to be accessed in the database into the cache, and determining the current heat value of the data to be accessed.
Further, the current heat value of each data in the cache is determined according to the local timestamp corresponding to each data.
Further, the current heat value of each data in the cache is determined according to the sum of the original heat value of each data and the local timestamp corresponding to each data.
Further, the current hot value of each data in the cache satisfies the following relationship:
Hn=Hn-1+α·(Tn-X);
in the formula: hnA current heat value for each data in the cache; hn-1The original heat value of each data in the cache; t is a unit ofnA local timestamp for each data in the cache; x is an initialization reference time stamp generated by the system; alpha is a preset time weight and the value range of alpha is more than 0 and less than or equal to 1.
Further, the method further comprises:
receiving a data access request; and if the data to be accessed exists in the cache, determining the current heat value of the data to be accessed in the cache.
Further, the method further comprises:
receiving a data access request; if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full; and if the cache is not full, writing the data to be accessed in the database into the cache, and determining the current heat value of the data to be accessed.
The invention also discloses a cache content management device, which comprises:
the receiving module receives a data access request;
the data writing module writes data to be accessed in the database into a cache;
the heat value determining module is used for determining the current heat value of each datum in the cache;
the judging module is used for determining whether the cache has data to be accessed or not, acquiring the data to be accessed from the database if the cache does not have the data to be accessed, and judging whether the cache is full;
and the elimination module deletes the data with the lowest current heat value in the cache if the cache is full, then the data writing module writes the data to be accessed in the database into the cache, and the heat value determination module determines the current heat value of the data to be accessed.
The invention also discloses an electronic device, comprising:
one or more processors;
storage means for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the cache content management method described above.
The invention also discloses a computer readable storage medium on which a computer program is stored, which when executed by a processor implements the above-mentioned cache content management method.
In summary, due to the adoption of the technical scheme, the invention has the beneficial effects that:
the invention can sequence the heat value of each data, when the cache is full, the data with the minimum heat value can be conveniently, accurately and quickly eliminated from the cache, the cache space is released, and the cache hit rate and the data access speed are further improved. Meanwhile, the influence of the access times on the hot value is eliminated through the time factor, and the hot value of the newer data is higher along with the lapse of time, so that the data in the cache keeps an active use state, a large amount of old data is prevented from occupying the cache, the cache hit rate is improved, and the data access speed is improved.
Drawings
FIG. 1 is a flow chart of a cache content management method;
fig. 2 is a schematic diagram of main modules of the cache content management apparatus.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
Example 1
As shown in fig. 1, the present invention discloses a cache content management method, which includes:
receiving a data access request initiated by a client;
if the data to be accessed exists in the cache, determining the current heat value of the data to be accessed in the cache, and then returning the data to be accessed to the client;
if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full;
if the cache is not full, writing the data to be accessed in the database into the cache, determining the current heat value of the data to be accessed, and then returning the data to be accessed to the client;
if the cache is full, deleting the data with the lowest current heat value in the cache, then writing the data to be accessed in the database into the cache, determining the current heat value of the data to be accessed, and then returning the data to be accessed to the client.
Due to the adoption of the method, each data in the cache corresponds to one heat value, each data can be sorted according to the heat value, when the cache is full, the data with the minimum heat value can be conveniently, accurately and quickly eliminated from the cache, the cache space is released, and the cache hit rate and the data access speed are further improved.
The heat value is updated once each time each data is accessed, and the current heat value is the heat value of each data when the data is accessed for the last time; the heat value of each data can be determined through the access times of each data, the heat value is +1 every time the data is accessed, and the heat value is gradually increased; however, as time goes on, the heat value is calculated by the access times, which results in that the heat value of the data is larger and larger, if the data is not used later, but the heat value of the data is too large, the data cannot be eliminated from the cache, and if the old data is eliminated, the subsequent new data needs higher access times, so that the old data can be removed from the cache after the heat value of the new data is larger than the heat value of the old data. As old data is moved out, the number of access times required by new data is increased, the cache is largely occupied by useless old data, the cache hit rate is reduced, and the data access speed is reduced.
Therefore, the current heat value of each data is determined through the local timestamp, the influence of the access times on the heat value is eliminated through the time factor, and the more new data is, the higher the heat value is, the data in the cache keeps an active use state, so that a large amount of old data is prevented from occupying the cache, the cache hit rate is improved, and the data access speed is improved.
Specifically, the current heat value of each data in the cache is determined according to the sum of the original heat value of each data and the local timestamp corresponding to each data. Further description is that the current hot value of each data in the cache satisfies the following relation:
Hn=Hn-1+α·(Tn-X);
in the formula:
Hnthe current heat value of each data in the cache is the heat value when each data is accessed for the last time;
Hn-1the original heat value of each data in the cache is the heat value when each data is accessed for the second time from the last, namely the last heat value of the current heat value;
Tna local timestamp of each data in the cache, namely a timestamp converted from the last time the data is accessed;
x is an initialization reference time stamp generated by the system; t can be reduced due to the presence of XnAnd the difference value between the X value and the X value reduces the data storage capacity, is convenient for storing data and improves the data reading efficiency.
Alpha is a preset time weight, the value range of alpha is more than 0 and less than or equal to 1, and the larger the alpha value is, the larger the weight of the time factor to the heat degree is.
From the above formula, T is shown as time goes onnThe data are larger and larger, namely the newer data heat value is higher, so that the data in the cache can keep an active use state, and the cache hit rate is improved; the cache occupation by a large amount of old data is avoided, the cache hit rate is improved, and the data access speed is improved.
Example 2
The invention also discloses a cache content management device, which comprises:
the receiving module receives a data access request;
the data writing module writes data to be accessed in the database into a cache;
the heat value determining module is used for determining the current heat value of each datum in the cache;
the judging module is used for determining whether the data to be accessed exists in the cache or not, and enabling the heat value determining module to determine the current heat value of the data to be accessed in the cache if the data to be accessed exists in the cache; if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full;
the elimination module is used for enabling the data writing module to write the data to be accessed in the database into the cache if the cache is not full, and enabling the heat value determination module to determine the current heat value of the data to be accessed; if the cache is full, deleting the data with the lowest current heat value in the cache, then enabling the data writing module to write the data to be accessed in the database into the cache, and enabling the heat value determining module to determine the current heat value of the data to be accessed.
Further, the hot value determining module determines the hot value of each data in the cache according to the following relationship:
Hn=Hn-1+α·(Tn-X);
in the formula:
Hnthe current heat value of each data in the cache is the heat value when each data is accessed for the last time;
Hn-1the original heat value of each data in the cache is the heat value when each data is accessed for the second time from the last, namely the last heat value of the current heat value;
Tna local timestamp of each data in the cache, namely a timestamp converted from the last time the data is accessed;
x is an initialization reference time stamp generated by the system; t can be reduced due to the presence of XnAnd the difference value between the X value and the X value reduces the data storage capacity, is convenient for storing data and improves the data reading efficiency.
Alpha is a preset time weight, the value range of alpha is more than 0 and less than or equal to 1, and the larger the alpha value is, the larger the weight of the time factor to the heat degree is.
The cache content management device can sequence the heat value of each data, and when the cache is full, the data with the minimum heat value can be conveniently, accurately and quickly eliminated from the cache, the cache space is released, and the cache hit rate and the data access speed are further improved. Meanwhile, according to the above formula, as time goes on, the time goes on,TnThe data are larger and larger, namely the newer data heat value is higher, so that the data in the cache can keep an active use state, and the cache hit rate is improved; the cache occupation by a large amount of old data is avoided, the cache hit rate is improved, and the data access speed is improved.
Example 3
The invention also discloses an electronic device, comprising:
one or more processors;
storage means for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the cache content management method in embodiment 1.
Example 4
The present invention also discloses a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements the cache content management method in embodiment 1.
Although the present invention has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that various changes in the embodiments and/or modifications of the invention can be made, and equivalents and modifications of some features of the invention can be made without departing from the spirit and scope of the invention.

Claims (9)

1. A cache content management method, characterized by: the method comprises the following steps:
receiving a data access request;
if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full;
if the cache is full, deleting the data with the lowest current heat value in the cache, then writing the data to be accessed in the database into the cache, and determining the current heat value of the data to be accessed.
2. The method for managing cache contents according to claim 1, wherein: and determining the current heat value of each data in the cache according to the local timestamp corresponding to each data.
3. The method for managing cache contents according to claim 1 or 2, wherein: the current heat value of each data in the cache is determined according to the sum of the original heat value of each data and the local timestamp corresponding to each data.
4. The method for managing cache contents according to claim 3, wherein: the current hot value of each data in the cache satisfies the following relation:
Hn=Hn-1+α·(Tn-X);
in the formula: hnA current heat value for each data in the cache; hn-1The original heat value of each data in the cache; t isnA local timestamp for each data in the cache; x is an initialization reference time stamp generated by the system; alpha is a preset time weight and the value range of alpha is more than 0 and less than or equal to 1.
5. The method for managing cache contents according to claims 1, 2, 3 and 4, wherein: the method further comprises the following steps:
receiving a data access request; and if the data to be accessed exists in the cache, determining the current heat value of the data to be accessed in the cache.
6. The method for managing cache contents according to claims 1, 2, 3 and 4, wherein: the method further comprises the following steps:
receiving a data access request; if the cache does not have the data to be accessed, acquiring the data to be accessed from the database, and judging whether the cache is full; and if the cache is not full, writing the data to be accessed in the database into the cache, and determining the current heat value of the data to be accessed.
7. A cache content management apparatus, characterized in that the management apparatus comprises:
the receiving module receives a data access request;
the data writing module writes data to be accessed in the database into a cache;
the heat value determining module is used for determining the current heat value of each datum in the cache;
the judging module is used for determining whether the cache has data to be accessed or not, acquiring the data to be accessed from the database if the cache does not have the data to be accessed, and judging whether the cache is full;
and the elimination module deletes the data with the lowest current heat value in the cache if the cache is full, then the data writing module writes the data to be accessed in the database into the cache, and the heat value determination module determines the current heat value of the data to be accessed.
8. An electronic device, characterized in that the electronic device comprises:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN202210074411.XA 2022-01-21 2022-01-21 Cache content management method and device, electronic equipment and storage medium Pending CN114461681A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210074411.XA CN114461681A (en) 2022-01-21 2022-01-21 Cache content management method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210074411.XA CN114461681A (en) 2022-01-21 2022-01-21 Cache content management method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114461681A true CN114461681A (en) 2022-05-10

Family

ID=81410849

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210074411.XA Pending CN114461681A (en) 2022-01-21 2022-01-21 Cache content management method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114461681A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069529A (en) * 2023-03-16 2023-05-05 天翼云科技有限公司 Dynamic caching method and device, electronic equipment and computer readable medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069529A (en) * 2023-03-16 2023-05-05 天翼云科技有限公司 Dynamic caching method and device, electronic equipment and computer readable medium

Similar Documents

Publication Publication Date Title
EP2612250B1 (en) Method and system for inserting cache blocks
US5778430A (en) Method and apparatus for computer disk cache management
US9767140B2 (en) Deduplicating storage with enhanced frequent-block detection
US7146467B2 (en) Method of adaptive read cache pre-fetching to increase host read throughput
US20110167230A1 (en) Selecting Storage Locations For Storing Data Based on Storage Location Attributes and Data Usage Statistics
US20140115261A1 (en) Apparatus, system and method for managing a level-two cache of a storage appliance
US7093072B2 (en) Methods for improved data caching
WO2023000536A1 (en) Data processing method and system, device, and medium
CN110888600A (en) Buffer area management method for NAND flash memory
CN106354664A (en) Solid state disk data transmission method and device
CN107562806B (en) Self-adaptive sensing acceleration method and system of hybrid memory file system
CN114461681A (en) Cache content management method and device, electronic equipment and storage medium
CN108228088B (en) Method and apparatus for managing storage system
CN114036089B (en) Data processing method and device, buffer, processor and electronic equipment
CN109002400B (en) Content-aware computer cache management system and method
US8732404B2 (en) Method and apparatus for managing buffer cache to perform page replacement by using reference time information regarding time at which page is referred to
US10949359B2 (en) Optimizing cache performance with probabilistic model
CN110162268A (en) It is calculated using real-time for the method and system by block data tissue and placement
US20140359228A1 (en) Cache allocation in a computerized system
CN112463652B (en) Data processing method and device based on cache consistency, processing chip and server
KR101144321B1 (en) Methods of managing buffer cache using solid state disk as an extended buffer and apparatuses for using solid state disk as an extended buffer
CN111639042B (en) Processing method and device for prefetching buffer data consistency
CN116069752A (en) Mixed prefetching method for distributed file system
CN115080459A (en) Cache management method and device and computer readable storage medium
WO2022156452A1 (en) Cache management method and apparatus, and device

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