ASP cache (Summary of ASP Cache Technology)

Source: Internet
Author: User

ASP cache (Summary of ASP Cache Technology)

I. What is ASP Cache/why cache?

At the early stage of your Web site's establishment using ASP technology, you may feel the convenience brought by ASP dynamic web page technology, as well as random modification and easy HTTP control. However, as the number of visits increases, you will surely find that your site access is getting slower and slower, and IIS restarts more and more frequently. Next, you must optimize ASP, such as replacing databases with better performance, creating indexes, and writing stored procedures. Some of these measures do not need to increase the cost pressure, and some are very costly (for example, the combination of access to SQL), and the effect is not certain.

In the face of the Web Access pressure, I think the most economical way is to use the Cache Optimization Technology to relieve the Web service pressure.

The increase in Web access usually means the rapid growth of the following resource demands:

1. Nic traffic increases and more CPU needs to be consumed to process network traffic and network I/O threads.

2. You need to enable or disable database connections more frequently (if you use database technology-Asp usually uses databases as data storage ), the number of things that consume resources heavily, as well as deadlocks caused by competing resources, will increase network I/O or CPU consumption.

3. If session is used, IIS will consume more memory to maintain the status, and memory consumption may lead to insufficient physical memory, resulting in frequent exchanges between the physical memory and the secondary memory, this causes code execution pauses and web response blocking.

4. If the access fails to respond in a timely manner, webpage access failures may occur, which may cause users to refresh the page, increasing CPU, memory, and other resource requirements.
In fact, considering common web applications, dynamic code execution is not necessary in many cases.

Ii. asp cache Classification

Summary without authorization, ASP cache can be divided into two types:

1. File Cache
The so-called File Cache is based on the logic judgment, the specific execution of an ASP will not change a lot in a period of time, so the content will be stored in the form of static html, then, the Web redirection technology is used to allow the client to access static files to reduce CPU and database resources. There are many such applications. For example, many forums re-generate a static file and redirect the whole post when replying to the post, such as the donews.com forum. There is also a side effect (Benefit) for static data-it can be easily indexed by Google and other search engines. Some so-called news publishing systems use this technology.

