Learn ASP Cache classes together

Source: Internet
Author: User
Tags copy execution iis implement sql query access root directory
When your Web site uses 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. However, as the number of visits increases, you will find that your site is getting more and more slow, and IIS restarts more and more frequently. Next, you will want to optimize the ASP, 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.

One, what is ASP cache/why to cache

When your Web site uses 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. However, as the number of visits increases, you will find that your site is getting more and more slow, and IIS restarts more and more frequently. Next, you will want to optimize the ASP, 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, the results are not the same, so it is not likely to generate a cache of query results, the adoption of a more complex cache and low cache utilization, resulting in management costs (assuming you cache 1000 query keywords, then management of these keywords with the cache corresponding is also a problem).

Iv. Example Analysis

Suppose the original layout of a suggested forum is as follows:

Root directory:
Default.aspHome, is generally the essence, recommend and so on

listborad.aspThis document lists the names and descriptions of all the columns, and if you carry the parameter mainbid, you will list the columns under the plate.

listthread.aspIf 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.aspList the contents of a post. 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.aspResponding to a post, carrying a parameter ID to respond to a post

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, they visit viewthread.asp and so on, 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 "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.

Using caching technology in ASP can greatly improve your site performance, but these implementations are very simple, and it will show how the caching on the server works and how you use an ADO connection technology called disconnected.

Before introducing these technologies, let's explain exactly what an ASP's caching technology is.
The so-called cache is actually in memory to open up a space to save data, using the cache you do not have to frequent access to the data you have saved on the hard disk, flexible use of the cache you will be spared the distressed look at the poor hard drive read data tortured. Once you have executed a query action and put the query results into the cache, you can quickly and repeatedly access the data. And if you do not put the data into the cache, when you execute the query again, the server will consume the process from the database to get and sort.

When the data is stored in the cache, the time taken to Requery is primarily the time it takes to display the data.

That is, we should not put data that is often needed to change into a server-side cache, and we should put the data in the cache with fewer changes, but with frequent access.

Now let's talk about ASP's use of caching technology on the server side, and then discuss how ASP can use the
Caching technology.

When you have a large amount of data (static, that is, less change) needs to be displayed to the client, you can consider using the server-side caching technology. This kind of technology is especially suitable for those websites with strong display style consistency (hehe, not easy to use for non-mainstream websites). )



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.