CN106254529B - A kind of client-side data cache method and apparatus - Google Patents
A kind of client-side data cache method and apparatus Download PDFInfo
- Publication number
- CN106254529B CN106254529B CN201610834271.6A CN201610834271A CN106254529B CN 106254529 B CN106254529 B CN 106254529B CN 201610834271 A CN201610834271 A CN 201610834271A CN 106254529 B CN106254529 B CN 106254529B
- Authority
- CN
- China
- Prior art keywords
- data
- client
- request
- caching
- server end
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 36
- 230000000977 initiatory effect Effects 0.000 claims abstract description 4
- 238000013500 data storage Methods 0.000 claims 1
- 230000003993 interaction Effects 0.000 abstract description 7
- 238000005138 cryopreservation Methods 0.000 description 4
- 238000000151 deposition Methods 0.000 description 4
- 238000010586 diagram Methods 0.000 description 4
- 238000005538 encapsulation Methods 0.000 description 3
- 238000012217 deletion Methods 0.000 description 2
- 230000037430 deletion Effects 0.000 description 2
- 238000013461 design Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 241001269238 Data Species 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000002360 preparation method Methods 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
Abstract
This application discloses a kind of client-side data cache method and apparatus, this method includes request of data being initiated to server end, and obtain the first data from the server end;According to the type of first data, first data are cached in a corresponding way in the client;When client receives the instruction for obtaining the first data, first data are taken out from the caching of client;The device includes obtaining widget, for initiating request of data to server end, and obtains the first data from the server end;It caches component and caches the first data in a corresponding way in the client for the type according to first data;Component is taken out, for taking out first data from the caching of client when client receives the instruction for obtaining the first data.The above method and device can be reduced the frequency of interaction of client and server, mitigate the pressure of server, reduce the average response time of data access, improve the data response speed of client.
Description
Technical field
The invention belongs to Web client technical fields, more particularly to a kind of client-side data cache method and apparatus.
Background technique
Client-side data cache technology, as the term suggests be exactly the data of client-cache server response, but it is current this
The internet world of a rapid development, it is desirable that the real-time and accuracy of data, this is contradicted with data cached logic again.With
The development of HTML5, using more and more, the data in single-page request in the different pages may be single-page web of today
It is identical, and the multiple request data of different page datas will result in the waste of transmission, increase client and server
Frequency of interaction increases the pressure of server.
Summary of the invention
To solve the above problems, client can be reduced the present invention provides a kind of client-side data cache method and apparatus
The frequency of interaction at end and server end, mitigates the pressure of server, reduces the average response time of data access, improves client
Data response speed.
A kind of client-side data cache method provided by the invention, comprising:
Request of data is initiated to server end, and obtains the first data from the server end;
According to the type of first data, first data are cached in a corresponding way in the client;
When client receives the instruction for obtaining first data, described is taken out from the caching of the client
One data.
Preferably, in above-mentioned client-side data cache method, it is described in the client in a corresponding way caching described in
After first data, further includes:
When first data are expired, newest first data are obtained from the server end and are updated.
Preferably, in above-mentioned client-side data cache method, the type according to first data, in client
In cache first data in a corresponding way and include:
When first data are permanent storage data, cached in the form of key-value pair in the way of localstorage
First data.
Preferably, in above-mentioned client-side data cache method, the type according to first data, in client
In cache first data in a corresponding way further include:
When first data are passive live data, first data are stored in a manner of Sessionstorage.
Preferably, in above-mentioned client-side data cache method, it is described in the client in a corresponding way caching described in
First data further include:
The request time stamp of first data is stored as the foundation updated.
A kind of client-side data cache device provided by the invention, comprising:
Obtaining widget for initiating request of data to server end, and obtains the first data from the server end;
Component is cached, for the type according to first data, caches described the in a corresponding way in the client
One data;
Component is taken out, for when client receives the instruction for obtaining first data, from delaying for the client
Deposit middle taking-up first data.
Preferably, in above-mentioned client-side data cache device, further includes:
Update component, for when first data are expired, from the server end obtain newest first data into
Row updates.
Preferably, in above-mentioned client-side data cache device, the caching component includes:
First cache unit is used for when first data are permanent storage data, in the way of localstorage
First data are cached in the form of key-value pair.
Preferably, in above-mentioned client-side data cache device, the caching component further include:
Second cache unit, for being deposited in a manner of Sessionstorage when first data are passive live data
Store up first data.
Preferably, in above-mentioned client-side data cache device, component is cached further include:
Storage unit, the request time for storing first data are stabbed as the foundation updated.
As can be seen from the above description, above-mentioned client-side data cache method and apparatus provided by the invention, due to this method
It include: to initiate request of data to server end, and obtain the first data from the server end;According to the class of first data
Type caches first data in a corresponding way in the client;The fingers of first data is obtained when client receives
When enabling, first data are taken out from the caching of the client, therefore the interaction of client and server can be reduced
Frequency mitigates the pressure of server, reduces the average response time of data access, improves the data response speed of client.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below
There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
The embodiment of invention for those of ordinary skill in the art without creative efforts, can also basis
The attached drawing of offer obtains other attached drawings.
Fig. 1 is the schematic diagram of the first client-side data cache method provided by the embodiments of the present application;
Fig. 2 is the schematic diagram of the first client-side data cache device provided by the embodiments of the present application.
Specific embodiment
In general, the frequency that data update in system may be roughly divided into three classes: (1) the fixed initialization number of system
According to these data may not will be updated always in the life cycle of whole system, these are exactly doomed dead evidence;(2) number of system
According to may not timing update, for requirement of real-time also so high, these data are exactly passiveness live data;(3) system
Data update it is especially fast, it is per second or every millisecond in can all have data update, and the requirement of real-time of these data is also relatively high,
These data are exactly positive live data.According to the different classifications of data, different request methods can be executed.
Therefore, core of the invention thought is to provide a kind of client-side data cache method and apparatus, can reduce visitor
The frequency of interaction at family end and server end mitigates the pressure of server, reduces the average response time of data access, improves client
The data response speed at end.
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, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
As shown in FIG. 1, FIG. 1 is the embodiment of the present application for the first client-side data cache method provided by the embodiments of the present application
The schematic diagram of the first the client-side data cache method provided.This method comprises the following steps:
S1: request of data is initiated to server end, and obtains the first data from the server end;
It should be noted that client when first time request data, is locally not data cached, therefore visitor
Family end will go server request data to use.
S2: according to the type of first data, first data are cached in a corresponding way in the client;
It should be noted that need data to be stored in local after client request to data, local cache data
Technology has localstorage, sessionstorage, indexedDB etc., can be needed to select suitable caching according to business
Technology.
S3: when client receives the instruction for obtaining first data, institute is taken out from the caching of the client
State the first data.
It should be noted that after data buffer storage success, when user needs the data of identical url and identical parameters again
When, this system will take out corresponding data for customer end from caching and use, and be not necessarily to request server, and server is just not necessarily to
The operation of response is executed, server stress is mitigated.
As can be seen from the above description, above-mentioned client-side data cache method provided by the embodiments of the present application, due to include: to
Server end initiates request of data, and obtains the first data from the server end;According to the type of first data, in visitor
First data are cached in the end of family in a corresponding way;When client receives the instruction for obtaining first data, from
First data are taken out in the caching of the client, therefore can reduce the frequency of interaction of client and server, are subtracted
The pressure of light server, reduces the average response time of data access, improves the data response speed of client.
Second of client-side data cache method provided by the embodiments of the present application is slow in the first above-mentioned client data
Further include following technical characteristic on the basis of depositing method:
It is described cache first data in a corresponding way in the client after, further includes:
When first data are expired, newest first data are obtained from the server end and are updated.
Specifically, client requires to estimate the real-time progress one of request data when using request data
Calculate, estimate the shortest renewal time interval of the data in the request be how many (being calculated with millisecond).In data cached value
The timestamp of storage is compared plus this time interval and current timestamp, illustrates this if it is greater than current timestamp
The data of caching are expired, need to re-request data and delete data cached storage new data, if be not more than currently
Timestamp illustrates that the data in this caching are available, without requesting new data.
The third client-side data cache method provided by the embodiments of the present application is slow in above-mentioned second of client data
Further include following technical characteristic on the basis of depositing method:
The type according to first data, caches first data packet in a corresponding way in the client
It includes:
When first data are permanent storage data, cached in the form of key-value pair in the way of localstorage
First data.
Specifically, Localstorage is stored in a manner of key-value pair (key-value), permanently stores, never fail, remove
Non-manual deletion, the data of each domain name storage 5M size.
4th kind of client-side data cache method provided by the embodiments of the present application is slow in the third above-mentioned client data
Further include following technical characteristic on the basis of depositing method:
The type according to first data caches first data in a corresponding way in the client and also wraps
It includes:
When first data are passive live data, first data are stored in a manner of Sessionstorage.
Specifically, Sessionstorage and localStorage be in application method it is identical, difference is
SessionStorage is emptied after closing the page, and localStorage can then be saved always.IndexedDB index number
According to library, have the abundant data-intensive offline HTML5Web application program that data are locally stored very useful creation, also
Help local cache data, traditional online web application (such as mobile Web application program) is made quickly can to run and ring
It answers.It is stored when storing data with key-value pair, to take.Wherein, with url, the unique mark of required parameter composition
The character string of knowledge is as key, it is ensured that the different data that url and parameter difference are requested can be stored and not conflict.
5th kind of client-side data cache method provided by the embodiments of the present application is slow in above-mentioned 4th kind of client data
Further include following technical characteristic on the basis of depositing method:
It is described to cache first data in a corresponding way in the client further include:
The request time stamp of first data is stored as the foundation updated.
It should be noted that the data that the timestamp and request when storing request in value arrive, timestamp is for recording number
According to timeliness, specifically, the value of three kinds of time intervals can be defined, respectively -1,0 and " number greater than 0 " these three feelings
Condition.
If it is -1, indicate this request in data never update, as long as have it is data cached just using cache in data,
If without requesting new data if data cached and saving, this mode is used for handling dead data;
If it is 0, indicates that this request is possible immediately and update, so this data requests all direct requests without caching every time
Backstage obtains new data, and this mode is for handling positive live data;
If it is the number for being greater than 0, indicate that data may not update at a certain time interval, progress is data cached more
New decision logic executes the update and use of data, and this mode is for handling passive live data.
The first client-side data cache device provided by the embodiments of the present application is as shown in Fig. 2, Fig. 2 is the embodiment of the present application
The schematic diagram of the first the client-side data cache device provided.The device includes:
Obtaining widget 201 for initiating request of data to server end, and obtains the first data from the server end,
Client is locally not data cached when first time request data, therefore client will go server number of request
According to using;
Component 202 is cached, for the type according to first data, in the client in a corresponding way described in caching
First data after client request to data, need data to be stored in local, the technology of local cache data has
Localstorage, sessionstorage, indexedDB etc. can need to select suitable caching technology according to business;
Component 203 is taken out, for when client receives the instruction for obtaining first data, from the client
First data are taken out in caching, after data buffer storage success, when user needs the data of identical url and identical parameters again
When, this system will take out corresponding data for customer end from caching and use, and be not necessarily to request server, server is with regard to nothing
The operation of response need to be executed, server stress is mitigated.
As can be seen from the above description, above-mentioned client-side data cache device provided by the embodiments of the present application, can reduce visitor
The frequency of interaction at family end and server end mitigates the pressure of server, reduces the average response time of data access, improves client
The data response speed at end.
Second of client-side data cache device provided by the embodiments of the present application is slow in the first above-mentioned client data
Further include following technical characteristic on the basis of cryopreservation device:
Update component, for when first data are expired, from the server end obtain newest first data into
Row updates.
Specifically, client requires to estimate the real-time progress one of request data when using request data
Calculate, estimate the shortest renewal time interval of the data in the request be how many (being calculated with millisecond).In data cached value
The timestamp of storage is compared plus this time interval and current timestamp, illustrates this if it is greater than current timestamp
The data of caching are expired, need to re-request data and delete data cached storage new data, if be not more than currently
Timestamp illustrates that the data in this caching are available, without requesting new data.
The third client-side data cache device provided by the embodiments of the present application is slow in above-mentioned second of client data
Further include following technical characteristic on the basis of cryopreservation device:
The caching component includes:
First cache unit is used for when first data are permanent storage data, in the way of localstorage
First data are cached in the form of key-value pair.
Specifically, Localstorage is stored in a manner of key-value pair (key-value), permanently stores, never fail, remove
Non-manual deletion, each domain name store 5M size data.
4th kind of client-side data cache device provided by the embodiments of the present application is slow in the third above-mentioned client data
Further include following technical characteristic on the basis of cryopreservation device:
The caching component further include:
Second cache unit, for being deposited in a manner of Sessionstorage when first data are passive live data
Store up first data.
Specifically, Sessionstorage and localStorage be in application method it is identical, difference is
SessionStorage is emptied after closing the page, and localStorage can then be saved always.IndexedDB index number
According to library, have the abundant data-intensive offline HTML5Web application program that data are locally stored very useful creation, also
Help local cache data, traditional online web application (such as mobile Web application program) is made quickly can to run and ring
It answers.It is stored when storing data with key-value pair, to take.Wherein, with url, the unique mark of required parameter composition
The character string of knowledge is as key, it is ensured that the different data that url and parameter difference are requested can be stored and not conflict.
5th kind of client-side data cache device provided by the embodiments of the present application is slow in above-mentioned 4th kind of client data
Further include following technical characteristic on the basis of cryopreservation device:
Cache component further include:
Storage unit, the request time for storing first data are stabbed as the foundation updated.
It should be noted that the data that the timestamp and request when storing request in value arrive, timestamp is for recording number
According to timeliness.The value of three kinds of time intervals can be defined, respectively -1,0 and " number greater than 0 " these three situations.
If it is -1, indicate this request in data never update, as long as have it is data cached just using cache in data,
If without requesting new data if data cached and saving, this mode is used for handling dead data;
If it is 0, indicates that this request is possible immediately and update, so this data requests all direct requests without caching every time
Backstage obtains new data, and this mode is for handling positive live data;
If it is the number for being greater than 0, indicate that data may not update at a certain time interval, progress is data cached more
New decision logic executes the update and use of data, and this mode is for handling passive live data.
In conclusion the data buffer storage that last time requests can be got up, be supplied when the data in the page do not change
Next same request uses, and in this way when a large number of users accesses same system, background service system can be much less not
Necessary request.Using the above method and device, following specific scheme can be realized: ajax request and the design are done centainly
Encapsulation, we only need to provide unified call entry after encapsulation, and when calling the method, inside of this encapsulation can be from
The parameter value of dynamic judgement local caching situation and transmitting, executes correctly judgement, and reasonably using local cache data and
New data is requested, the reasonable access times to doomed dead evidence, passive live data, positive live data of the design are had reached.
The foregoing description of the disclosed embodiments enables those skilled in the art to implement or use the present invention.
Various modifications to these embodiments will be readily apparent to those skilled in the art, as defined herein
General Principle can be realized in other embodiments without departing from the spirit or scope of the present invention.Therefore, of the invention
It is not intended to be limited to the embodiments shown herein, and is to fit to and the principles and novel features disclosed herein phase one
The widest scope of cause.
Claims (4)
1. a kind of client-side data cache method characterized by comprising
Request of data is initiated to server end, and obtains the first data from the server end;
According to the type of first data, first data are cached in a corresponding way in the client;
When client receives the instruction for obtaining first data, first number is taken out from the caching of the client
According to;
It is described cache first data in a corresponding way in the client after, further includes:
When first data are expired, newest first data are obtained from the server end and are updated, wherein including elder generation
A shortest renewal time interval is estimated for the real-time of request data, then by the first data value of caching
The timestamp of middle storage is compared plus after the shortest renewal time interval with current timestamp, if it is greater than working as
Preceding timestamp then re-requests data and deletes the first data storage new data, if no more than current timestamp
Without requesting new data;
The type according to first data, caching first data in a corresponding way in the client includes:
When first data are permanent storage data, in the way of localstorage in the form of key-value pair described in caching
First data;
When first data are passive live data, first data are stored in a manner of Sessionstorage.
2. client-side data cache method according to claim 1, which is characterized in that described in the client with corresponding
Mode caches first data further include:
The request time stamp of first data is stored as the foundation updated.
3. a kind of client-side data cache device characterized by comprising
Obtaining widget for initiating request of data to server end, and obtains the first data from the server end;
Component is cached, for the type according to first data, caches first number in a corresponding way in the client
According to;
Component is taken out, for when client receives the instruction for obtaining first data, from the caching of the client
Take out first data;
Component is updated, for newest first data being obtained from the server end and being carried out more when first data are expired
Newly, wherein the real-time including being first directed to request data estimates a shortest renewal time interval, then will be described in caching
The timestamp stored in first data value is compared plus after the shortest renewal time interval with current timestamp
Compared with then re-requesting data if it is greater than current timestamp and delete first data and store new data, if be not more than
Current timestamp is then not necessarily to request new data;
The caching component includes:
First cache unit is used for when first data are permanent storage data, with key in the way of localstorage
The form of value pair caches first data;
Second cache unit, for storing institute in a manner of Sessionstorage when first data are passive live data
State the first data.
4. client-side data cache device according to claim 3, which is characterized in that caching component further include:
Storage unit, the request time for storing first data are stabbed as the foundation updated.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610834271.6A CN106254529B (en) | 2016-09-20 | 2016-09-20 | A kind of client-side data cache method and apparatus |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610834271.6A CN106254529B (en) | 2016-09-20 | 2016-09-20 | A kind of client-side data cache method and apparatus |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106254529A CN106254529A (en) | 2016-12-21 |
CN106254529B true CN106254529B (en) | 2019-09-24 |
Family
ID=57599975
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610834271.6A Active CN106254529B (en) | 2016-09-20 | 2016-09-20 | A kind of client-side data cache method and apparatus |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106254529B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106843769B (en) * | 2017-01-23 | 2019-08-02 | 北京齐尔布莱特科技有限公司 | A kind of interface data caching method, device and calculate equipment |
CN107239530A (en) * | 2017-05-31 | 2017-10-10 | 努比亚技术有限公司 | Label search method, device, system and computer-readable recording medium |
CN108280764A (en) * | 2018-02-06 | 2018-07-13 | 杭州政信金服互联网科技有限公司 | A kind of data based on the transaction of government debt check system and method |
CN109002495A (en) * | 2018-06-28 | 2018-12-14 | 郑州云海信息技术有限公司 | Date storage method and device |
CN110895474A (en) * | 2018-08-24 | 2020-03-20 | 深圳市鸿合创新信息技术有限责任公司 | Terminal micro-service device and method and electronic equipment |
CN109815433A (en) * | 2019-01-11 | 2019-05-28 | 平安科技(深圳)有限公司 | Method and device, storage medium and electronic equipment is locally stored in browser |
CN109783499B (en) * | 2019-01-18 | 2023-09-22 | 成都宝瓜科技有限公司 | Data caching method, device and server |
CN112433867A (en) * | 2020-11-25 | 2021-03-02 | 四川长虹电器股份有限公司 | Method for optimizing APP request equipment list of Android internet of things |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101815087A (en) * | 2010-02-10 | 2010-08-25 | 北京播思软件技术有限公司 | Method for caching information of mobile communication terminal |
CN104142966A (en) * | 2013-09-26 | 2014-11-12 | 腾讯科技(深圳)有限公司 | Web page displaying method and client |
CN104391862A (en) * | 2014-10-23 | 2015-03-04 | 北京锐安科技有限公司 | Method and device for updating cache data |
-
2016
- 2016-09-20 CN CN201610834271.6A patent/CN106254529B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101815087A (en) * | 2010-02-10 | 2010-08-25 | 北京播思软件技术有限公司 | Method for caching information of mobile communication terminal |
CN104142966A (en) * | 2013-09-26 | 2014-11-12 | 腾讯科技(深圳)有限公司 | Web page displaying method and client |
CN104391862A (en) * | 2014-10-23 | 2015-03-04 | 北京锐安科技有限公司 | Method and device for updating cache data |
Also Published As
Publication number | Publication date |
---|---|
CN106254529A (en) | 2016-12-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106254529B (en) | A kind of client-side data cache method and apparatus | |
CN103853727B (en) | Improve the method and system of big data quantity query performance | |
CN104111900B (en) | Data replacement method and device in one kind caching | |
CN105450780B (en) | A kind of CDN system and its return source method | |
CN105635196B (en) | A kind of method, system and application server obtaining file data | |
CN102999522B (en) | A kind of date storage method and device | |
CN104717314B (en) | A kind of IP management method and system, client, server | |
CN106603713A (en) | Session management method and system | |
CN105138679B (en) | A kind of data processing system and processing method based on distributed caching | |
CN104394182A (en) | Method for realizing content delivery network acceleration and source server | |
CN103905439A (en) | Webpage browsing accelerating method based on home gateway | |
CN105468707A (en) | Cache-based data processing method and device | |
CN108429777A (en) | Data updating method based on cache and server | |
CN109167840A (en) | A kind of task method for pushing, Site autonomy server and edge cache server | |
WO2014161261A1 (en) | Data storage method and apparatus | |
CN107332843A (en) | IOS network requests intercept forwarding cache method and system | |
CN102946320A (en) | Distributed supervision method and system for user behavior log forecasting network | |
US20150095581A1 (en) | Data caching policy in multiple tenant enterprise resource planning system | |
CN102546674A (en) | Directory tree caching system and method based on network storage device | |
CN109714443A (en) | Name server, domain name backup method and computer readable storage medium | |
CN105871607B (en) | Information processing method and service platform | |
CN110365810A (en) | Domain name caching method, device, equipment and storage medium based on web crawlers | |
CN109189748A (en) | A kind of buffer consistency processing method and nfs server | |
CN107018170A (en) | A kind of method of data synchronization and equipment | |
CN101551781A (en) | Method of magnetic disc cache replacement in P2P video on demand system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |