CN109828749A - Take into account the data cache method and system that quick response and data update - Google Patents
Take into account the data cache method and system that quick response and data update Download PDFInfo
- Publication number
- CN109828749A CN109828749A CN201811636286.7A CN201811636286A CN109828749A CN 109828749 A CN109828749 A CN 109828749A CN 201811636286 A CN201811636286 A CN 201811636286A CN 109828749 A CN109828749 A CN 109828749A
- Authority
- CN
- China
- Prior art keywords
- data
- validity period
- time
- live
- request
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The data cache method and system that quick response and data update are taken into account the invention discloses a kind of, S1 determines data cached time-to-live, minimum validity period and maximum validity period;The time-to-live and the minimum validity period and the maximum validity period that S2 comparison step S1 is determined;Cache policy is determined based on comparison result described in step S2 with S3.The invention has the advantages that: quick response can not only be reached, and take into account more new data within the scheduled time.
Description
Technical field
The present invention relates to the communications fields, it particularly relates to a kind of data buffer storage taking into account quick response and data and updating
Method and system.
Background technique
During software system development, some data query times are long, and request frequency is high, if looked into real time every time
Data are ask, it is very slow to will lead to request of data response, especially in the case where data are to need largely to be calculated, can consume a large amount of
Server resource.
In order to which quick response request of data often delays data in the case where not requiring data real-time update
It deposits (such as using redis, the components such as memcache carry out data buffer storage), after data buffer storage, in request of data, from caching
Middle acquisition data, can quick returned data, solve the problems, such as quick response, but attracted data replacement problem.
Currently, general use just inquires data after data cached expired to data cached setting expired time again,
It after inquiring data, is put into caching, while returned data, since inquiry data time is long, just will appear data at this moment and ask
Ask and respond very slow situation: it is 10s that such as one, which is taken into account quick response and the data buffer storage time of data update, that means that
Every 10s will appear once to request of data low-response.
For the problems in the relevant technologies, currently no effective solution has been proposed.
Summary of the invention
For above-mentioned technical problem in the related technology, the present invention proposes a kind of number taking into account quick response and data and updating
According to caching method and system, data can be thought to solve data replacement problem while caching, blocking data is not requested, to reach
It takes into account quick response and data updates.
To realize the above-mentioned technical purpose, the technical scheme of the present invention is realized as follows:
A kind of data cache method taking into account quick response and data and updating, comprising the following steps:
S1 determines data cached time-to-live, minimum validity period and maximum validity period;
The time-to-live and the minimum validity period and the maximum validity period that S2 comparison step S1 is determined;With
S3 determines cache policy based on comparison result described in step S2.
Further, in step S3: when the time-to-live is in minimum validity period, direct return cache data.
Further, in step S3: when the time-to-live is between minimum validity period and maximum validity period, triggering
Data update request and arrive request queue, then return cache data, in the thread pool processing request queue that processing data update
Request updates data cached.
Another aspect of the present invention provides a kind of data buffering system taking into account quick response and data and updating, comprising:
First determining module, for determining data cached time-to-live, minimum validity period and maximum validity period;
Comparison module, for comparing the determining time-to-live and the minimum validity period and the maximum validity period;With
Second determining module determines cache policy for result based on the comparison.
Further, in second determining module: when the time-to-live is in minimum validity period, directly return is slow
Deposit data.
Further, in second determining module: when the time-to-live is in minimum validity period and maximum validity period
Between when, trigger data updates request and arrives request queue, then return cache data, and the thread pool processing that processing data update is asked
The request in queue is asked, is updated data cached.
Beneficial effects of the present invention: can not only reach quick response, and take into account more new data within the scheduled time.
Detailed description of the invention
It in order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, below will be to institute in embodiment
Attached drawing to be used is needed to be briefly described, it should be apparent that, the accompanying drawings in the following description is only some implementations of the invention
Example, for those of ordinary skill in the art, without creative efforts, can also obtain according to these attached drawings
Obtain other attached drawings.
Fig. 1 is the process for taking into account the data cache method that quick response and data update described according to embodiments of the present invention
Figure;
Fig. 2 is the schematic diagram for taking into account the data cache method that quick response and data update described according to embodiments of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, those of ordinary skill in the art's every other embodiment obtained belong to what the present invention protected
Range.
As shown in Figure 1, a kind of data buffer storage taking into account quick response and data and updating described according to embodiments of the present invention
Method, comprising the following steps:
S1 determines data cached time-to-live, minimum validity period and maximum validity period;
The time-to-live and the minimum validity period and the maximum validity period that S2 comparison step S1 is determined;With
S3 determines cache policy based on comparison result described in step S2.
In one particular embodiment of the present invention, in step S3: when the time-to-live is in minimum validity period, directly
Connect return cache data.
In one particular embodiment of the present invention, in step S3: when the time-to-live in minimum validity period and most
When between big validity period, trigger data updates request and arrives request queue, then return cache data, the thread that processing data update
Pond handles the request in request queue, updates data cached.
Data buffer storage refers to the position that stores data in and can quickly read, and there may be in memory, also can store
In some common components, such as redis, memcache etc..
Define cacheData, include attribute data, uniqueId, st, t1, t2, detailed description below:
CacheData: referring to data cached packet, is exactly the data packet that be finally put into caching;
Data: referring to the data to be requested, and the data finally to be returned;
UniqueId: referring to the unique identification of data data, such as user information can be using User ID as unique identification, display
Product quantity can be indicated with customized key_product_count;
St: refer to data cached time packet creation or updated, unit millisecond;When also illustrating that the starting of data cached packet survival
Between, when creating or updating data cached packet, st can be set as current time;
T1: refer to the minimum validity period of caching, unit millisecond;
T2: refer to the maximum validity period of caching, unit millisecond;
Current time indicates that unit is all millisecond with now;
Now-st can indicate the time-to-live of data cached packet cacheData.
CacheData is put into caching, be it is one-to-one with uniqueId, can be obtained from caching according to uniqueId
Get cacheData;
Data request interface IDataProvider is defined, there is method getData, for the data that please be look for novelty and return,
The calling of getData method is a time-consuming process;
Define request of data dataRequest, the unique identification uniqueId comprising data, the realization object of data request interface
dataProvider;
It realizes data request queue requestQueue, is the queue of a first in first out, is used to store request of data.
The array uniqueIdArray for realizing thread-safe is used to store in the queue or the request of present
uniqueId。
Realize that the thread pool of processing request of data, thread pool are more asked from data and take out request in queue, processing request.
Specifically, building dataRequest, starts request data;
S1 obtains data packet cacheData when receiving dataRequest, according to the uniqueId in request from caching;
If S2 cacheData is not present, the getData of the dataProvider object in dataRequest is called directly
Method obtains new data data, then constructs new data cached packet cacheData, and cacheData is put into caching
In, then returned data data;If cacheData exists, start the validity period for judging cacheData;If meeting now
- st < t1, that is, the time-to-live of cacheData are less than t1, then directly return to the data value of cacheData;If full
Sufficient now-st > t2, that is, the time-to-live of cacheData are greater than t2, then call directly in dataRequest
The getData method of dataProvider object obtains new data data, then constructs new data cached packet
CacheData, and cacheData is put into caching, then returned data data;If meeting now-st >=t1 simultaneously
And now-st≤t2, that is, cacheData time-to-live between t1 and t2, then request of data is entered into S3;
S3 when there are same data update request when, then direct return cache data;When there is no the updates of same data to ask
When asking, the request of data is respectively put into the data request queue and/or the array of thread-safe.Judge
Whether the uniqueId of dataRequest is had existed in uniqueIdArray, if it is present directly returning to cacheData
Data value;If it does not, just dataRequest is put into requestQueue, while by dataRequest's
UniqueId is put into uniqueIdArray, then returns to the data value of cacheData;Handle the thread pool of request of data
Then the asynchronous taking-up dataRequest from data request queue requestQueue calls dataRequest's
The getData method of dataProvider object obtains new data, then constructs new data cached packet cacheData, and will
CacheData is put into caching, uses for request next time, uniqueId is then removed from uniqueIdArray.
In conclusion be to inquire data again when first time request of data, low-response, next within the t1 time, all
It is from caching from data are obtained, response is fast;First request between t1-t2, meeting trigger data request to request queue
In, all requests of this period also can all obtain data from caching, and response is fast;Thread pool asynchronous process request of data, place
Reason request, updates data cached, and st becomes current time, if request number of times be not it is especially few, can allow data cached deposit
For live time now-st always within t2, realization obtains always data from caching, and response is fast.It also can guarantee data simultaneously
It updates, even if in extreme bad in the case where, for example request number of times is seldom, also the request only in the interval t2 time can just respond
Slowly, it influences less.
It is requested using maximized using data cached response data, caching number is updated by the asynchronous mode of thread pool
According to being updated to reach and take into account quick response and data.
As shown in Fig. 2, another aspect of the present invention, provides a kind of data buffer storage system for taking into account quick response and data and updating
System, comprising:
First determining module, for determining data cached time-to-live, minimum validity period and maximum validity period;
Comparison module, for comparing the determining time-to-live and the minimum validity period and the maximum validity period;With
Second determining module determines cache policy for result based on the comparison.
In one particular embodiment of the present invention, in second determining module: when the time-to-live is in minimum
When validity period, direct return cache data.
In one particular embodiment of the present invention, in second determining module: when the time-to-live is in minimum
When between validity period and maximum validity period, trigger data updates request and arrives request queue, then return cache data, handles data
Request in the thread pool processing request queue of update, updates data cached.
Specifically, obtaining data packet from caching according to the uniqueId in request when receiving dataRequest
cacheData;
If cacheData is not present, the side getData of the dataProvider object in dataRequest is called directly
Method obtains new data data, then constructs new data cached packet cacheData, and cacheData is put into caching,
Then returned data data;If cacheData exists, start the validity period for judging cacheData;If meeting now-
St < t1, that is, the time-to-live of cacheData are less than t1, then directly return to the data value of cacheData;If met
Now-st > t2, that is, the time-to-live of cacheData are greater than t2, then call directly in dataRequest
The getData method of dataProvider object obtains new data data, then constructs new data cached packet
CacheData, and cacheData is put into caching, then returned data data;If meeting now-st >=t1 simultaneously
And now-st≤t2, that is, cacheData time-to-live between t1 and t2, then request of data is entered into S3;
When there are same data update request when, then direct return cache data;When there is no same data to update request
When, the request of data is respectively put into the data request queue and/or the array of thread-safe.Judge
Whether the uniqueId of dataRequest is had existed in uniqueIdArray, if it is present directly returning to cacheData
Data value;If it does not, just dataRequest is put into requestQueue, while by dataRequest's
UniqueId is put into uniqueIdArray, then returns to the data value of cacheData;Handle the thread pool of request of data
Then the asynchronous taking-up dataRequest from data request queue requestQueue calls dataRequest's
The getData method of dataProvider object obtains new data, then constructs new data cached packet cacheData, and will
CacheData is put into caching, uses for request next time, uniqueId is then removed from uniqueIdArray.
In conclusion guarantee once to request within maximum time validity period by means of above-mentioned technical proposal of the invention,
Can make the request of data each time in addition to first time is all that data are obtained from caching, reaches quick response, Er Qiejian
The purpose of more new data within the scheduled time is cared for.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Within mind and principle, any modification, equivalent replacement, improvement and so on be should all be included in the protection scope of the present invention.
Claims (6)
1. a kind of data cache method taking into account quick response and data and updating, which comprises the following steps:
S1 determines data cached time-to-live, minimum validity period and maximum validity period;
The time-to-live and the minimum validity period and the maximum validity period that S2 comparison step S1 is determined;With
S3 determines cache policy based on comparison result described in step S2.
2. data cache method according to claim 1, which is characterized in that in step S3: existing when the time-to-live
When minimum validity period, direct return cache data.
3. data cache method according to claim 1 or 2, which is characterized in that in step S3: when the time-to-live
When between minimum validity period and maximum validity period, trigger data updates request and arrives request queue, then return cache data, place
The request in the thread pool processing request queue that data update is managed, is updated data cached.
4. a kind of data buffering system taking into account quick response and data and updating, which comprises the following steps:
First determining module, for determining data cached time-to-live, minimum validity period and maximum validity period;
Comparison module, for comparing the determining time-to-live and the minimum validity period and the maximum validity period;With
Second determining module determines cache policy for result based on the comparison.
5. data buffering system according to claim 4, which is characterized in that in second determining module: when described
Time-to-live in minimum validity period, direct return cache data.
6. data buffering system according to claim 4 or 5, which is characterized in that in second determining module: when described
Time-to-live between minimum validity period and maximum validity period when, trigger data updates request and arrives request queue, then returns
Data cached, in the thread pool processing request queue that processing data update request, updates data cached.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811636286.7A CN109828749A (en) | 2018-12-29 | 2018-12-29 | Take into account the data cache method and system that quick response and data update |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811636286.7A CN109828749A (en) | 2018-12-29 | 2018-12-29 | Take into account the data cache method and system that quick response and data update |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109828749A true CN109828749A (en) | 2019-05-31 |
Family
ID=66860715
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811636286.7A Pending CN109828749A (en) | 2018-12-29 | 2018-12-29 | Take into account the data cache method and system that quick response and data update |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109828749A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113515530A (en) * | 2021-03-30 | 2021-10-19 | 贵州白山云科技股份有限公司 | Cache object updating method, device, equipment and storage medium |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622426A (en) * | 2012-02-27 | 2012-08-01 | 杭州闪亮科技有限公司 | Database writing system and database writing method |
CN105138587A (en) * | 2015-07-31 | 2015-12-09 | 小米科技有限责任公司 | Data access method, apparatus and system |
KR20170035155A (en) * | 2015-09-22 | 2017-03-30 | 삼성전자주식회사 | Memory Controller, Non-volatile Memory System and Operating Method thereof |
CN106599721A (en) * | 2016-12-13 | 2017-04-26 | 微梦创科网络科技(中国)有限公司 | Cache-based data access method and apparatus |
CN107291756A (en) * | 2016-04-01 | 2017-10-24 | 阿里巴巴集团控股有限公司 | The method and device of data buffer storage |
-
2018
- 2018-12-29 CN CN201811636286.7A patent/CN109828749A/en active Pending
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622426A (en) * | 2012-02-27 | 2012-08-01 | 杭州闪亮科技有限公司 | Database writing system and database writing method |
CN105138587A (en) * | 2015-07-31 | 2015-12-09 | 小米科技有限责任公司 | Data access method, apparatus and system |
KR20170035155A (en) * | 2015-09-22 | 2017-03-30 | 삼성전자주식회사 | Memory Controller, Non-volatile Memory System and Operating Method thereof |
CN107291756A (en) * | 2016-04-01 | 2017-10-24 | 阿里巴巴集团控股有限公司 | The method and device of data buffer storage |
CN106599721A (en) * | 2016-12-13 | 2017-04-26 | 微梦创科网络科技(中国)有限公司 | Cache-based data access method and apparatus |
Non-Patent Citations (1)
Title |
---|
颜建华: "《Android开发关键技术之旅 JAVA程序员快速学习通道》", 30 July 2012, 中国铁道出版社 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113515530A (en) * | 2021-03-30 | 2021-10-19 | 贵州白山云科技股份有限公司 | Cache object updating method, device, equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8930489B2 (en) | Distributed rate limiting of handling requests | |
KR100791628B1 (en) | Method for active controlling cache in mobile network system, Recording medium and System thereof | |
US7366738B2 (en) | Method and system for object cache synchronization | |
US9519547B2 (en) | Systems and methods for supporting transactional message handling | |
CN107241380B (en) | Method and apparatus for time-based adjusted load balancing | |
CA2495896A1 (en) | Method and apparatus for preloading caches | |
CN106331148A (en) | Cache management method and cache management device for data reading by clients | |
US10080233B2 (en) | Method for providing M2M data | |
US8577008B2 (en) | Asynchronous calls using intermittent callback for delay sensitive applications | |
CN106453667A (en) | Method and device for updating cached data | |
US20100008377A1 (en) | Queue management based on message age | |
CN106790552B (en) | A kind of content providing system based on content distributing network | |
CN109976924A (en) | Interface call method and device | |
CN112615793A (en) | Data current limiting method and device | |
CN109828749A (en) | Take into account the data cache method and system that quick response and data update | |
US20180129528A1 (en) | Predicting transaction outcome based on artifacts in a transaction processing environment | |
CN101699436A (en) | Method, device and system for resource management | |
CN109063140A (en) | A kind of data query method, transfer server and computer readable storage medium | |
CN116756190A (en) | Data cache management method, device, terminal equipment and storage medium | |
CN109976885B (en) | Event processing method and device based on multitask operating system and storage medium | |
CN111367670A (en) | Remote sensing satellite ground station network resource application method and system | |
CN115858582A (en) | Cache real-time updating method, device, equipment and storage medium | |
WO2018090315A1 (en) | Data request processing method and cache system | |
CN110727827B (en) | Video list data aggregation method and device, computer equipment and storage medium | |
US20180063005A1 (en) | Non-blocking request processing method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20190531 |
|
RJ01 | Rejection of invention patent application after publication |