1.服务器端缓存
ListBox=Application("ListBox")
If ListBox<>"" then
Response.Write "本次通过服务器缓存读取数据:<BR>"
End If
If ListBox="" then
Response.Write "本次为第一次读取数据,从数据库中读取:<BR>"
Response.Write "另外打开窗口读取或者刷新页面即可验证从服务器缓存中读取数据<BR>"
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Map("Book.mdb")
Conn.Open
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from book"
set rs=conn.Execute(sql)
ListBox="<select>"
'用一个循环把Recordset赋值给ListBox变量
Do Until rs.Eof
ListBox=ListBox & "<option>" & rs("book_press") & "</option>"
rs.MoveNext
Loop
rs.Close
Set rs=nothing
ListBox=ListBox & "</select>"
Application("ListBox")=ListBox
End If
Reponse.Write Application("ListBox")
用了简单的Application变量后,可以发现服务器上的请求数量会降低不少,这种方法尤其适合那些更新不是很频繁的网站
2.客户端缓存
客户端缓存技术也叫断开连接的ADO技术,主要用来保护用户的个人信息,密码,代号等,如在Global.asa中,添加如下代码
<script language="vbscript" runat="Server">
Sub Applicaion_OnStart()
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("user.mdb")
Conn.Open
Set rs=Server.CreateObject("ADODB.RecordSet")
sql="select username,password from userinfo"
rs.CursorLocation=3
rs.Open sql,Conn,3,1
set rs.ActiveConnection=Nothing
set Application("rs")=rs
End Sub
</script>
在User.Asp中,添加如下代码
set youruser=Application("rs").Clone
set yourname=yourusers("username")
set password=yourusers("password")
Do Until yourusers.Eof
Response.Write "您的姓名:" & username
Response.Write "您的密码:" & password
yourusers.MoveNext
loop