CN112035526A - Data caching method, device, equipment and readable storage medium - Google Patents
Data caching method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN112035526A CN112035526A CN202010903867.3A CN202010903867A CN112035526A CN 112035526 A CN112035526 A CN 112035526A CN 202010903867 A CN202010903867 A CN 202010903867A CN 112035526 A CN112035526 A CN 112035526A
- Authority
- CN
- China
- Prior art keywords
- interface
- cache
- time
- data
- caching
- 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.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24552—Database cache management
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
The embodiment of the application provides a data caching method, a data caching device, data caching equipment and a readable storage medium, wherein the caching time of an interface is obtained and is the storage time of data accessed by a calling interface in a cache, and the caching time of the interface is updated in response to cache data failure, wherein the cache data is obtained by writing the data accessed by the interface into the cache, and the data is written into the cache in response to the data accessed by the interface and by taking the updated caching time of the interface as the storage time of the data. It can be understood that the invalidation of the cached data is at least related to the timeliness of the data, and thus, the data caching method provided by the embodiment of the present application can adaptively adjust the caching time of the interface according to the invalidation of the cached data, so that the caching time of the interface is related to the timeliness of the data, and thus, the hit rate of the cached data is improved.
Description
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a data caching method, apparatus, device, and readable storage medium.
Background
With the increase of the number of active users and transaction amount of the mobile banking, the access amount of the background system of the mobile banking is larger and larger, and the system faces higher performance pressure. In order to relieve performance pressure caused by large access amount of a background system of a mobile phone bank, interface data can be written into a cache from a system database, and the interface data can be directly read from the cache in the valid period of the cache data without accessing the background system and the system database. However, the cache hit rate in the prior art is low, and the background system and the database still need to be revisited to read data after the cache data is invalid.
Disclosure of Invention
The application provides a data caching method, a data caching device, data caching equipment and a readable storage medium, and the data caching method comprises the following steps:
a data caching method, comprising:
obtaining the cache time of an interface, wherein the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
updating the cache time of the interface in response to cache data invalidation, wherein the cache data is obtained by writing the data accessed by the interface into a cache;
and responding to the interface to access the data, and writing the data into a cache by taking the updated cache time of the interface as the storage time of the data.
Optionally, obtaining the cache time of the interface includes:
acquiring a preset access weight of the interface;
and multiplying the preset caching time by the access weight to obtain the caching time of the interface.
Optionally, obtaining the preset access weight of the interface includes:
collecting the accumulated access amount of the interface, wherein the accumulated access amount is the data access amount of the interface in a preset period;
calculating an average access amount, wherein the average access amount is an average value of the accumulated access amounts of all interfaces in the period;
and calculating the ratio of the accumulated access amount to the average access amount as the access weight of the interface.
Optionally, in response to a cache data failure, updating the cache time of the interface includes:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
Optionally, reducing the buffering time of the interface includes:
reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface;
if the first cache time of the interface is not less than a preset minimum threshold value, updating the cache time of the interface to the first cache time.
If the first cache time of the interface is smaller than the minimum threshold value, updating the cache time of the interface to the minimum threshold value.
Optionally, increasing the buffering time of the interface includes:
increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface;
if the second cache time of the interface is not greater than a preset maximum threshold value, updating the cache time of the interface to the second cache time;
if the second cache time of the interface is greater than the maximum threshold, updating the cache time of the interface to the maximum threshold.
A data caching apparatus, comprising:
the device comprises a cache time determining unit, a cache time determining unit and a cache processing unit, wherein the cache time determining unit is used for acquiring the cache time of an interface, and the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
a cache time updating unit, configured to update the cache time of the interface in response to a cache data failure, where the cache data is obtained by writing the data accessed by the interface into a cache;
and the data caching unit is used for responding to the data accessed by the interface, taking the updated caching time of the interface as the storage time of the data, and writing the data into a cache.
Optionally, the cache time updating unit is configured to update the cache time of the interface in response to a cache data failure, and includes: the cache time updating unit is specifically configured to:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
A data caching device comprising: a memory and a processor;
the memory is used for storing programs;
the processor is configured to execute the program to implement the steps of the data caching method.
A readable storage medium, having stored thereon a computer program which, when executed by a processor, carries out the steps of the data caching method as described above.
According to the technical scheme, the data caching method, the data caching device, the data caching equipment and the readable storage medium, provided by the embodiment of the application, are used for obtaining the caching time of the interface, wherein the caching time of the interface is the storage time of the data accessed by the calling interface in the cache, and updating the caching time of the interface in response to the invalidation of the caching data, wherein the caching data is obtained by writing the data accessed by the interface into the cache, and the data is written into the cache in response to the data accessed by the interface and the updated caching time of the interface is the storage time of the data. It can be understood that the invalidation of the cached data is at least related to the timeliness of the data, and thus, the data caching method provided by the embodiment of the present application can adaptively adjust the caching time of the interface according to the invalidation of the cached data, so that the caching time of the interface is related to the timeliness of the data, and thus, the hit rate of the cached data is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a specific implementation of a data caching method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a data caching method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a data caching apparatus according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a data caching device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The data caching method provided by the embodiment of the application is applied to but not limited to determining the caching time of the data of the interface in the mobile phone bank. An optional application scenario of this embodiment is as follows: the mobile phone bank comprises n interfaces, in order to reduce the pressure of the system, data accessed by the calling interface is written into the cache, and when the data needs to be accessed again, the data is directly read from the cache. It should be noted that the present embodiment may also be applied to determining the cache time of data in other scenarios, for example, determining the cache time of the webpage information cache data of the web site, which is not limited in this embodiment.
Fig. 1 is a schematic flow chart of a data caching method according to an embodiment of the present application, and as shown in fig. 1, the method may specifically include the following steps S101 to S111.
S101, collecting the accumulated access amount of each interface.
In this embodiment, the accumulated access amount of each interface is a data access amount of the interface in a preset period, that is, a data amount of the interface access called in the preset period. It should be noted that the accumulated access amount collection method of the interface can be referred to in the prior art.
And S102, calculating the average access amount of all interfaces.
In this embodiment, the average access amount of all interfaces is an average value of the cumulative access amounts of all interfaces.
For example, the number of interfaces is denoted as n, and the average value of the access amounts of all the interfaces is calculated according to formula (1) as follows:
in the formula:is the average access amount, NiCumulative access volume, for any interface, i ∈ [1, n ]]。
And S103, calculating the access weight of the interface.
In this embodiment, the access weight of the interface is a ratio of an accumulated access amount to an average access amount of the interface, that is, a ratio of an access amount of the interface in a preset period to an average access amount of all the interfaces in the preset period, and it should be noted that the size of the access weight of the interface may represent an access frequency of the interface, for example, the larger the access weight of the interface is, the higher the access frequency of the interface is.
Using interface as interface kiFor example, interface kiSee equation (2), as follows:
in the formula, FiIs an interface kiAccess weight of, NiIs an interface kiThe accumulated amount of access of (a) is,is the average access volume.
And S104, acquiring the initial caching time of the interface.
In this embodiment, the initial buffering time of the interface is the buffering time of the interface at the initial time of the preset period, and the buffering time of the interface is the storage time of the data accessed by the calling interface in the buffer.
The method for calculating the initial caching time of the interface comprises the following steps: and multiplying the preset caching time by the access weight of the interface to obtain the initial caching time of the interface.
In this embodiment, the preset cache time is set according to actual requirements, and it should be noted that, in actual application, the preset cache times of different interfaces are the same.
In this embodiment, the interface is used as the interface kiFor example, interface kiA specific calculation method of the initial cache time can be seen in formula (3)
Ti0=TC*Fi (3)
In the formula, Ti0Is an interface kiInitial buffering time of TCFor presetting the buffer time, FiIs an interface kiThe access weight of (2).
It should be noted that, when calculating the access weight of the interface, the average access amount is the same, and the access amount of the interface is proportional to the access weight of the interface, that is, the access weight of the interface with the larger access amount is higher, and the access weight of any interface can indicate the access frequency of the interface.
In summary, the method considers the influence of the access frequency on the cache time, determines different initial cache times for the interfaces with different access frequencies, and if the cache time of the interface with high access frequency is long, the hit rate of the cache data of the interface is high.
And S105, responding to the update failure of the cache data, and reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface.
In this embodiment, the cache data is obtained by writing the data accessed by the interface into the cache, and the update failure of the cache data is triggered by the update of the data.
It should be noted that, after data accessed by any interface is written into the cache, cache data of the data is obtained, and when the data is updated in the system, the cache data corresponding to the data in the cache is inconsistent with the data, which results in invalidation of the cache data.
It should be noted that, if the update failure of the cached data is the first failure (update failure or expiration failure) in a preset period, the caching time of the interface is the initial caching time of the interface, and the method for calculating the first caching time of the interface includes: and subtracting a preset first value from the buffer time of the interface.
In response to the update failure of the cached data, the first cache time calculation method of the interface is as follows according to formula (4):
Ti1=Ti-ΔTsub (4)
in the formula, Ti1Is an interface kiFirst buffer time, Δ TsubIs a first value, TiIs an interface kiWhen the cached data is first invalidated (update invalidation or expiration invalidation) in a preset period, Ti=Ti0。
It should be noted that the first value may be set according to a frequency of cache data update invalidation, and the first value is smaller than the initial cache time, it is understood that the first value indicates a timeliness of the cache data, and when the timeliness of the cache data is higher, that is, the update frequency is higher, the first value is larger.
And S106, under the condition that the first cache time of the interface is not less than the preset minimum threshold value, updating the cache time of the interface into the first cache time.
In this embodiment, the minimum threshold is set according to actual requirements, and optionally, the minimum threshold is the minimum value of the cache times of all the interfaces, and is recorded as Tmin,Tmin=min{T1,T2,...,Tn}。
In the above example, if Ti1≥TminThen, T is updatedi=Ti1。
And S107, updating the cache time of the interface to be the minimum threshold value under the condition that the first cache time of the interface is smaller than the preset minimum threshold value.
In the above example, if Ti1<TminThen, T is updatedi=Tmin
And S108, responding to the expiration of the cache data, and increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface.
In this embodiment, the expiration of the cached data is triggered by the expiration of the retention time of the data in the cache.
It should be noted that, if the update failure of the cached data is the first failure (update failure or expiration failure) in the preset period, the caching time of the interface is the initial caching time of the interface, and the method for calculating the second caching time of the interface includes: and increasing the buffer time of the interface by a preset second value.
In response to the expiration of the cached data, the second cache time calculation method of the interface is as follows, see formula (4):
Ti2=Ti+ΔTadd (4)
in the formula, Ti2Is an interface kiSecond buffer time, Δ TaddIs a second value, TiIs an interface kiWhen the cached data is first invalidated (update invalidation or expiration invalidation) in a preset period, Ti=Ti0。
It should be noted that the second value may be set according to a frequency of cache data expiration, and it is understood that the second value indicates a time effectiveness of the interface, and the second value is larger when the time effectiveness of the interface is lower, that is, the update frequency is lower.
And S109, updating the buffer time of the interface to the second buffer time under the condition that the second buffer time of the interface is not larger than the preset maximum threshold value.
In this embodiment, the maximum threshold is set according to actual requirements, and optionally, the maximum threshold is a maximum value of the cache time of all the interfaces, and is denoted as Tmax,Tmax=max{T1,T2,...,Tn}。
In the above example, if Ti2≤TmaxThen, T is updatedi=Ti2。
And S110, updating the cache time of the interface to be the maximum threshold value under the condition that the second cache time of the interface is greater than the preset maximum threshold value.
In the above example, if Ti1>TmaxThen, T is updatedi=Tmax
It should be noted that, when the cache data fails (in the first case or the second case), the cache data in the cache is deleted.
It should be noted that, in S105 to S107, taking the first failure in the preset period as an example of updating the failure, the method of updating the cache time of the interface, and in S108 to S110, taking the first failure in the preset period as an expired failure, the method of updating the cache time of the interface, as shown in fig. 1, there is no restriction on the order between S105 to S107 and S108 to S110.
And S111, responding to the interface access data, taking the updated cache time of the interface as the data storage time, and writing the data into the cache.
In this embodiment, the updated cache time of the interface is used as a time tag for calling data accessed by the interface, and the data is stored in the cache, where the time tag is the storage time of the data, which may be specifically referred to in the prior art.
According to the technical scheme, the data caching method provided by the embodiment of the application obtains the caching time of the interface, the caching time of the interface is the storage time of the data accessed by the calling interface in the cache, and the caching time of the interface is updated in response to the cache data failure, wherein the cache data is obtained by writing the data accessed by the interface into the cache, the data is accessed in response to the interface, and the data is written into the cache in response to the cache data with the updated caching time of the interface as the storage time of the data. It can be understood that the invalidation of the cached data is at least related to the timeliness of the data, and thus, the data caching method provided by the embodiment of the present application can adaptively adjust the caching time of the interface according to the invalidation of the cached data, so that the caching time of the interface is related to the timeliness of the data, and thus, the hit rate of the cached data is improved.
Further, when the cache data update is invalid, the timeliness of the data accessed by the interface is high, so that the cache time of the interface is reduced by the method. When the cache data is out of date, the timeliness of the data accessed by the interface is low, so that the method increases the cache time of the interface, namely, the method can shorten the cache time of the interface with high timeliness and prolong the cache time of the interface with low timeliness.
Further, the method considers the influence of the access frequency on the cache time, determines different initial cache times for the interfaces with different access frequencies according to the access weight of the interfaces, and the cache time of the interface with high access frequency is long, so that the hit rate of the cache data is further improved.
Therefore, compared with the prior art that fixed cache time is set for all the interfaces, the method integrates the timeliness of data and the influence of the access frequency of the interfaces on the cache time, adaptively determines the cache time of each interface, improves the hit rate of cache data on the premise of keeping the data consistency, further reduces the access times of a system database, relieves the performance pressure of the system, and improves the response speed of the interfaces.
For example, data with high access frequency and low timeliness is given longer effective time in the cache, and when the interface is accessed by a mobile phone bank, the cache hit probability is high, so that frequent access to a system database is avoided, and the response speed of the interface is improved.
It should be noted that fig. 1 is only an optional specific implementation of the data caching method provided in the embodiment of the present application, and the method may further include other specific implementations, for example, the preset caching time may be directly used as the initial caching time, and for example, the access weight of the interface may be a ratio of the number of calls of the interface in the preset period to an average value of the number of calls of all interfaces in the preset period.
To sum up, the data caching method provided in the embodiment of the present application may be summarized as a schematic flow chart of the data caching method shown in fig. 2, and as shown in fig. 2, the method may include S201 to S203.
S201, obtaining the buffer time of the interface.
In this embodiment, the cache time of the interface is the storage time of the data accessed by the calling interface in the cache.
It should be noted that, at the initial time of the preset period, the buffering time of the interface is the initial buffering time of the interface, optionally, the initial buffering time of the interface may be determined according to the access weight, specifically refer to S104, and it should be noted that the method for obtaining the initial buffering time of the interface may further include other methods, specifically refer to the prior art.
And S202, responding to the failure of the cache data, and updating the cache time of the interface.
In this embodiment, the cache data is obtained by writing data accessed by the interface into the cache, and the cache data failure means that the cache data is inconsistent with the data or that the storage time of the cache data expires, so that the cache data is removed from the cache.
Optionally, the method for updating the cache time of the interface in response to the cache data invalidation includes multiple methods, optionally, when the update of the data triggers the cache data invalidation, the cache time of the interface is reduced, which may specifically refer to S105 to S107 described above, and optionally, when the storage time of the cache data expires, the cache time of the interface is increased, which may specifically refer to S108 to S110 described above.
It should be noted that, in response to the cache data failure, the method for updating the cache time of the interface is not limited to the method described in S105 to S107 or S108 to S110, and may also include other methods, which is not limited in this application.
And S203, responding to the interface access data, taking the updated cache time of the interface as the data storage time, and writing the data into the cache.
In this embodiment, the updated cache time of the interface is used as a time tag for calling data accessed by the interface, and the data is stored in the cache, where the time tag is the storage time of the data, which may be specifically referred to in the prior art.
According to the technical scheme, the data caching method provided by the embodiment of the application obtains the caching time of the interface, the caching time of the interface is the storage time of the data accessed by the calling interface in the cache, and the caching time of the interface is updated in response to the cache data failure, wherein the cache data is obtained by writing the data accessed by the interface into the cache, the data is accessed in response to the interface, and the data is written into the cache in response to the cache data with the updated caching time of the interface as the storage time of the data. It can be understood that the invalidation of the cached data is at least related to the timeliness of the data, and thus, the data caching method provided by the embodiment of the present application can adaptively adjust the caching time of the interface according to the invalidation of the cached data, so that the caching time of the interface is related to the timeliness of the data, and thus, the hit rate of the cached data is improved.
Fig. 3 shows a schematic structural diagram of a data caching apparatus according to an embodiment of the present application, and as shown in fig. 3, the apparatus may include:
a cache time determining unit 301, configured to obtain a cache time of an interface, where the cache time of the interface is a storage time of data called by the interface in a cache;
a cache time updating unit 302, configured to update the cache time of the interface in response to a cache data failure, where the cache data is obtained by writing the data accessed by the interface into a cache;
a data caching unit 303, configured to respond to the interface to access the data, and write the data into a cache with the updated caching time of the interface as a storage time of the data.
Optionally, the obtaining the buffering time of the interface by the buffering time determining unit includes: the buffer time determination unit is specifically configured to:
acquiring a preset access weight of the interface;
and multiplying the preset caching time by the access weight to obtain the caching time of the interface.
Optionally, the cache time determining unit is configured to obtain a preset access weight of the interface, and includes: the buffer time determination unit is specifically configured to:
collecting the accumulated access amount of the interface, wherein the accumulated access amount is the data access amount of the interface in a preset period;
calculating an average access amount, wherein the average access amount is an average value of the accumulated access amounts of all interfaces in the period;
and calculating the ratio of the accumulated access amount to the average access amount as the access weight of the interface.
Optionally, the cache time updating unit is configured to update the cache time of the interface in response to a cache data failure, and includes: the buffer time update unit is specifically configured to:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
Optionally, the cache time updating unit is configured to reduce the cache time of the interface, and includes: the buffer time update unit is specifically configured to:
reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface;
if the first cache time of the interface is not less than a preset minimum threshold value, updating the cache time of the interface to the first cache time.
If the first cache time of the interface is smaller than the minimum threshold value, updating the cache time of the interface to the minimum threshold value.
Optionally, the cache time updating unit is configured to increase the cache time of the interface, and includes: the buffer time update unit is specifically configured to:
increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface;
if the second cache time of the interface is not greater than a preset maximum threshold value, updating the cache time of the interface to the second cache time;
if the second cache time of the interface is greater than the maximum threshold, updating the cache time of the interface to the maximum threshold.
Fig. 4 shows a schematic structural diagram of the data caching device, which may include: at least one processor 401, at least one communication interface 402, at least one memory 403 and at least one communication bus 404;
in the embodiment of the present application, the number of the processor 401, the communication interface 402, the memory 403 and the communication bus 404 is at least one, and the processor 401, the communication interface 402 and the memory 403 complete communication with each other through the communication bus 404;
the memory 403 may include a high-speed RAM memory, and may further include a non-volatile memory (non-volatile memory) or the like, such as at least one disk memory;
the memory stores programs, and the processor can execute the programs stored in the memory, so that the steps of the data caching method provided by the embodiment of the application are realized as follows:
obtaining the cache time of an interface, wherein the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
updating the cache time of the interface in response to cache data invalidation, wherein the cache data is obtained by writing the data accessed by the interface into a cache;
and responding to the interface to access the data, and writing the data into a cache by taking the updated cache time of the interface as the storage time of the data.
Optionally, obtaining the cache time of the interface includes:
acquiring a preset access weight of the interface;
and multiplying the preset caching time by the access weight to obtain the caching time of the interface.
Optionally, obtaining the preset access weight of the interface includes:
collecting the accumulated access amount of the interface, wherein the accumulated access amount is the data access amount of the interface in a preset period;
calculating an average access amount, wherein the average access amount is an average value of the accumulated access amounts of all interfaces in the period;
and calculating the ratio of the accumulated access amount to the average access amount as the access weight of the interface.
Optionally, in response to a cache data failure, updating the cache time of the interface includes:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
Optionally, reducing the buffering time of the interface includes:
reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface;
if the first cache time of the interface is not less than a preset minimum threshold value, updating the cache time of the interface to the first cache time.
If the first cache time of the interface is smaller than the minimum threshold value, updating the cache time of the interface to the minimum threshold value.
Optionally, increasing the buffering time of the interface includes:
increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface;
if the second cache time of the interface is not greater than a preset maximum threshold value, updating the cache time of the interface to the second cache time;
if the second cache time of the interface is greater than the maximum threshold, updating the cache time of the interface to the maximum threshold.
An embodiment of the present application further provides a readable storage medium, where the readable storage medium may store a computer program suitable for being executed by a processor, and when the computer program is executed by the processor, the computer program implements the steps of the data caching method provided in the embodiment of the present application, as follows:
obtaining the cache time of an interface, wherein the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
updating the cache time of the interface in response to cache data invalidation, wherein the cache data is obtained by writing the data accessed by the interface into a cache;
and responding to the interface to access the data, and writing the data into a cache by taking the updated cache time of the interface as the storage time of the data.
Optionally, obtaining the cache time of the interface includes:
acquiring a preset access weight of the interface;
and multiplying the preset caching time by the access weight to obtain the caching time of the interface.
Optionally, obtaining the preset access weight of the interface includes:
collecting the accumulated access amount of the interface, wherein the accumulated access amount is the data access amount of the interface in a preset period;
calculating an average access amount, wherein the average access amount is an average value of the accumulated access amounts of all interfaces in the period;
and calculating the ratio of the accumulated access amount to the average access amount as the access weight of the interface.
Optionally, in response to a cache data failure, updating the cache time of the interface includes:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
Optionally, reducing the buffering time of the interface includes:
reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface;
if the first cache time of the interface is not less than a preset minimum threshold value, updating the cache time of the interface to the first cache time.
If the first cache time of the interface is smaller than the minimum threshold value, updating the cache time of the interface to the minimum threshold value.
Optionally, increasing the buffering time of the interface includes:
increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface;
if the second cache time of the interface is not greater than a preset maximum threshold value, updating the cache time of the interface to the second cache time;
if the second cache time of the interface is greater than the maximum threshold, updating the cache time of the interface to the maximum threshold.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A method for caching data, comprising:
obtaining the cache time of an interface, wherein the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
updating the cache time of the interface in response to cache data invalidation, wherein the cache data is obtained by writing the data accessed by the interface into a cache;
and responding to the interface to access the data, and writing the data into a cache by taking the updated cache time of the interface as the storage time of the data.
2. The method of claim 1, wherein obtaining the buffer time of the interface comprises:
acquiring a preset access weight of the interface;
and multiplying the preset caching time by the access weight to obtain the caching time of the interface.
3. The method of claim 2, wherein the obtaining the preset access weight of the interface comprises:
collecting the accumulated access amount of the interface, wherein the accumulated access amount is the data access amount of the interface in a preset period;
calculating an average access amount, wherein the average access amount is an average value of the accumulated access amounts of all interfaces in the period;
and calculating the ratio of the accumulated access amount to the average access amount as the access weight of the interface.
4. The method according to any one of claims 1 to 3, wherein the updating the cache time of the interface in response to a cache data failure comprises:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
5. The method of claim 4, wherein the reducing the cache time of the interface comprises:
reducing the cache time of the interface by a preset first numerical value to obtain the first cache time of the interface;
if the first cache time of the interface is not less than a preset minimum threshold value, updating the cache time of the interface to the first cache time;
if the first cache time of the interface is smaller than the minimum threshold value, updating the cache time of the interface to the minimum threshold value.
6. The method of claim 4, wherein the increasing the cache time of the interface comprises:
increasing the cache time of the interface by a preset second numerical value to obtain second cache time of the interface;
if the second cache time of the interface is not greater than a preset maximum threshold value, updating the cache time of the interface to the second cache time;
if the second cache time of the interface is greater than the maximum threshold, updating the cache time of the interface to the maximum threshold.
7. A data caching apparatus, comprising:
the device comprises a cache time determining unit, a cache time determining unit and a cache processing unit, wherein the cache time determining unit is used for acquiring the cache time of an interface, and the cache time of the interface is the storage time of data accessed by calling the interface in a cache;
a cache time updating unit, configured to update the cache time of the interface in response to a cache data failure, where the cache data is obtained by writing the data accessed by the interface into a cache;
and the data caching unit is used for responding to the data accessed by the interface, taking the updated caching time of the interface as the storage time of the data, and writing the data into a cache.
8. The apparatus of claim 7, wherein the buffer time updating unit is configured to update the buffer time of the interface in response to a buffer data failure, and comprises: the cache time updating unit is specifically configured to:
in response to an update failure of cached data, reducing the caching time of the interface, the update failure being triggered by an update of the data;
increasing the caching time of the interface in response to an expiration of the cached data, the expiration being triggered by expiration of a retention time of the data in a cache.
9. A data caching apparatus, comprising: a memory and a processor;
the memory is used for storing programs;
the processor is used for executing the program and realizing the steps of the data caching method according to any one of claims 1 to 6.
10. A readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the data caching method as claimed in any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010903867.3A CN112035526B (en) | 2020-09-01 | 2020-09-01 | Data caching method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010903867.3A CN112035526B (en) | 2020-09-01 | 2020-09-01 | Data caching method, device, equipment and readable storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112035526A true CN112035526A (en) | 2020-12-04 |
CN112035526B CN112035526B (en) | 2023-09-22 |
Family
ID=73591634
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010903867.3A Active CN112035526B (en) | 2020-09-01 | 2020-09-01 | Data caching method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112035526B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114185905A (en) * | 2021-12-06 | 2022-03-15 | 蓝信移动(北京)科技有限公司 | Cache data updating method, apparatus, device, storage medium, and program |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110489063A (en) * | 2019-08-27 | 2019-11-22 | 北京奇艺世纪科技有限公司 | Cache setting method, device, electronic equipment and the storage medium of expired time |
CN110837513A (en) * | 2019-11-07 | 2020-02-25 | 腾讯科技(深圳)有限公司 | Cache updating method, device, server and storage medium |
US10657064B1 (en) * | 2019-01-31 | 2020-05-19 | Salesforce.com. inc. | Extending usages of cached data objects beyond cache expiration periods |
-
2020
- 2020-09-01 CN CN202010903867.3A patent/CN112035526B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10657064B1 (en) * | 2019-01-31 | 2020-05-19 | Salesforce.com. inc. | Extending usages of cached data objects beyond cache expiration periods |
CN110489063A (en) * | 2019-08-27 | 2019-11-22 | 北京奇艺世纪科技有限公司 | Cache setting method, device, electronic equipment and the storage medium of expired time |
CN110837513A (en) * | 2019-11-07 | 2020-02-25 | 腾讯科技(深圳)有限公司 | Cache updating method, device, server and storage medium |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114185905A (en) * | 2021-12-06 | 2022-03-15 | 蓝信移动(北京)科技有限公司 | Cache data updating method, apparatus, device, storage medium, and program |
Also Published As
Publication number | Publication date |
---|---|
CN112035526B (en) | 2023-09-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109240946B (en) | Multi-level caching method of data and terminal equipment | |
CN102902730B (en) | Based on data reading method and the device of data buffer storage | |
US8949544B2 (en) | Bypassing a cache when handling memory requests | |
US7343396B2 (en) | Precomputation of web documents | |
US8601216B2 (en) | Method and system for removing cache blocks | |
US8447948B1 (en) | Dynamic selective cache compression | |
CN109977129A (en) | Multi-stage data caching method and equipment | |
CN104156323B (en) | A kind of adaptive read method of the data block length of cache memory and device | |
CN110795457B (en) | Data caching processing method, device, computer equipment and storage medium | |
WO2017139037A1 (en) | Profiling cache replacement | |
CN108897495B (en) | Cache updating method, device, cache equipment and storage medium | |
CN111880731B (en) | Data processing method and device and related components | |
US20050172076A1 (en) | System for managing distributed cache resources on a computing grid | |
CN112035526B (en) | Data caching method, device, equipment and readable storage medium | |
CN112631504A (en) | Method and device for realizing local cache by using off-heap memory | |
CN103209212B (en) | Based on the data cache method in the Web network management client of RIA and system | |
CN108287878A (en) | A kind of dynamic buffering data failure dispatching method, device and caching system | |
CN116992180A (en) | Method, device, terminal equipment and storage medium for caching data | |
US11269784B1 (en) | System and methods for efficient caching in a distributed environment | |
CN111061654A (en) | Cache refreshing processing method and device and electronic equipment | |
CN112214178A (en) | Storage system, data reading method and data writing method | |
CN112199400B (en) | Method and device for data processing | |
JP3279253B2 (en) | Cache page management method and medium storing cache page management program | |
CN115129752A (en) | Data caching method, data processing method, system, equipment and storage medium | |
CN111506261B (en) | Caching method, device, equipment and storage medium based on double cache areas |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |