ASP Cache Technology

Source: Internet
Author: User

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 .)
In fact, the implementation method is very simple. You just need to take a look at the following simple example to understand.
This is an example program used to display the category of books.
Displaybooks. asp file:
<% @ Language = JavaScript %>
<HTML>
<Body>
<Form method = post>
Book category; <% = getbookslistbox () %>
<P>
<Input type = submit>
 
<%
Function getbookslistbox ()
{
Bookslistbox = Application ("bookslistbox ")
If (bookslistbox! = NULL) return bookslistbox;
CRLF = string. fromcharcode (13, 10)
Bookslistbox = "<select name = books>" + CRLF;
SQL = "select * From books order by name ";
Cnnbooks = server. Createobject ("ADODB. Connection ");
Cnnbooks. Open ("books", "admin ","");
Rstbooks = cnnbooks. Execute (SQL );
Fldbookname = rstbooks ("bookname ");
While (! Rstbooks. EOF ){
Bookslistbox = bookslistbox + "<option>" +
Fldbookname + "" + CRLF;
Rstbooks. movenext ();
}
Bookslistbox = bookslistbox + ""
Application ("bookslistbox") = bookslistbox
Return bookslistbox;
}
%>
Actually, the simple application technology is used, and the difference is as follows:
Application ("bookslistbox") = bookslistbox
You can verify that the number of requests on the server will decrease a lot. This situation is especially suitable for websites that are not updated frequently. For example, you only update the content once a day (or for a long time.
Next we will discuss a client cache technology, which is also called the disconnected ADO connection technology (the translation level is too high and it sounds so awkward ). This technology is mainly used to save users' personal information, such as users' passwords and codes. It mainly uses some properties of ADO. At the same time, I also answered some questions about whether the ADO object can be used in the applocation. The explanation is unclear. Let the code speak below:
File global. Asa:
<! -- Metadata type = "typelib" file = "C:/program files/common files/system/ADO/msado15.dll" -->
<Script language = VBScript runat = "server">
Sub application_onstart
SQL = "select username, password from userinfo"
Cnnusers = "DSN = user"
Set rsusers = server. Createobject ("ADODB. recordset ")
'Note that the following two sentences are used to implement the available disconnection ADO technology.
Rscustomers. cursorlocation = aduseclient
Rscustomers. Open SQL, cnnadvworks, adopenstatic, adlockreadonly
'Disconnect the recordset from the database
Rscustomers. activeconnection = nothing
Set Application ("rscustomers") = rscustomers
End sub

File users. asp
<%
The 'clone method gives each user A recordset.
Set yourusers = Application ("rsusers"). Clone
Set username = yourusers ("username ")
Set Password = yourusers ("password ")
Do until yourusers. EOF
%>
User name: <% = username %> User Password: <% = PASSWORD %>
<%
Yourusers. movenext
Loop
%>

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.