Multi-level data caching method and terminal device
By calculating the cache level coefficient of the target data and storing it in the appropriate cache block, the problem of low cache response speed and high server pressure is solved, and the efficiency of data storage and response is improved.
Patent Information
- Application Number
- CN201811038785.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-09-06
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2038-09-06
AI Technical Summary
In the existing technology, the slowdown in data response speed in the cache causes great data calling pressure on the backend server, especially in the case of high concurrent access.
By obtaining the target data and its data information, calculate its cache level coefficient, determine the storage medium according to the level coefficient, store the data in the corresponding cache block, and ensure that the data is stored in the appropriate medium to improve storage and release efficiency. and response speed.
Effectively utilize the cache blocks of storage media to improve the efficiency of data storage and release, and improve the response speed of data in the cache.
Smart Images

Figure CN109240946B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and in particular relates to a multi-level data cache method and terminal equipment. Background Art
[0002] Applications or web pages will generate more and more application data during use, resulting in a large amount of concurrency in the application data call process, which in turn affects the response speed of the backend interface. In the prior art, cache space is added to the backend program or storage space to store the application data generated by the program during runtime in the cache space to alleviate the interface pressure of data storage and call.
[0003] However, when the interface accesses data with high concurrency, the response speed of the data in the cache will still decrease, resulting in a large data call pressure on the backend server. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a multi-level data caching method and terminal device to solve the problem in the prior art that the data response speed in the cache is reduced, resulting in great data call pressure on the background server.
[0005] A first aspect of an embodiment of the present invention provides a multi-level data cache method, comprising:
[0006] Obtaining target data to be cached and data information thereof; the data information includes the data volume of the target data;
[0007] Calculate the cache level coefficient of the target data according to the data information, and determine the storage medium storing the target data according to the cache level coefficient; the storage medium is preset with cache blocks of different storage amounts;
[0008] According to the storage capacity of the cache block in the storage medium and the data volume of the target data, the target data is stored in the corresponding cache block in the storage medium.
[0009] A second aspect of an embodiment of the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0010] Obtaining target data to be cached and data information thereof; the data information includes the data volume of the target data;
[0011] Calculate the cache level coefficient of the target data according to the data information, and determine the storage medium storing the target data according to the cache level coefficient; the storage medium is preset with cache blocks of different storage amounts;
[0012] According to the storage capacity of the cache block in the storage medium and the data volume of the target data, the target data is stored in the corresponding cache block in the storage medium.
[0013] A third aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the method of the first aspect.
[0014] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0015] The embodiment of the present invention obtains the target data to be cached and its data information, calculates the storage level coefficient of the target data according to the data information, and determines the storage medium capable of storing the target data according to the storage level coefficient. Secondly, according to the data volume of the target data and the storage volume of different storage blocks in the storage medium, the target data is stored in the corresponding cache block in the storage medium. In this way, it is ensured that the target data of different data information can be stored in the cache block in the appropriate storage medium, and on the premise of effectively utilizing the cache block of the storage medium, the efficiency of data storage and release, as well as the data response speed in the cache are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0017] Figure 1 is a flow chart of a multi-level caching method for data provided in Embodiment 1 of the present invention;
[0018] Figure 2 is a specific implementation flow chart of step S102 of the multi-level cache method for data provided in the second embodiment of the present invention;
[0019] Figure 3 is a flow chart of a multi-level caching method for data provided in Embodiment 3 of the present invention;
[0020] Figure 4 is a schematic diagram of a terminal device provided in Embodiment 4 of the present invention;
[0021] Figure 5 It is a schematic diagram of a terminal device provided in Embodiment 5 of the present invention. DETAILED DESCRIPTION
[0022] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.
[0023] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0024] See also Figure 1 , Figure 1 1 is a flowchart of a multi-level data caching method provided in Embodiment 1 of the present invention. The execution subject of the multi-level data caching method in this embodiment includes but is not limited to computers, servers and other devices, all of which have data caching functions. Figure 1 The multi-level data caching method shown may include the following steps:
[0025] In S101, target data to be cached and its data information are obtained; the data information includes the data volume of the target data.
[0026] In the process of using many application software or web pages, there will be a lot of application data. As the content information of application software and web pages becomes more and more complex, the number of users and the number of visits are increasing, and application software and web pages need to support more concurrency at the same time. Therefore, the calculations done by application servers and database servers are also increasing. However, application server resources are often limited, the number of requests that the database can accept per second is limited, and the reading and writing of files is also limited. Therefore, it is necessary to effectively use limited resources to provide the largest possible throughput. An effective way is to introduce cache. In each link, the request can directly obtain the target data from the cache and return it, thereby reducing the amount of calculation, effectively improving the response speed, and allowing limited resources to serve more users.
[0027] Data cache is generally a high-speed memory inside the hard disk, which is like a buffer in the computer to temporarily save some data for reading and re-reading. Hard disks with large data cache have great advantages in accessing scattered files. The user's request goes from the application interface to the network transmission, application service, and storage, and then returns to the interface to present the content. By putting the application data requested for the first time in the memory, the next time the page is displayed, the data saved last time will be displayed first, and the data will be requested at the same time. After the request is completed, the new data will be refreshed and cached again, which can greatly reduce the amount of data requests.
[0028] The target data to be cached is obtained, wherein the target data may include application data of application software or web pages during operation. The data information of the target data may include information such as the data type, data identifier, and data volume of the target data. By obtaining the target data to be cached and its data information, a suitable cache space is determined according to the data information to store the target data.
[0029] In S102, a cache level coefficient of the target data is calculated according to the data information, and a storage medium for storing the target data is determined according to the cache level coefficient; cache blocks with different storage capacities are preset in the storage medium.
[0030] Different storage media store different types of data and different ways of storing data. For example, the cache of a computer often uses random access memory (RAM), so after it is used up, the file will still be sent to a hard disk or other storage device for permanent storage. The largest cache in a computer is the memory bar, and the fastest is the L1 and L2 cache embedded in the central processing unit (CPU). The video memory of the graphics card is the cache for the graphics card computing chip, and there is also a 16M or 32M cache on the hard disk. Its working principle is: when the CPU wants to read data, it first searches from the CPU cache, and immediately reads and sends it to the CPU for processing if it finds it; if it does not find it, it reads from the relatively slow memory and sends it to the CPU for processing, and at the same time, the data block where the data is located is transferred into the cache, so that the entire block of data can be read from the cache in the future, without having to call the memory again. Such a reading mechanism has a very high hit rate for the CPU to read the cache, which means that 90% of the data that the CPU wants to read next time is in the CPU cache, and only about 10% needs to be read from the memory. This greatly saves the time that the CPU takes to read memory directly, and also means that the CPU basically does not need to wait when reading data.
[0031] Another caching mechanism is page caching, which directly generates static pages from dynamic pages and places them on the server. When users call the same page, the static page will be directly downloaded to the client, and there is no need to run the program and access the database, which greatly saves the server load. Every time a page is accessed, it will detect whether the corresponding cache page exists. If not, it will connect to the database to obtain the data rendering page and generate a cache page file, so that the page file will come into play the next time it is accessed.
[0032] The database cache is generally provided by the database, and a high-speed cache can be established for the table. In the database, users may execute the same query statement multiple times. In order to improve the query efficiency, the database will allocate a special area in the memory to store the user's most recent query. This area is the cache. If there is a table that does not change frequently in a project and the server receives a large number of identical queries for this table, data caching can play a good role. Usually, the effect will be more obvious for applications on the World Wide Web (Web). For example, there is a product information table in the database. The users of the enterprise need to query the product information through the web page. If the default query result is to display the product information that has been traded in the last month when the system is designed, then every time the user queries the product information by default, the information will be obtained from the cache, and the system query speed will be faster.
[0033] The browser cache mechanism is mainly the cache mechanism defined by the HyperText Transfer Protocol (HTTP), such as Expires and Cache-control fields, etc. It also includes cache mechanisms defined by non-HTTP protocols, for example, using HTML Meta tags. Among them, Expires is a header field in the Web server response message. When responding to an HTTP request, it tells the browser that the browser can directly obtain data from the browser cache before the expiration time without requesting again. Cache-Control and Expires have the same function, both of which indicate the validity period of the current resource and control whether the browser directly obtains data from the browser cache or resends a request to the server to obtain data.
[0034] The browser will cache the resources it has browsed, such as web pages, pictures, etc. If the resource is within the shelf life, the next time the same request is made, the cache will be used directly. After the expiration date, the last modification time of the resource will be brought, and the server will determine whether it is invalid. If it is invalid, new data will be returned to the browser and continue to be cached. The browser cache is stored on the hard disk of the user's computer. Every time the user uses the browser to read the cache, the cache data on the hard disk is first loaded into the memory and then read to the browser. The rules of browser-side caching are mainly defined in the HTTP protocol header and the meta tag of HTML. They respectively specify whether the browser uses the data in the cache directly or needs to go to the source server to obtain the updated version from the two dimensions of freshness and checksum. There is a cache data shelf life in the browser cache method. The cached data must meet the following conditions for the browser to consider it valid and new enough: it contains complete expiration time control header information, such as the HTTP protocol message header, and is still within the validity period; the browser has used this cached data and has checked its freshness in the last session, that is, when the user last accessed the data. If one of the above two conditions is met, the browser will directly obtain the cached data from the cache and render it to the browser.
[0035] Furthermore, in the browser cache mode, the verification value verification mechanism can be used to process the changed data. When the server returns the data, it sometimes carries the entity tag of the resource in the header information, which can be used as a verification mark for the browser to request again. If the verification mark does not match, it means that the data has been modified or expired, and the browser needs to re-acquire the data content.
[0036] The cache level coefficient of the target data is calculated according to the data information, and the storage medium of the target data is determined according to the cache level coefficient to determine in which storage medium the data is stored.
[0037] Optionally, a cache level coefficient of the target data may be determined according to the data volume and importance of the target data, and a storage medium for storing the target data may be determined according to the cache level coefficient.
[0038] There are many types of storage media, but each has different characteristics and is used for data with different attributes. For example, client cache supports dynamic configuration and can be uniformly controlled by the background interface. It is suitable for data that is not updated frequently but has a large number of accesses.
[0039] In S103, according to the storage capacity of the cache block in the storage medium and the data volume of the target data, the target data is stored in the corresponding cache block in the storage medium.
[0040] After the storage medium is determined, if the target data is directly stored in the storage medium, it will cause a lot of storage fragments, and there may be delays when calling the target data later. Therefore, it is necessary to uniformly manage the cache space of these data stored in the storage medium and store the target data in the appropriate cache block.
[0041] In this embodiment, the storage medium is divided according to the size of the storage capacity. By setting storage capacities of different sizes in the storage medium, the storage medium is managed uniformly to store data of appropriate size.
[0042] Furthermore, step S103 may specifically include:
[0043] Set the minimum cache block capacity in the storage medium as Cap_blo(min), and set the cache block capacity of the i-th cache block as Cap_blo(i)=A in an increasing manner according to the increasing factor A. i-1 Cap_blo(min);
[0044] If the data volume Cap_blo(pac) of the target data satisfies:
[0045] A i-2 Cap_blo(min)≤Cap_blo(pac)≤A i-1 Cap_blo(min), the target data is stored in the i-th cache block in the storage medium.
[0046] Specifically, the minimum cache block capacity in the storage medium is set to Cap_blo(min), and the cache block capacity of the i-th cache block is set to Cap_blo(i)=A in an increasing manner according to the increasing factor A. i-1 Cap_blo(min). In essence, it is a geometric progression with Cap_blo(min) as the first and A as the common ratio. The total cache capacity of the storage medium is determined based on the cache capacity of each block, which is the sum of the geometric progression:
[0047] Furthermore, the block capacity of the storage medium can be set according to a multiple relationship. For example, the minimum cache block capacity in the storage medium is set to Cap_blo(min), and the cache block capacity of the i-th cache block is set in an increasing multiple manner as: Cap_blo(i)=i·Cap_blo(min). In essence, the cache capacity of the storage medium is divided in an arithmetic progression with Cap_blo(min) as the first item. By dividing the cache blocks of different sizes in an increasing manner in the storage medium, data of different sizes are stored in corresponding blocks, which can reduce memory fragmentation in the storage medium, effectively manage the cache space, and maximize the cache space.
[0048] The above scheme obtains the target data to be cached and its data information, calculates the storage level coefficient of the target data according to the data information, and determines the storage medium capable of storing the target data according to the storage level coefficient. Secondly, according to the data volume of the target data and the storage volume of different storage blocks in the storage medium, the target data is stored in the corresponding cache block in the storage medium. In this way, it is ensured that the target data of different data information can be stored in the cache block in the appropriate storage medium, and on the premise of effectively utilizing the cache block of the storage medium, the efficiency of data storage and release, as well as the data response speed in the cache are improved.
[0049] See also Figure 2 , Figure 2 1 is a specific implementation flow chart of the multi-level cache method S102 for data provided in the first embodiment of the present invention, wherein the data information also includes the creation time of the target data, the latest access time when the target data was last accessed, and the update time when the target data was last updated. Figure 2 The multi-level data caching method shown may include the following steps:
[0050] In S201, a cache level coefficient of the target data is calculated according to the current time and various items of data information of the target data.
[0051] If a set of target data needs to be stored in a storage medium, the data information of the set of data needs to be determined first. In this embodiment, the data information may include the creation time, the latest access time, the data update time, the current time and the data volume of the target data.
[0052] Among them, the creation time of the target data is used to indicate the generation time of the latest target data. Since many types of new data may be generated during the operation of the application and web page, and the new data can overwrite the original old data, it is necessary to determine the generation time of the target data. The latest access time is used to indicate the time when the target data was last accessed or called, and is used to measure the freshness and frequency of use of the data. The data update time is used to indicate that during the operation of the application and web page, there will definitely be data modifications or updates. Therefore, the data update time is used to indicate the update time of data of the same data type or the same data identifier. The current time is used to indicate the moment when the cache level coefficient of the target data is calculated after the target data is obtained. The data volume is used to indicate the size of the target data that needs to be cached, and is used to reflect the size of the storage space of the storage medium that the target data will occupy.
[0053] Furthermore, in this embodiment, the data identifier of the target data can be determined first, and the data corresponding to the data identifier in the cache can be determined based on the data identifier, and the target data and the data in the cache can be compared. If there is no change, the target data will not be put into the cache, and the original cache data will continue to be used; if there is a change, the value or change situation of the changed target data will be determined, and the data of the changed part will be stored in the storage medium according to the change situation.
[0054] After determining the creation time, the latest access time, the data update time, the current time and the data volume of the target data, the cache level coefficient of the target data is calculated by the following formula:
[0055]
[0056] Among them, Qua is used to indicate the data volume of the target data; Time_cre is used to indicate the creation time; Time_cur is used to indicate the current time; Time_las is used to indicate the latest access time; and Time_mod is used to indicate the data update time.
[0057] Specifically, if the target data has a large data volume, a long creation time and a short latest access time, the target data has a higher cache level coefficient and can be stored in a storage medium of a higher level; at the same time, if the target data has a small data volume, a short creation time and a long latest access time, the target data has a lower cache level coefficient and can be stored in a storage medium of a lower level.
[0058] In S202, store the target data with a cache level coefficient greater than a preset first cache threshold into the client cache; store the target data with a cache level coefficient less than the first cache threshold and greater than a preset second cache threshold into the virtual machine cache; store the target data with a cache level coefficient less than the second cache threshold into the redis cache.
[0059] After determining the cache level coefficient of the target data, by presetting two level thresholds G 1 、G 2 ; and G 1 >G 2 ,compare the obtained G value with the two thresholds, and store the target data with different cache level coefficients into the corresponding storage media according to the characteristics of each storage medium. Among them, the client cache supports dynamic configuration and can be uniformly controlled by the background interface. The client cache is applicable to interfaces with infrequent data updates but high access volume; since redis does not support caching large objects well and consumes relatively more data input / output resources, the virtual machine cache is used to make up for the defects of the redis cache.
[0060] Specifically, if: G 1 <G, cache the data in the client cache; G 1 =G, cache the data in the client cache and / or the virtual machine cache; G 2 <G<G 1 , cache the data in the virtual machine cache; G = G 2 , cache the data in the virtual machine cache and / or the redis cache; G<G 2 , cache the data in the redis cache.
[0061] Furthermore, after each grading, the values of G 1 、G 2 will be updated according to the remaining cache space of each storage medium to make it in dynamic balance. When the cache space is low, increase the values of G 1 、G 2 regularly, so that fewer files meet the cache requirements and release the cache space as soon as possible; when the cache space is sufficient, decrease the values of G 1 、G 2 regularly, so that all the read data can enter the cache.
[0062] Furthermore, since the database has more storage resources, these target data can be stored in the database at the same time. Provided by the database, a high-speed cache can be established for the data table. The data in the database is temporarily stored in one location, and the same request is directly returned again, without the need to query various tables to obtain data again, which reduces the time to query the database and improves efficiency. Not all historical records are cached, and there must be a strategy. For example, only cache two months of data, and if the data is not requested again after being requested two months ago, it will be recycled, that is, the record will be erased, and only the recent multiple requests will be saved. Priority should be given to clearing those that have been used for a long time and have low usage, otherwise too much cache will lose the essence and meaning of the cache.
[0063] In the database, data is stored on disk. Although the database layer has corresponding cache, this database-level cache is generally aimed at query content. Generally, the corresponding cache of the database will only work when the data in the table has not changed. Sometimes it cannot reduce the huge pressure of adding, deleting, checking, and modifying the database by the business system. At this time, the general practice is to add a cache server between the database and the business server, such as the familiar redis. The data requested by the client for the first time is taken out of the database and placed in redis. Under the premise that the data does not expire or change, the next request will directly get the data from redis, which greatly relieves the pressure on the database.
[0064] The above scheme calculates the cache level coefficient of the target data according to the creation time, the latest access time, the data update time, the current time and the data volume of the target data, and compares the cache level coefficient with the preset cache threshold to determine the storage medium in which the target data can be stored. The target data corresponding to different cache level coefficients can be stored in different storage media, so that different types of target data can be called or processed through the corresponding storage media, thereby improving the data processing and response speed.
[0065] See also Figure 3 , Figure 3 1 is a flow chart of a multi-level cache method for data provided by Embodiment 1 of the present invention. Figure 3 The multi-level data caching method shown may include the following steps:
[0066] In S301, a call request for target data is received; the call request includes data information of the target data.
[0067] When a user initiates a data request through a browser, the browser will go through the following steps to obtain the data: Local cache stage: first search for the data locally. If the data is found and has not expired, this data will be used and no HTTP request will be sent to the server; Negotiation cache stage: If the corresponding data is found in the local cache, but it is not known whether the data is expired, an HTTP request will be sent to the server, and then the server will judge the request. If the requested data has not been modified or expired on the server, a 304 status code will be returned (which can be understood as a secret code from the server to the browser) to allow the browser to find the data locally; Cache failure stage: When the server finds that the requested resource has been modified, or this is a new request, the server returns the data and a 200 status code. The premise of this process is to find the data. If there is no data on the server, 404 is returned.
[0068] In this embodiment, the received call request for target data includes data information of the target data, wherein the data information may include: creation time of the target data, latest access time, data update time, current time and data volume, which is used to determine in which storage medium and cache block the required target data is stored through this information.
[0069] In S302, a storage medium storing the target data and a cache block therein are determined according to the data information.
[0070] In actual applications, after the target data is stored in the storage medium, the required target data will be called from the storage medium when the front end needs it. Generally, the target data can be queried through a Structured Query Language (SQL) statement, but two completely identical SQL statements are required to find the corresponding target data from the storage medium. If the conditions are different or the fields used are different, the database system will not use cache to optimize the query. In addition, for SQL statement parsing, it is case sensitive, that is to say, if the case of the keywords in the same query statement is different, it will be considered to be a different SQL statement. In view of this situation, in this embodiment, the storage location of the target data is automatically determined to search and call the target data.
[0071] After obtaining the call request for the target data, the data information is determined according to the call request, and the cache level coefficient of the required target data is calculated according to the data information. In order to ensure the uniformity of the query and storage data addresses, the specific cache level coefficient calculation method is the same as the implementation method in step S201 in Example 2, which will not be repeated here. After calculating the cache level coefficient of the target data, the storage medium of the target data is determined by a preset level threshold. The specific determination method is the same as step S202, which will not be repeated here. After determining the storage medium, the target data is determined in the cache block in the storage medium according to the data volume of the target data and the block capacity of the cache block in the storage medium. The specific determination method is the same as the implementation method in step S103, which will not be repeated here.
[0072] In S303, the target data is called from the cache block of the storage medium.
[0073] In actual applications, after the target data is stored in the storage medium, the required target data will be called from the storage medium when the front end needs it. Generally, the target data can be queried through structured SQL statements, but two completely identical SQL statements are required to find the corresponding target data from the storage medium. If the conditions are different or the fields used are different, the database system will not use cache to optimize queries. In addition, the MySQL database is different from other databases. For SQL statement parsing, it is case sensitive. That is to say, if the case of the keywords in the same query statement is different, it will also be considered to have used different SQL statements. In view of this situation, in this embodiment, the storage location of the target data is automatically determined to search and call the target data.
[0074] In this embodiment, after the storage medium storing the target data and the cache block therein are determined, the corresponding target data is directly called from the address of the cache block in the storage medium.
[0075] Furthermore, since the database has more storage resources, these target data can be stored in the database at the same time. However, when calling data, the corresponding storage medium and cache block can be determined first, and the data can be searched in the cache block of the storage medium. The interface will only access the database when the above cache is invalid or not enabled, which can greatly reduce the pressure on the database and improve the response speed of the interface.
[0076] The above scheme, after receiving the call request of the target data, determines the storage medium storing the target data and the cache block therein according to the data information of the target data in the call request, and finally calls the target data directly from the cache block of the storage medium. This avoids the uncertainty of searching for the target data through the entry search statement, improves the efficiency of calling or releasing the target data, and also improves the calling efficiency of the cache.
[0077] See also Figure 4 , Figure 4 4 is a schematic diagram of a terminal device provided by an embodiment of the present invention. The terminal device 400 may be a computer, a server or other device, and the terminal device has a multi-level cache function for data. The units included in the apparatus 400 of this embodiment are used to execute Figure 1 For details of the steps in the corresponding embodiments, please refer to Figure 1 and Figure 1 The device 400 of this embodiment includes: a data acquisition unit 401 , a medium determination unit 402 or a data storage unit 403 .
[0078] A data acquisition unit 401 is used to acquire target data to be cached and data information thereof; the data information includes the data volume of the target data;
[0079] A medium determination unit 402 is used to calculate a cache level coefficient of the target data according to the data information, and determine a storage medium for storing the target data according to the cache level coefficient; the storage medium is pre-set with cache blocks of different storage amounts;
[0080] The data storage unit 403 is used to store the target data in a corresponding cache block in the storage medium according to the storage capacity of the cache block in the storage medium and the data volume of the target data.
[0081] The storage medium includes a client cache, a virtual machine cache and a redis cache;
[0082] Further, the medium determination unit 402 may include:
[0083] A coefficient calculation unit, used for calculating a cache level coefficient of the target data according to the current time and each item of data information of the target data;
[0084] A coefficient comparison unit is used to store target data whose cache level coefficient is greater than a preset first cache threshold in the client cache; store target data whose cache level coefficient is less than the first cache threshold and greater than a preset second cache threshold in the virtual machine cache; and store target data whose cache level coefficient is less than the second cache threshold in the redis cache.
[0085] Furthermore, the coefficient calculation unit may be specifically used for:
[0086] The cache level coefficient of the target data is calculated by the following formula:
[0087]
[0088] Among them, Qua is used to indicate the data volume of the target data; Time_cre is used to indicate the creation time; Time_cur is used to indicate the current time; Time_las is used to indicate the latest access time; and Time_mod is used to indicate the data update time.
[0089] Furthermore, the data storage unit 403 may include:
[0090] A capacity setting unit, used to set the minimum cache block capacity in the storage medium to Cap_blo(min), and the cache block capacity of the i-th cache block to Cap_blo(i)=A i-1 Cap_blo(min);
[0091] A block storage unit is used for if the data volume Cap_blo(pac) of the target data satisfies:
[0092] A i-2 Cap_blo(min)≤Cap_blo(pac)≤A i-1 Cap_blo(min), the target data is stored in the i-th cache block in the storage medium; wherein A is used to represent the ratio of the capacities of cache blocks of adjacent sizes.
[0093] Furthermore, the terminal device may also include:
[0094] A data request unit, configured to receive a call request for target data; the call request includes data information of the target data;
[0095] A storage determination unit, configured to determine a storage medium storing the target data and a cache block therein according to the data information;
[0096] A data calling unit is used to call the target data from the cache block of the storage medium.
[0097] The above scheme obtains the target data to be cached and its data information, calculates the storage level coefficient of the target data according to the data information, and determines the storage medium capable of storing the target data according to the storage level coefficient. Secondly, according to the data volume of the target data and the storage volume of different storage blocks in the storage medium, the target data is stored in the corresponding cache block in the storage medium. In this way, it is ensured that the target data of different data information can be stored in the cache block in the appropriate storage medium, and on the premise of effectively utilizing the cache block of the storage medium, the efficiency of data storage and release, as well as the data response speed in the cache are improved.
[0098] Figure 5 Schematic diagram of a terminal device provided by an embodiment of the present invention. Figure 5 As shown, the terminal device 5 of this embodiment includes: a processor 50, a memory 51, and a computer program 52 stored in the memory 51 and executable on the processor 50. When the processor 50 executes the computer program 52, the steps in the above-mentioned multi-level cache method embodiment of each data are implemented, such as Figure 1 Alternatively, when the processor 50 executes the computer program 52, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 4 The functions of units 401 to 403 are shown.
[0099] Exemplarily, the computer program 52 may be divided into one or more modules / units, which are stored in the memory 51 and executed by the processor 50 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program 52 in the terminal device 5.
[0100] The terminal device 5 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will appreciate that Figure 5 It is only an example of the terminal device 5 and does not constitute a limitation of the terminal device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0101] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0102] The memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FC), etc. equipped on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used to store the computer program and other programs and data required by the terminal device. The memory 51 may also be used to temporarily store data that has been output or is to be output.
[0103] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0104] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0105] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0106] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium.
[0107] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. A multi-level data caching method, It is characterized in that include: Get the target data and data information that need to be cached; The data information includes the data volume of the target data; Calculate the cache level coefficient of the target data according to the data information, and determine the storage medium for storing the target data according to the cache level coefficient; The storage medium is preset with cache blocks of different storage amounts; According to the storage capacity of the cache block in the storage medium and the data volume of the target data, storing the target data in the corresponding cache block of the storage medium; The storage medium includes a client cache, a virtual machine cache and a redis cache; The step of calculating a cache level coefficient of the target data according to the data information, and determining a storage medium for storing the target data according to the cache level coefficient, includes: Calculate the cache level coefficient of the target data according to the current time and each item of data information of the target data; The target data whose cache level coefficient is greater than the preset first cache threshold is stored in the client cache; the target data whose cache level coefficient is less than the first cache threshold and greater than the preset second cache threshold is stored in the virtual machine cache; the target data whose cache level coefficient is less than the second cache threshold is stored in the redis cache; The data information also includes the creation time, the latest access time and the data update time of the target data; the data information according to the current time and each item of the target data includes: The cache level coefficient of the target data is calculated by the following formula: in, A data volume for representing the target data; Used to indicate the creation time; Used to indicate the current time; Used to indicate the latest access time; Used to indicate the data update time.
2. The multi-level cache method for data according to claim 1, It is characterized in that According to the storage capacity of the cache block in the storage medium and the data volume of the target data, storing the target data in the corresponding cache block in the storage medium includes: Set the minimum cache block capacity in the storage medium to , the cache block capacity of the i-th cache block is ; If the data volume of the target data satisfy: , the target data is stored in the i-th cache block in the storage medium; wherein A is used to represent the ratio of the capacities of cache blocks of adjacent sizes.
3. The multi-level cache method for data according to any one of claims 1 to 2, It is characterized in that The method further comprises: Receiving a call request for target data; the call request includes data information of the target data; Determine a storage medium storing the target data and a cache block therein according to the data information; The target data is called from the cache block of the storage medium.
4. A terminal device, It is characterized in that The method comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and wherein when the processor executes the computer program, the following steps are implemented: Obtaining target data to be cached and data information thereof; the data information includes the data volume of the target data; Calculate the cache level coefficient of the target data according to the data information, and determine the storage medium storing the target data according to the cache level coefficient; the storage medium is preset with cache blocks of different storage amounts; According to the storage capacity of the cache block in the storage medium and the data volume of the target data, storing the target data in the corresponding cache block of the storage medium; The storage medium includes a client cache, a virtual machine cache, and a redis cache; the cache level coefficient of the target data is calculated according to the data information, and the storage medium for storing the target data is determined according to the cache level coefficient, including: Calculate the cache level coefficient of the target data according to the current time and each item of data information of the target data; The target data whose cache level coefficient is greater than the preset first cache threshold is stored in the client cache; the target data whose cache level coefficient is less than the first cache threshold and greater than the preset second cache threshold is stored in the virtual machine cache; the target data whose cache level coefficient is less than the second cache threshold is stored in the redis cache; The data information also includes the creation time, the latest access time and the data update time of the target data; the data information according to the current time and each item of the target data includes: The cache level coefficient of the target data is calculated by the following formula: in, A data volume for representing the target data; Used to indicate the creation time; Used to indicate the current time; Used to indicate the latest access time; Used to indicate the data update time.
5. The multi-level cache method for data as claimed in claim 4, It is characterized in that According to the storage capacity of the cache block in the storage medium and the data volume of the target data, storing the target data in the corresponding cache block in the storage medium includes: Set the minimum cache block capacity in the storage medium to , the cache block capacity of the i-th cache block is ; If the data volume of the target data satisfy: , the target data is stored in the i-th cache block in the storage medium; wherein A is used to represent the ratio of the capacities of cache blocks of adjacent sizes.
6. A computer-readable storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
