Simple page buffering technology (1) (reposted to Chinese users ). The preface is actually a technology, maybe not a real technology. This is just a page processing method I have come up with. of course, it may be consistent with others' ideas. However, I would also like to explain
It is actually a technology, maybe not a real technology. This is just a page processing method I have come up with. of course, it may be consistent with others' ideas. But I still want to give it a nice name. So what is the page buffer I refer to here? This means to save the dynamically generated page for the next use. In this way, the next access may not need to be dynamically generated. Just like providing a cache. On my website, maybe the same is true for your website. with technologies such as templates, the pages you see are dynamically generated. However, if a page is like this for you and others, it will not change for a period of time, isn't it better to directly return the result generated last time to the user who accessed the next time? This reduces the generation time and is more efficient. I think with the development of the website, the speed and efficiency issues still need to be considered. Here I will provide my implementation, hoping to help you. There is no specific implementation.
Usage conditions
Is it best to use all webpages? I don't want it, and it's impossible. The reason for buffering is that the content of the next access and the last access may be exactly the same. Therefore, it is not suitable for frequently changing pages. For example, it is not appropriate to display the count information on the page. In addition, if your dynamic page output is not first output to the variable, but directly returned to the user, such as echo, print, readfile, I personally don't think it can be done yet. Because I cannot get the output result and save it to the file (I thought for a long time that I didn't come up with anything to cut the output and redirect it to the file ). The appropriate processing of dynamic pages is that the output results can be put into a string. Therefore, the conditions are as follows:
The page remains unchanged.
The processing results of dynamic pages can be stored in strings.
In this way, it is good to use the template class to process dynamic pages. You can set replaceable variables in the template, replace the variables in the template according to the actual values, and put the results in strings for output, the processing of this template class is very suitable for storing processed pages. Of course, it is feasible to generate output results without using a template class or using string processing. We will not discuss how to do this.
Implementation
As mentioned above, it is not a real implementation, but an implementation idea.
Process:
Generate a buffer file name based on the access requirements.
Check whether the file name exists. if the file does not exist, a dynamic page is generated, the page is saved, and the result is output at the same time. if the file exists, perform step 1.
Statistics on the modification time of files and the modification time of files related to dynamic page generation
Compare the modification time of the cached file with the modification time of other pages. if the modification time of other pages is later than the modification time of the cached file, the dynamic page result may be changed, save it to the file and output the result to the end. otherwise, perform step 1.
Indicates that the buffer file is up to date, and the buffer file is output directly.
This is my processing. You can create a temporary directory or use a database to store the cached files. If a database is used, the method for determining whether the file is up-to-date should also be changed. for example, you can add a generated time field to the database and compare the modification time between the time field and other files. The method is self-developed.
Actually, token is a technology. maybe it cannot be a real technology. This is just a page processing method I have come up with. of course, it may be consistent with others' ideas. But I still...