In fact, when your Web site using ASP technology to establish the initial stage, you may feel that the ASP Dynamic Web technology brings convenience, as well as the arbitrary modification of the HTTP control freely. But as the number of visits increases, you will find that your site is getting more and more slow, and IIS is restarting more and more frequently.
One, what is ASP cache/Why to cache
In fact, when your Web site using ASP technology to establish the initial stage, you may feel that the ASP Dynamic Web technology brings convenience, as well as the arbitrary modification of the HTTP control freely. But as the number of visits increases, you will find that your site is getting more and more slow, and IIS is restarting more and more frequently. Then, you will want to optimize your ASP program, such as replacing a better performance database, indexing, writing stored procedures, and so on. Some of these measures do not need to increase the cost of pressure, some are very expensive (for example, bundle access to SQL), and the effect is not necessarily.
In the face of Web access pressure, I think the most economical way is to use caching optimization technology to ease the Web service pressure.
The increase in web traffic usually means a rapid increase in the following resource requirements:
1, the network card traffic increases, need to consume more CPU processing network traffic and network I/O thread.
2, the need to open/close the database links more frequently (if you use database technology-Typically, ASP will use the database as the data store), the amount of things that seriously consumes resources, and transactions competing for resources caused by deadlock, increase network I/O or CPU consumption.
3, if the use of Session, IIS in order to maintain state, will consume more memory, and memory consumption may cause insufficient physical memory, resulting in physical memory and secondary storage frequent exchange, resulting in code execution of the pause, web response block.
4, due to the lack of access to timely response, will cause Web page access failure, resulting in user refresh, thereby exacerbating the CPU, memory and other resource needs.
In fact, most of the time dynamic code execution is unnecessary, considering the usual web applications.
Second, the ASP cache classification
In summary, the ASP cache can be divided into two categories:
1. File caching
The so-called file caching, is based on logical judgment, a certain period of time, the implementation of an ASP will not be very big changes, so the content in the form of static HTML storage, and then with the Web redirect technology to allow clients access to static files, to reduce CPU, database resources and so on. Such a lot of applications, such as many forums in reply to the post when the entire post to regenerate a static file, and then redirect, such as Donews.com forum. The static also has a side effect (benefits)-can easily be indexed by Google and other search engines. Some of the so-called press release systems are using this technology.
2. File Fragment Caching
So-called file caching, it is also based on logical judgment, a certain part of the data (usually the need to consume resources of the bulk database query) will not change for a certain period of time, so we can use the form of file storage, when it is necessary to read the file to obtain data, to avoid increasing the burden of the database. For example, we usually store some data in XML format, and then use XSLT technology to implement the display (XML processing usually requires a lot of CPU resources, so it is usually IE read the XML directly to the client on the customer's CPU). This is how CSDN's forum is handled.
3, main memory cache
In addition, it is possible to consider processing caching in memory, storing content that needs to be responsive in memory, and delivering it immediately from a fast store once access is needed. If a large number of access requirements are concentrated in a few small pages or main memory, I would like to use main memory cache can greatly improve Web access performance.
Iii. How to implement/use caching
Implementing caching requires consideration of the following issues:
1, which pages will not change in a short period of time?
Analysis of their own site, such a lot of pages. For example, a site usually has news information class columns, these columns are usually site maintenance staff at a certain time of day to release information, and then rarely change the page. These pages are suitable for use with static file caching. In fact, the so-called press release system is to do so, then it can also refer to the ideas of these systems to transform their original dynamic ASP page.
2, those pages for all visitors to use the same logical generation (that is, not distinguish between visitors).
In addition to news and information such as the column of all visitors to look at an interface, the forum, such as the use of resources used in general can also be designed as a unified logic generation (the same post, Dick look alike), for such application pages we can also use static cache to achieve. It is also possible to consider fragmentation of the data, using scripting techniques that are handled by the client browser beyond the server's processing power.
3, the use of the cost of caching and harvesting.
The main thing is "space Exchange (response) time." Using caching technology to preprocess the frequently needed content to improve the responsiveness of Web servers is more important to win the favor of visitors.
The cost is the increase in web space requirements, while it may affect the access effect.
But I think the proper caching is more beneficial than the disadvantage.
4, those places are not suitable to use the cache
Dynamic Query page, each person's query content is not the same, so the results are not the same, so it is unlikely to generate a cache of query results, so the use of caching is more complex and cache utilization, resulting in management costs (assuming you cache 1000 query keywords, It is also troublesome to manage these keywords in response to the cache.
Iv. Example Analysis
Suppose the original layout of a suggested forum is as follows:
Root directory:
Default.asp Home, General is the essence, recommend and so on
Listborad.asp This document lists the name and description of all the columns, and if you carry the parameter mainbid, you will list the columns under the plate.
listthread.asp If the file does not carry any parameters indicating that all the posts are listed, carry mainbid to indicate that all posts of a block are listed. If you carry subbid to express the list of specific column posts. If you carry a page parameter to represent pagination, list the topics.
Viewthread.asp list the content of a posting. Let's assume that the post is displayed as a statement, with any comments listed at the back. The ID parameter is the post to display.
Reply.asp respond to a post, carrying a parameter ID to respond to a posting
The rest of the discussion is pending.
Above, we can see, if all is to use the original asp/php to do, that almost every ASP file execution needs database operation, frequent query, multiple table query. To know that the query database will eventually bring performance degradation, the response speed down, bring visitors slow browsing impact, not conducive to the quality of the web. More importantly for a B two people to Will, they visit viewthread.asp and the like if the ID is the same, so many times they will see the same content (their browser received almost the same HTML code), but for this "the same content", The server needs to open database links, queries, read records, display, close records, database links .... The following operations that consume server resources, if more people visit, end up consuming server resources. In fact, the repetitive work done for the "same content" can be avoided by using caching techniques. Such as:
After reply.asp commits the content, we call the generation static function immediately, the entire post content is stored as viewthread_xxxx.htm and so on the static HTML file, then normally accesses the viewthread.asp?id=xxxx time, The system automatically redirect to the corresponding static file viewthreadxxxx.htm go. In this way, when a post is not the latest release, he is always static content provided to the browser, once the new submission, will be updated to the static file, so that will save a lot of database operations, greatly improve the response speed.
Listborad.asp can also be implemented statically. We can analyze the parameters that it may carry, set the cache filename to listboard_xx.htm, and update listboard_xxx.htm when adding new columns. Listthread.asp is similar, except that there are many cached files because of their more parameters. Click to cache listthread.asp? subbid=xxx&page=2, then the corresponding static file is listthread_xxx_p2.htm. The same is default.asp.
So how do you decide when to update? At what time is it updated?
Discuss listthread.asp? subbid=xxx&page=2, we extracted subid and page in the execution of listthread.asp and then probed Listthread_xxx_ P2.htm is present, and if it does not exist, invoke the static build function to generate the file, which is eventually redirected to this static file. Note that the absence here means that new content needs to be updated.
How does that cause the file not to exist? Delete. We can delete static files like listthread_xxx_p2.htm when we publish a new post, delete posts, and move posts. This informs when the cache is to be cached.
Now there is a problem, how to generate a static file?
We note that the "same content" that we mentioned earlier. We can copy a copy of Default.asp, listthread.asp, etc. before the transformation, named Default_d.asp, Listthread_2.asp, and in the same directory (theoretically listthtrad.asp?subid= 123 with listthread_d.asp? Subid=123 's access will be the same, so that we can invoke the modified copy, get the HTML code, and store it as a static file, in the logic of the need to generate a static file, through a Web Access request. This Web request actually corresponds to the HTML that the server itself will output before any real viewer accesses the static content, and then returns the code, which is stored as a static file using the file manipulation function. In this way, the cached file is created before the true viewer.
Such a scheme almost does not touch the original layout, almost do not cause the transformation of the 404 error. Second, static files will also help your site is easily indexed by Google and other search engines. Why
Finally, to remind, through the Web Access, ASP programming environment, many people adopt XMLHTTP component access, this can cause many problems. The XMLHTTP itself will cache the requested resources, causing the content we request through this component to be not up to date, resulting in logical confusion. Therefore, you should select an XML Server HTTP object or WinHTTP component to implement the Web request resource.
80: The implementation of caching technology There are several key things,
Server-side application, suitable for multiple pages there are more infrequently updated elements;
Generate HTML static files, usually using template technology, through the FSO or Adostream to generate static files, usually applicable to many people see the same page content of the situation, such as articles, forum posts, etc.;
Other
In fact, the most important thing is based on the needs of their own system to decide what technology to use, minimize the number of query database, reduce the database pressure, of course, usually at the expense of space to do.
In addition, are you considering the possibility of using the client's cache to improve efficiency?