A kind of efficient caching method and system of serverTechnical field
The present invention relates to a kind of efficient caching method and system of computer system data disposal route, particularly a kind of server, be applicable to the computer service system that Data Update is more frequent.
Background technology
At present, in the page program of website, generally all can relate to some and be stored in general information in the database server, as the province tabulation, commodity classification etc., these information all are identical for each calling party.Usually during each user capture, all to go database server to read, be shown to the user then; The database server load is increased the weight of, can't serve prior issued transaction fast, and the web server also must ceaselessly be created the database server connecting object, the consumption ample resources, caused when the user is a lot, the response speed of webpage is very slow.For example, there are 100 people that certain webpage is sent request of access in the same time, so just need from database server, read 100 secondary data, send to the people that these send request of access then respectively, be a kind of great waste like this to the database server resource of preciousness, very low to the efficient of same categorical data frequent access.
Summary of the invention
The objective of the invention is to, a kind of efficient caching method and system of server is provided, it can reduce the visit capacity of database server,Improved efficient to same categorical data frequent access.
For solving the problems of the technologies described above, the present invention adopts following technical scheme: a kind of efficient caching method of server may further comprise the steps:
S1, the web server receives the request of access that the user sends;
The request of access that S2, web server send according to the user is sent to the buffer memory service equipment and is write or the request of reading of data;
S3, buffer memory service equipment write or reading of data according to the request of web server, and data streams read is returned to the web server.
In the efficient caching method of aforesaid a kind of server, described step S3 comprises: during the data that do not have in the expired or buffer memory service equipment when the data of storing in the buffer memory service equipment to inquire about, the buffer memory service equipment sends the reading of data request to database server, return to the web server obtain data from database server after, the buffer memory service equipment is also preserved these data a simultaneously.
In the efficient caching method of aforesaid a kind of server, the expired determination methods of the data of storing in the described buffer memory service equipment is: is set effective time for the data of storing in the buffer memory service equipment.Surpassing the storage time of data is expired described effective time.
Described buffer memory is transparent for access program, need not buffer memory be set explicitly.Only need indicate this access, may how long effective.Back buffer memory service equipment can be provided with the result data of this visit the effective time of one section designated length, and in effective time, same request can not impact back-end data base, just directly the result is returned.
Realize the efficient caching system of a kind of server of preceding method, comprising:
The request receiver module is used for the web server and receives the request of access that the user sends;
Data demand module is used for the request of access sent according to the user, and the web server sends to the buffer memory service equipment and writes or the request of reading of data;
Data processing module is used for the request according to the web server, and the buffer memory service equipment writes or reading of data, and data streams read is returned to the web server.
In the efficient caching system of aforesaid a kind of server, be provided with the data check module in the described data processing module, be used for verification current cache service equipment and whether exist the data of user inquiring or data whether expired, and database server is sent the reading of data request according to the verification situation.During the data that do not have in the expired or buffer memory service equipment when the data of buffer memory service equipment to inquire about, the buffer memory service equipment sends the reading of data request to database server, return to the web server obtain data from database server after, the buffer memory service equipment is also preserved these data a simultaneously.
In the efficient caching system of aforesaid a kind of server, be provided with time block in the described data check module, time block is used for to the data that the buffer memory service equipment is stored being set effective time.Surpassing the storage time of data is expired described effective time.
Described buffer memory is transparent for access program, need not buffer memory be set explicitly.Only need indicate this access, may how long effective.Back buffer memory service equipment can be provided with the result data of this visit the effective time of one section designated length, and in effective time, same request can not impact back-end data base, just directly the result is returned.
Compared with prior art, the present invention adopts the buffer memory service equipment, the user during to same categorical data frequent access, the data that obtain by database server in the time of the user can being visited for the first time are stored in the buffer memory service equipment, later visit data can directly read from the buffer memory service equipment, do not need the accessing database server, reduced the visit capacity of database server,Improved efficient to same categorical data frequent access.
Description of drawings
Fig. 1 is the structural representation of a kind of embodiment of the present invention;
Fig. 2 is the workflow diagram of embodiments of the invention.
Reference numeral: 1-asks receiver module, 2-data demand module, 3-data processing module, 4-web server, 5-buffer memory service equipment, 6-database server, 7-data check module.
The present invention is further illustrated below in conjunction with the drawings and specific embodiments.
Embodiment
Embodiments of the invention: a kind of efficient caching method of server may further comprise the steps:
S1, the web server receives the request of access that the user sends;
The request of access that S2, web server send according to the user is sent to the buffer memory service equipment and is write or the request of reading of data;
S3, buffer memory service equipment write or reading of data according to the request of web server, and data streams read is returned to the web server.
Described step S3 comprises: during the data that do not have in the expired or buffer memory service equipment when the data of storing in the buffer memory service equipment to inquire about, the buffer memory service equipment sends read data operation to database server, from database server, obtain after the data, return to the web server, the buffer memory service equipment is also preserved these data a simultaneously.
The expired determination methods of the data of storing in the described buffer memory service equipment is: is set effective time for the data of storing in the buffer memory service equipment.Surpassing the storage time of data is expired described effective time.Be 1min the effective time that present embodiment is provided with data.
Described buffer memory is transparent for access program, need not buffer memory be set explicitly.Only need indicate this access, may how long effective.Back buffer memory service equipment can be provided with the result data of this visit the effective time of one section designated length, and in effective time, same request can not impact back-end data base, just directly the result is returned.
Realize the efficient caching system of a kind of server of preceding method, comprising:
Request receiver module 1 is used forweb server 4 and receives the request of access that the user sends;
Data demand module 2 is used for the request of access sent according to the user, andweb server 4 sends to buffermemory service equipment 5 and writes or the request of reading of data;
Data processing module 3 is used for the request according toweb server 4, and buffermemory service equipment 5 writes or reading of data, and data streams read is returned toweb server 4.
Be provided withdata check module 7 in the describeddata processing module 3, be used for verification currentcache service equipment 5 and whether exist the data of user inquiring or data whether expired, anddatabase server 6 is sent the reading of data request according to the verification situation.During the data that do not have in the expired or buffermemory service equipment 5 when the data of buffermemory service equipment 5 to inquire about, buffermemory service equipment 5 sends the reading of data request todatabase server 6, return toweb server 4 obtain data fromdatabase server 6 after, buffermemory service equipment 5 is also preserved these data a simultaneously.
Be provided with time block in the describeddata check module 7, time block is used for to the data that the buffer memory service equipment is stored being set effective time.Surpassing the storage time of data is expired described effective time.Be 1min the effective time that present embodiment is provided with data.
Described buffer memory is transparent for access program, need not buffer memory be set explicitly.Only need indicate this access, may how long effective.Back buffer memory service equipment can be provided with the result data of this visit the effective time of one section designated length, and in effective time, same request can not impact back-end data base, just directly the result is returned.
The workflow of a kind of embodiment of the present invention: (as Fig. 2)
S1, the web server receives the request of access that the user sends;
The request of access that S2, web server send according to the user is sent to the buffer memory service equipment and is write or the request of reading of data;
S3, buffer memory service equipment write or reading of data according to the request of web server, and data streams read is returned to the web server.
Example explanation: such as 1000 certain stars' of user capture homepage was arranged in one minute, this homepage will obtain star's bean vermicelli tabulation, traditional method obtains star's bean vermicelli tabulation, is to read identical data from database 1000 times, is distributed to each user then respectively.If use method of the present invention, only need read one time the data in the database, these data are kept in the buffer memory, and expired time is set 1 minute, except first user is data in the reading database, all the other 999 people are the results who reads from buffer memory, can save the expense of reading database like this, reduce the frequency of reading database greatly.In addition, because first user is the data that directly read from database, outside the shared time is long slightly, other users are the data that read from buffer memory within expired time, the browser response is fast especially, and the page is presented in face of the user very soon, has brought favorable experience to the user.
Say for another example, the someone has visited 50 pages within 10 minutes, each page all need be obtained good friend's relation, and the possibility that these good friends passes tie up to variation within 10 minutes is little, when not needing so whenever to browse a page, all send the request of friend information in the reading database.Only this friend information need be buffered in the buffer memory service equipment, and 10 minutes expired time are set, can directly fetch data from the buffer memory service equipment when getting good friend's relation within expired time, it is fast to read page data speed, has brought favorable experience to the user.