1. What is ASP cache/why cache
In fact, when your web site is established in the early stage of ASP technology, what may feel is the convenience brought by the ASP dynamic web technology, as well as the free modification and free HTTP control. But with the increase of access volume, you will definitely find that your site access speed will become slower and slower, and IIS has re -started. So, you must want to optimize your ASP program, such as changing databases with better performance, establishing indexes, writing storage procedures, and so on. Some of these measures do not need to increase cost pressure, while some of the cost pressure (such as cluster Access to SQL), and the effect is not necessarily.
Facing the pressure of web access, I think the most economical method is to use cache optimization technology to relieve the service pressure of Web.
Increased web access volume usually means the rapid growth of the following resource demand:
1. Increased network card traffic, it is necessary to consume more CPU processing network traffic and network I/O threads.
2. It is necessary to open/close the database connection more frequently (if the database technology is used -usually ASP will use database as data storage), the number of things that seriously consume resources, and the deadlock caused by the competing resources of transactions, which will increase the network I/O. Or CPU consumption.
3. If the session is used, IIS will consume more memory in order to maintain the status, and the memory consumption may cause insufficient physical memory, cause frequent exchange between physical memory and the auxiliary memory, which causes the code execution to stop. Essence
4. Due to the timely response of the access, the webpage access failure will be caused, which will cause users to refresh, thereby exacerbating the needs of CPUs, memory and other resources.
In fact, considering the usual web application, many times the dynamic code execution is unnecessary.
2. Classification of ASP cache
Summarizing without authorization, the cache of ASP can be divided into two categories:
1. File cache
The so -called file cache is to judge according to the logical judgment. For a period of time, the specific execution of a certain ASP will not change greatly. Therefore, the content is stored in the form of static HTML, and then the client can access the static file from the web redirection to technology , To meet the needs of reducing CPUs, database resources. There are many such applications. For example, many forums re -generate a static file when they reply to the stickers, and then redirect, such as Donews.com's forum. The static static side has a side effect (benefits) -the can be easily included by search engines such as Google. Some so -called press release systems have adopted this technology.
2. File film break cache
The so -called file cache is also based on logical judgment. A part of the data (usually a large -capacity database query that needs to be consumed to consume resources) will not change in a certain period of time, so we can store this data in the form of files. You can obtain data by reading files to avoid increasing the burden on the database. For example, we usually store some data in XML format, and then use XSLT technology to implement display (XML processing usually requires a large amount of CPU resources, so IE usually reads XML directly to the client to handle it on the customer's CPU). This is how CSDN's forum is processed.
3. Main memory cache
In addition, you can also consider dealing with the cache in memory, and store the content that need to be responding in a timely manner in memory. Once you access the demand, immediately transport it from quickly storage. If a large number of access needs are concentrated on several small pages or main storage, I want to use the main memory cache to greatly improve the web access performance.
3. How to achieve/use cache
The following issues need to be considered to implement the cache:
1. Which pages will not change in a short time?
Analyze your own site, there are many pages. For example, a site usually has news and information columns. These columns are usually published information at a certain time of the site maintenance personnel, and then they rarely change the page. Then these pages are suitable for cache with static files. In fact, the so -called press release system is done, so you can also refer to the ideas of these systems to transform your original dynamic ASP page.
2. Those pages are generated for all visits to generate the same logic (that is, not distinguish between visitors).
Except for the columns such as news and information, all visitors look at a interface, and the application of resources such as forums and other consumption resources can generally be designed as a unified logic generation (the same post, Zhang Sanli and Sisi are the same). It can be implemented with a static cache. You can also consider breaking the data and using script technology in addition to the server processing capacity, that is, the client browser for processing.
3. Use the cost and harvest of cache.
Mainly the time for space changes (response). Use cache technology to pre -process the frequently needed content to improve the response ability of the web server, and more importantly win the favor of the visitors.
The price is that the demand for web space increases, and it may affect the access effect.
But I think that the proper cache is greater than the disadvantages.
4. Instead of using cache in those places
The dynamic query page, each person's query content is different, so the display results are not the same, so it is unlikely to generate the query result cache, so the cache is more complicated and at the bottom of the cache utilization rate, resulting in the management cost. 1,000 query keywords, then the corresponding correspondence to managing these keywords is also troublesome).
Fourth, instance analysis
Suppose the original layout of a suggestion forum is as follows:
In the root directory:
default.asp homepage, generally essence, recommendation and the like
ListBorad.asp This file lists the names and introduction of all columns. If you carry the parameter mainBID, it means to list the column under the plate
ListThread.asp The file does not carry any parameters to indicate all the stickers and carry MainBid to represent all the stickers of a certain piece. If Subbid is carried to indicate the post of the specific column. If you carry the Page parameter to indicate the pagination of the topic.
ViewThread.asp lists a certain sticker content. We assume that posts are displayed as a speech, and all follow the stickers are listed behind. The ID parameter is the post to be displayed.
Reply.asp responds to a certain post, carry the parameter ID to respond to a certain post
No other discussion.
Above, we can see that if all of them are done using the original ASP/PHP, the execution of almost every ASP file requires database operations, frequent query, and multiple querys. It should be known that the query database will eventually bring a decline in performance, the response speed decreases, and the slow browsing impact on the visitors will not be conducive to the quality of the web. More importantly, for the two people in A and B, they visited ViewThread.asp and the like if IDs are consistent, then many times they will see the same content (the HTML code received by their browser is almost the same), but for this for this In the same content, the server needs to open the database connection, query, read records, and show that the records and database connections are closed. Essence Essence Essence If more people are accessed by more people, the end result is that these people exacerbate server resources. In fact, the duplicate labor for the same content can be optimized with cache technology. for example:
After submitting the content of the repy.asp, we immediately called the static function to generate the static content to the static HTML files such as viewthread_xxxx.htm, and then when visiting ViewThread.asp? ID = xxxx, the system automatically automatically Redirect to the corresponding static file viewThreadxxxx.htm. In this way, when a post is not latest, he is always provided to the viewer static content; once a new submission is, it will be updated to the static file. speed.
ListBorad.asp can also implement static. We can analyze the parameters that may be carried, set the cache file name to listboard_xx.htm, and update the listboard_xxx.htm when adding a new column. ListThread.asp is similar, but because of more parameters, there will be a lot of cache files. If you want to cache listthread.asp? Subbid = xxx & page = 2, then the corresponding static file is listThread_xxx_p2.htm. The same is true of default.asp.
So how to judge when to update? What time to update?
讨论listThread.asp? subBID=xxx&page=2,我们在执行listThread.asp俄时候提取subID和page,然后探测listThread_xxx_p2.htm是否存在,如果不存在就调用静态生成功能进行生成该文件,最终重定向到此Static file. Note that no existence here means that the emergence of new content requires us to update.
How can the files do not exist? delete. We can delete all static files like listthread_xxx_p2.htm when publishing a new sticker, deleting stickers, and moving stickers. In this way, the cache is notified.
There is still one problem left now, how to generate static files?
We noticed that the same content we mentioned before.我们可以将改造前的default.asp、listThread.asp等拷贝一个副本,取名为default_d.asp、listThread_2.asp,且在同一个目录中(理论上listThtrad.asp?subID=123同LISTtHREAD_D.ASP? The access results of subid = 123 will be the same content), so that in the logic of the need to generate static files, we call the copy before the modification by the web access request, obtain the HTML code, and store it as a static file. This web request is actually equivalent to before any real viewer accesss static content, the server itself is inspected by the HTML that will be output, and then return these code to store the file operation function as a static file. In this way, the cache file was created before the real viewer.
Such a scheme almost does not touch the original layout, and it will hardly cause errors such as 404 due to transformation. Secondly, static files will also help your site is easily included by search engines such as Google. Why not?
Finally, remind that through the web access, in the ASP programming environment, many people use XMLHTTP components to access, which will cause many problems. The resource that XMLHTTP itself will Cache requests, resulting in the content obtained by our requests through this component, causing logical confusion. Therefore, you should choose XML Server HTTP objects or WinHTTP components to implement Web request resources.
80 post -picked language: There are several key things to achieve cache technology,
The server side Application, which is suitable for multiple pages, there are more elements that are not often updated;
The HTML static file is generated, and template technology is usually used to generate static files through FSO or Adostream. It is usually suitable for many people to see the same page content, such as articles, forum posts, etc.;
other
In fact, the most important thing is to decide what technology to adopt according to the needs of your own system to minimize the number of query database as possible and reduce the pressure of databases. Of course, it is generally at the cost of sacrificing space.
In addition, is it considering whether the cache of the client can be used to improve efficiency?