Summary of the invention
Technical problem to be solved by this invention provides the method for a kind of website buffer memory, and in order to solve in the prior art, the buffer memory instantaneity is poor, data cached inconsistent, the serious waste of resources of each client computer, the low problem of buffer efficiency.
The present invention also provides a kind of network-caching device, in order to guarantee said method realization and application in practice.
For solving the problems of the technologies described above, the embodiment of the invention discloses the method for a kind of website buffer memory, comprising:
The identification information of record source data and final updating temporal information are to cache information table; Wherein, for newly-generated source data, the final updating temporal information that is write down is the temporal information that described source data generates, and for the renewal that described source data is carried out, the final updating temporal information that is write down is the last temporal information of upgrading of this source data;
Receive the access request of submitting to, generate solicited message, described request information comprises the identification information of institute's access originator data;
According to whether having the data cached of described source data in the described identification information judgment local cache;
If there is no, then extract the final updating temporal information that writes down in the identification information of described source data, described source data and the described cache information table, in local cache, generate the data cached of described source data;
If exist, the final updating temporal information of respective identification information compares in then will be described data cached final updating temporal information and the described cache information table, as if unanimity, then reads described data cached; If inconsistent, then extract the final updating temporal information that writes down in the identification information of described source data, described source data and the described cache information table, in local cache, regenerate the data cached of described source data.
Preferably, described recording step comprises:
Generate source data and identification information thereof, described identification information recording to cache information table, is recorded to the rise time information of described source data in the cache information table as the final updating temporal information;
Upgrade source data, according to current update time information revise the final updating temporal information of the identification information correspondence of this source data in the described cache information table.
Preferably, described source data is stored in first server, and described cache information table is stored in the second server.
Preferably, described cache information table is a Hash table.
Preferably, described cache information table is a plurality of.
The embodiment of the invention also discloses the device of a kind of website buffer memory, comprising:
Record cell is used for writing down the identification information of source data and final updating temporal information to cache information table; Wherein, for newly-generated source data, the final updating temporal information that is write down is the temporal information that described source data generates, and for the renewal that described source data is carried out, the final updating temporal information that is write down is the last temporal information of upgrading of this source data;
Interface unit is used for the access request that subscribing client is submitted to, generates solicited message, and described request information comprises the identification information of institute's access originator data;
Judging unit is used for whether having the data cached of described source data according to described identification information judgment local cache, if there is no, then triggers the buffer memory creating unit; If exist, then trigger the contrast unit;
The buffer memory creating unit is used for extracting the identification information of described source data, described source data and the final updating temporal information that described cache information table writes down, and generates the data cached of described source data in local cache;
The contrast unit, be used for the described data cached final updating temporal information and the final updating temporal information of described cache information table respective identification information are compared, and when unanimity, trigger reading unit, when inconsistent, call the buffer memory creating unit and in local cache, regenerate the data cached of described source data;
Reading unit is used to read described data cached.
Preferably, described record cell further comprises:
Generate the record subelement, be used to generate source data and identification information thereof, described identification information recording to cache information table, is recorded to the rise time information of described source data in the cache information table as the final updating temporal information;
More the new record subelement is used to upgrade source data, according to current update time information revise the final updating temporal information of the identification information correspondence of this source data in the described cache information table.
Preferably, described device also comprises:
Memory cell is used to store described source data.
Preferably, described memory cell is positioned at first server end, described record cell second server end.
Preferably, described cache information table is a Hash table.
Compared with prior art, the embodiment of the invention has the following advantages:
At first, because the present invention is by comparing the final updating temporal information in data cached in record final updating temporal information of source data and the buffer memory in the cache information table, and the final updating temporal information in data cached is the temporal information at buffer update last time, as seen its contrast factor does not rely on the contrast of current system time, thereby no matter on any client computer, generate data cached, its time information is all taken from the set time information element in the cache information table, thereby can guarantee that data cached on each client computer is consistent;
And, the buffer update operation can be initiated as long as comparing result is inconsistent, thereby the instantaneity of buffer memory can be effectively guaranteed, and data cached real-time;
Moreover, because the present invention judges whether buffer memory needs the request of upgrading, only need to judge that according to the corresponding temporal information of identification information system resources consumption is very little, thereby has effectively improved the efficient of buffer memory;
At last, the present invention is by the data cached final updating temporal information of contrast cache information table and respective identification, and only under the inconsistent situation of comparing result, just initiate to upgrade, as long as unanimity is then represented source data and is not upgraded, thereby need not to initiate the renewal of buffer memory, further avoid the wasting of resources, improved buffer efficiency.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
One of core idea of the embodiment of the invention is, preset cache information table, the identification information and the final updating temporal information of record source data in the described cache information table, in practice, the rise time information of record source data is the final updating temporal information when generating source data, when upgrading described source data, with current update time information be designated as the final updating temporal information of described source data, when the user's access originator data first time, in local cache, generate the data cached of described source data, described data cached this source data and identification information and the final updating temporal information of comprising; When the user visits again described source data later on, earlier with the final updating temporal information contrast of writing down in final updating temporal information data cached described in the local cache and the cache information table, in case source data was once initiated renewal, for example, by the user edit, modification etc., the final updating temporal information of this source data can be changed in the then described cache information table, thereby in this case, comparing result is inconsistent, at this moment, then initiate data cached renewal to source data described in the local cache; If source data is not updated, the final updating temporal information of this source data can not change in the then described cache information table, at this moment, is consistent with the final updating temporal information in the described cache information table with data cached temporal information, in this case, then do not need to initiate renewal, and directly read this data cached getting final product data cached.
With reference to figure 1, show the flow chart of the method embodiment of a kind of website of the present invention buffer memory, specifically can may further comprise the steps:
The identification information of step 101, record source data and final updating temporal information are to cache information table;
Preferably, in the present embodiment, described recording step can comprise following substep:
Substep S1, generate source data and identification information thereof, described identification information recording to cache information table, is recorded to the rise time information of described source data in the cache information table as the final updating temporal information;
Substep S2, upgrade source data, according to current update time information revise the final updating temporal information of the identification information correspondence of this source data in the described cache information table.
Promptly in practice, for newly-generated source data, the final updating temporal information that is write down is the temporal information that described source data generates; For the renewal that described source data is carried out, the final updating temporal information that is write down is the last temporal information of upgrading of this source data.
The access request that step 102, reception are submitted to generates solicited message;
Wherein, described request information comprises the identification information of institute's access originator data;
Step 103, according to whether having the data cached of described source data in the described identification information judgment local cache, if there is no, then execution in step 104; If exist, then execution in step 105;
The final updating temporal information that writes down in step 104, the identification information that extracts described source data, described source data and the described cache information table generates the data cached of described source data in local cache;
Step 105, the final updating temporal information of respective identification information in described data cached final updating temporal information and the described cache information table is compared, if consistent, then execution in step 106; If inconsistent, then execution in step 104 regenerates the data cached of described source data in local cache;
Step 106, read described data cached.
The web of website using system is alternately usually based on C/S (Client/Server, client/server), or B/S (Browser/Server, browser/server) pattern, in C/S model, client directly links to each other with server, client is submitted to server with user's requirement, and server receives the service request that CLIENT PROGRAM proposes, and handles accordingly, again the result is returned to client, the result that client is returned server again is shown to the user with particular form; In the B/S pattern, the client operate browser software, browser proposes the requirement of accessing database to Web server with the hypertext form, after Web server is accepted client-requested, this request is converted into the SQL grammer, and give database server, after database server obtains request, verify its legitimacy, the line data of going forward side by side is handled, and the result after will handling then returns to Web server, and all results that Web server will obtain again transform, become the html document form, be transmitted to client browser and show with close friend's Web page format.The user carries out data alternately by client or browser and Web server and submits to, can trigger Web server and generate corresponding source data or corresponding source data is upgraded.
In practice, the user is by the access request of client computer submission at certain source data, the identification information that then can comprise this source data in the described access request, if the user visits this source data for the first time on current client computer, what can expect so is, be the data cached of not this source data in the buffer memory of current client computer, thereby need in the local cache of current client computer, generate data cached.For organizing data structurally, in the present embodiment, preferably, described source data is stored in first server, and described cache information table is stored in the second server.In this case, then in first server, extract the source data of respective identification information correspondence, in second server, extract simultaneously the final updating time of the source data of respective identification information correspondence, generate the data cached of the content, identification information and the final updating temporal information that comprise this source data then.
For managing and use described cache information table better, preferably, described cache information table is a Hash table.Under the bigger situation of data volume, a plurality of cache information table can also be set, for example, a Hash table is set at the source data in the certain limit.To make things convenient for searching of data.Be well known that, Hash table is according to the hash function H (key) that sets and handles the method for conflicting a set of keyword is videoed on the limited continuous address set, and with keyword in address set (interval) " as " as the memory location that is recorded in the table, in the present embodiment, the method to described structure Hash table does not limit.
For example, a kind of Hash table of structure as shown in Figure 2, wherein, described Tid is an identification information, described Cachetime is the final updating temporal information, hash algorithm relies on shown in following code:
Function createhash(string$tid){
$md5string=md5($tid);
Return substr($md5str,0,2);
}
As can be seen, in this example,, data are evenly distributed, and can split, reduce by two data magnitudes, make two data magnitudes of improved efficiency, thereby improve the response speed of server by data according to the hash computing.
For making those skilled in the art understand present embodiment better, below the process of visiting for the first time with the user who uses present embodiment be that example describes.
Example 1 is supposed party A-subscriber's Website login on the A client computer, and delivers one piece of article on the website, and content (being source data) is for " being familiar with you is very glad! ", its identification information Tid is 1, according to current time 2007091815:49:00, the timestamp of conversion rise time information is Cachetime:1190130540, then generates cache information table and is:
tid |
cachetime |
1 |
1190130540 |
Suppose that the party B-subscriber visits this article for the first time on the B client computer, the URL address of supposing this article is http://hostname/1.php, wherein, whether 1 is the identification information tid of this article, in this case, at first exist data cached accordingly in the local cache according to the condition judgment B client computer of tid:1, owing to be visit for the first time, so judged result is not for having, in this case, then from Website server, extract this identification information and be 1 article " being familiar with you is very glad! ", simultaneously in cache information table be that 1 final updating temporal information Cachetime:1190130540 extracts with this identification information, in the B client computer, generate data cached, shape as:
<xml>
<tid>1</tid>
<cachetime>1190130540</cachetime>
<content〉be familiar with you and be very glad!</content 〉
</xml>
If the user is not the access originator data first time, then the final updating temporal information with respective identification information in the data cached final updating temporal information of respective identification information in the buffer memory and the cache information table compares, it should be noted that, final updating temporal information in the cache information table is to upgrade according to the renewal of source data, that is to say, if source data has been upgraded, when upgrading its content, promptly trigger the renewal of its final updating temporal information, promptly replace existing final updating temporal information with the temporal information of current more new data.In this case, then the possibility of result of described contrast is consistent, may be for inconsistent, if consistent, show that then this source data do not carry out renewal, and therefore directly read this data cached the getting final product in the local cache; If it is inconsistent, show that then this source data upgrades, thereby the respective cache data in the local cache also should be upgraded, in this case, can extract content, identification information and the final updating temporal information of the source data of this final updating, in local cache, regenerate the data cached of this source data.
Following according to above-mentioned example 1 by instantiation for this non-first the visit situation describe.
Example 2 supposes that the party A-subscriber delivering above-mentioned article after 5 seconds, has edited this article again on the A client computer, and the content behind the editor is for " being familiar with you is very glad! Give us your advice later on! ", at this moment,,, also needing the final updating temporal information of respective sources data in the cache information table is upgraded along with the renewal of feed data content according to stabbing to Cachetime:1190130545 change-over time current time, the cache information table after the renewal is:
tid |
cachetime |
1 |
1190130545 |
At this moment, suppose that the party B-subscriber has refreshed this article on the B client computer, the URL address of this article still is http://hostname/1.php, and wherein, 1 is identification information tid, calls data cached 1.xml, and the data cached of acquisition is:
<xml>
<tid>1</tid>
<cachetime>1190130540</cachetime>
<content〉be familiar with you and be very glad!</content 〉
</xml>
Obtaining this data cached final updating temporal information is 1190130540, cachetime in itself and the cache information table is compared, can obtain comparing result is: 1190130545>1190130540, and comparing result is inconsistent, thereby initiates data cached renewal:
" be familiar with you is very glad source data after extraction is upgraded! Give us your advice later on! ", the final updating temporal information cachetime:1190130545 that writes down in identification information 1 and the cache information table, regenerate and data cachedly be:
<xml>
<tid>1</tid>
<cachetime>1190130545</cachetime>
<content〉be familiar with you and be very glad! Give us your advice later on!</content 〉
</xml>
Suppose after 5 minutes in, do not have the user that this model is upgraded, refresh or access request again if user B continues on the B client computer this model submitted to, call and data cachedly still be accordingly in the buffer memory:
<xml>
<tid>1</tid>
<cachetime>1190130545</cachetime>
<content〉be familiar with you and be very glad! Give us your advice later on!</content 〉
</xml>
Obtaining this data cached final updating temporal information is 1190130545, cachetime in itself and the cache information table is compared, can obtain comparing result is: 1190130545=1190130545, and the comparing result unanimity, this is data cached thereby directly read.
As can be seen, the present invention is by comparing the final updating temporal information in data cached in record final updating temporal information of source data and the buffer memory in the cache information table, and the final updating temporal information in data cached is the temporal information at buffer update last time, as seen its contrast factor does not rely on the contrast of current system time, thereby no matter on any client computer, generate data cached, its time information is all taken from the set time information element in the cache information table, thereby can guarantee that data cached on each client computer is consistent; And, the buffer update operation can be initiated as long as comparing result is inconsistent, thereby the instantaneity of buffer memory can be effectively guaranteed, and data cached real-time; Moreover, because the present invention judges whether buffer memory needs the request of upgrading, only need to judge that according to the corresponding temporal information of identification information system resources consumption is very little, thereby has effectively improved the efficient of buffer memory; At last, the present invention is by the data cached final updating temporal information of contrast cache information table and respective identification, and only under the inconsistent situation of comparing result, just initiate to upgrade, as long as unanimity is then represented source data and is not upgraded, thereby need not to initiate the renewal of buffer memory, further avoid the wasting of resources, improved buffer efficiency.
With reference to figure 3, show the structured flowchart of the device embodiment of a kind of website of the present invention buffer memory, specifically can comprise with lower unit:
Record cell 301 is used for writing down the identification information of source data and final updating temporal information to cache information table;
Interface unit 302 is used for the access request that subscribing client is submitted to, generates solicited message, and described request information comprises the identification information of institute's access originator data;
Judging unit 303 is used for whether having the data cached of described source data according to described identification information judgment local cache, if there is no, then triggers buffer memory creating unit 304; If exist, then trigger contrast unit 305;
Buffer memory creating unit 304 is used for extracting the identification information of described source data, described source data and the final updating temporal information that described cache information table writes down, and generates the data cached of described source data in local cache;
Contrast unit 305, be used for the described data cached final updating temporal information and the final updating temporal information of described cache information table respective identification information are compared, and when unanimity, trigger reading unit 306, when inconsistent, call buffer memory creating unit 304 and in local cache, regenerate the data cached of described source data;
Reading unit 306 is used to read described data cached.
Preferably, in the present embodiment, described record cell further comprises following subelement:
Generate the record subelement, be used to generate source data and identification information thereof, described identification information recording to cache information table, is recorded to the rise time information of described source data in the cache information table as the final updating temporal information;
More the new record subelement is used to upgrade source data, according to current update time information revise the final updating temporal information of the identification information correspondence of this source data in the described cache information table.
Preferably, in the present embodiment, can also comprise memory cell, be used to store described source data.
More preferably, described memory cell is positioned at first server end, described record cell second server end.
More preferably, described cache information table is a Hash table.
With reference to figure 4, show and use the flow chart that preferred embodiment embodiment shown in Figure 3 carries out the website buffer memory, specifically can may further comprise the steps:
The identification information of step 401, recording unit records source data and final updating temporal information are to cache information table;
Preferably, described record cell can be realized its function by following subelement:
Generate the record subelement and generate source data and identification information thereof, described identification information recording to cache information table, is recorded to the rise time information of described source data in the cache information table as the final updating temporal information;
More the new record subelement upgrades source data, according to current update time information revise the final updating temporal information of the identification information correspondence of this source data in the described cache information table.
The access request that step 402, interface unit subscribing client are submitted to generates solicited message;
Wherein, described request information comprises the identification information of institute's access originator data;
Step 403, judging unit if there is no, then trigger buffer memory creating unit execution in step 404 according to whether having the data cached of described source data in the described identification information judgment local cache; If exist, then trigger contrast unit execution in step 405;
Step 404, buffer memory creating unit are extracted the final updating temporal information that writes down in the identification information of described source data, described source data and the described cache information table, generate the data cached of described source data in local cache;
The final updating temporal information of respective identification information compares in final updating temporal information that step 405, contrast unit are will be described data cached and the described cache information table, and when unanimity triggering reading unit execution in step 406; When inconsistent, call buffer memory creating unit execution in step 404;
Step 406, reading unit read described data cached.
For device embodiment, because it is substantially corresponding to method embodiment, so description is fairly simple, relevant part gets final product referring to the part explanation of method embodiment.
In practice, can obtain to optimize for making the present invention, the present invention can based on LAMP (
Apache, MySQL and PHP/Perl/Python) the framework realization, promptly comprise (SuSE) Linux OS, the Apache webserver, the MySQL database, PHP, Perl or Python programming language, it is one group of open source software that is commonly used to build dynamic website or clothes server, it itself all is program independently separately, but because often be brought together use, had more and more higher compatibility, formed a powerful web application platform jointly.Application program based on LAMP is to write with the such script of PHP (sometimes replacing with Perl or Python), and they are as the part operation of the Apache Web server that moves on the Linux main frame.The PHP application program by URL, all form datas of request and any session information of having caught from the client computer acquired information, thereby determine carry out what operation.If necessary, server can be from MySQL database (also moving at Linux) acquired information, with these information and some HypertextMarkup Language (HTML) form assemblies together, and the result is returned to client computer.When the user navigated in application program, this process repeated; When a plurality of user capture system, this process can concurrent carrying out.But data flow is not unidirectional, because can be used for information updating database from the user, comprises the content (upgrading such as comment or website) that session data, statistics (comprising ballot) and user submit to.Except dynamic element, also has static elements, such as image, JavaScript code and CSS (CSS).
The present invention can be used for numerous general or special purpose computingasystem environment or configuration.For example: personal computer, server computer, handheld device or portable set, plate equipment, multicomputer system, the system based on microprocessor, set top box, programmable consumer-elcetronics devices, network PC, minicom, mainframe computer, comprise distributed computing environment (DCE) of above any system or equipment or the like.In addition, the present invention can also describe in the general context of the computer executable instructions of being carried out by computer, for example program module.Usually, program module comprises the routine carrying out particular task or realize particular abstract, program, object, assembly, data structure or the like.Also can in distributed computing environment (DCE), put into practice the present invention, in these distributed computing environment (DCE), by by communication network connected teleprocessing equipment execute the task.In distributed computing environment (DCE), program module can be arranged in the local and remote computer-readable storage medium that comprises memory device.
More than the method for a kind of website provided by the present invention buffer memory and the device of a kind of website buffer memory are described in detail, used specific case herein principle of the present invention and execution mode are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that all can change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.