2. File segment Cache
The so-called File Cache is also based on logical judgment. Some data (usually obtained through a large-capacity database query that consumes resources) will not change for a certain period of time, therefore, we can store the data in the form of files. When necessary, we can read the file to obtain the data to avoid increasing the burden on the database. For example, we usually store some data in XML format, and then use XSLT Technology for display (XML processing usually requires a lot of CPU resources, therefore, ie directly reads XML and processes it on the client's CPU ). This is how csdn forums handle this problem.

3. Primary storage cache
In addition, you can also consider processing the cache in the memory to store the content that requires timely response in the memory. Once the access needs are met, the content is immediately transferred from the quick storage. If a large number of access requests are concentrated on a few small numbers of pages or a large number of primary storages, I think using the primary cache will definitely improve the web access performance.

Iii. How to Implement/use Cache

To implement caching, consider the following:

1. Which pages will not change in a short time?
Analysis of your site, there are many such pages. For example, a website usually has news topics, which are usually published by site maintenance personnel at a certain time of the day and rarely changed pages. These pages are suitable for static file caching. In fact, the so-called news publishing system is doing this, you can also refer to the ideas of these systems to transform their original dynamic ASP pages.

2. Those pages are generated using the same logic for all visitors (that is, they do not differentiate visitors ).
In addition to viewing an interface for all visitors in news and information topics, forums and other resource-consuming applications can also be designed to generate a unified logic (the same post is the same as that of Zhang sanli and Si ), static cache can also be used for such application pages. You can also consider data fragmentation and use script technology to process data in a client browser beyond the server's processing capabilities.

3. the cost and benefits of using the cache.
It mainly refers to "Space Change (response) Time ". Cache technology is used to pre-process frequently-needed content to improve the web server's response capability and win the hearts of visitors.
The cost is that the demand for web space increases and the access effect may be affected.
However, I think proper caching is a good advantage over disadvantage.

4. cache is not suitable for those places
On the dynamic query page, each person's query content is different and the displayed results are not the same. Therefore, it is unlikely that the query results will be generated as a cache. The cache is complicated and the cache utilization is low, what causes management costs (assuming that you cache 1000 query keywords, managing these keywords is also troublesome for the cache ).

 

Iv. instance analysis

Assume that the original layout of a suggested forum is as follows:

Under the root directory:
Default. asp homepage, which is generally excellent and recommended

Listborad. asp: This file lists the names and descriptions of all columns. If the mainbid parameter is included, the columns under the section are to be listed.

Listthread. asp: if this file does not contain any parameters, it indicates listing all the posts and mainbid indicates listing all the posts of a block. If subbid is included, it indicates listing the posts of a specific topic. If the page parameter is included, the topic is listed by page.

Viewthread. asp lists the content of a post. Let's assume that the post is displayed as a speech, and any post is listed below. The ID parameter is the post to be displayed.

Reply. asp responds to a post and carries the parameter ID to respond to a post.

The rest will not be discussed for the moment.

As shown in the preceding figure, if all ASP/PHP files are used, database operations, frequent queries, and multi-table queries are required to execute almost every ASP file. You need to know that querying a database will eventually result in a decline in performance and a decrease in response speed, which will affect slow browsing of visitors, which is not conducive to the quality of the web. More importantly, for both parties, they access viewthread. if the IDs of ASP and others are consistent, they will often see the same content (their browsers receive almost the same HTML code), but for this "same content ", the server needs to open the database link, query, read the record, display, close the record, database link .... The following table lists the operations that consume server resources. If more people access the server, the final result is that these users consume more server resources. In fact, the repetitive work for "the same content" can be avoided by using the Cache Technology for optimization. For example:
After the reply.asp, we can use the static function to store the whole body as a static html file such as viewthread_xxxx.htm, and then access viewthread. asp normally? When id1_xxxx, the system automatically redirectto the corresponding static file viewthreadxxxx.htm. In this way, when a post is not newly released, it is always static content provided to the viewer. Once a new submission is made, it will be updated to the static file. In this way, this will save many database operations and greatly increase the response speed.

Listborad. asp can also be static. . Similar to listthread. asp, there are many cached files because there are more parameters. Click to cache listthread. asp? Subbid1_xxx&page=2. The corresponding static file is listthread_xxx_p2.htm. The same applies to default. asp.

So how to determine when to update? At what time?
Discuss listthread. asp? If the object does not exist, call the static generation function to generate the object and redirect it to the static object. Note: If the content does not exist, it means that new content needs to be updated.

How can this cause the file to not exist? Delete. We can delete all static files such as listthread_xxx_p2.htm when we delete a new table post and move it. This notifies you when to cache the data.

How to generate static files?

We noticed that we mentioned "the same content ". We can copy a copy of the default. asp, listthread. asp, and so on before the transformation, named default_d.asp, listthread_2.asp, and in the same directory (theoretically listthtrad. asp? Subid = 123 same as listthread_d.asp? Subid = 123 the access result will be the same). In this way, in the logic of generating static files, we call the copy before transformation through the Web access request to obtain the HTML code, and stored as static files. This Web request is actually equivalent to viewing the HTML that will be output by the server itself before any real viewer accesses static content, and then returning the code to store it as a static file using the file operation function. In this way, the cached file is created before the real viewer.

Such a solution hardly touched the original layout, and hardly caused errors such as 404 during the transformation. Second, static files will also help your site to be easily indexed by Google and other search engines. Why not?

Finally, I would like to remind you that in Web access and ASP programming environments, many people use XMLHTTP components for access, which may cause many problems. XMLHTTP itself caches the requested resources, causing the contents requested by this component to be not up-to-date, resulting in logical confusion. Therefore, you should select an XML server HTTP object or a WinHTTP component to implement web request resources.

Using the Cache Technology in ASP can greatly improve the performance of your website. In fact, these implementation methods are very simple, it will show you how the cache on the server works and how you use an ADO connection technology called disconnected.

Before introducing these technologies, describe what ASP cache technology is.
The so-called cache is actually to open up a space in the memory to store data. Using the cache, you don't need to frequently access the data you saved on the hard disk, flexible use of the cache saves you the trouble of reading data from poor hard disks. Once you execute a query action and put the query results into the cache, you can quickly repeat the data. If you do not put the data into the cache, When you execute this query again, the server will consume the process to obtain and sort it from the database.
 
When the data is stored in the cache, the time consumed for re-query is mainly about the data display time.

That is to say, we should not put the data that often needs to be changed into the server cache. We should put the data that needs to be accessed frequently in the cache.

Now we will first discuss the technology for ASP to use caching on the server, and then discuss how ASP can be used on the client.
Cache Technology.

When you need to display a large amount of data (static, that is, less changed) to the client, you can consider using the server cache technology. This technology is especially suitable for websites with strong display style consistency (haha, it is not useful for non-mainstream websites .)

 

 

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.