最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ASP 3.0高级编程(四十三)
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
首先需要注意的是,数据高速缓存与记录集高速缓存虽然都用于改善性能,但两者是无关的。数据高速缓存是临时的数据存储区,允许使用高速缓存中的数据,而不是重新生成新的数据。这只适用于那些不经常改动但多次被访问的数据。
在ASP中一个最简单的缓存数据的方法是使用Application和Session范围的变量。例如,假设有一些需要选择书类型的网页。正常情况下,可能会创建一个含有以下函数的包含文件。
<%
Function BookTypes()
Dim rsBookTypes
Dim strQuote
strQuote = Chr(34)
Set rsBookTypes = Server.CreateObject ("ADODB.Recordset")
' Get the book types
rsBookTypes.Open "usp_BookTypes", strConn
Response.Write ""
rsBookTypes.Close
Set rsBookTypes = Nothing
End Function
%>
这仅仅是调用一个存储过程,从而得到书的类型,同时创建一个SELECT列表。上述代码的缺点在于每次调用该函数都必须访问数据库。因此,重新修改这个函数。
<%
Function BookTypes()
Dim rsBookTypes
Dim strQuote
Dim strList
' See if the list is in the cache
strList = Application("BookTypes")
If strList = "" Then
' Not cached, so build up list and cache it
strQuote = Chr(34)
Set rsBookTypes = Server.CreateObject ("ADODB.Recordset")
' Get the book types
rsBookTypes.Open "usp_BookTypes", strConn
strList = ""
rsBookTypes.Close
Set rsBookTypes = Nothing
' Check the list
Application("BookTypes") = strList
End If
-
上一个: ASP 3.0高级编程(四十五)
-
下一个: ASP 3.0高级编程(四十二)
相关文章
- ASP实现加法验证码方法 09-16
- ASP错误捕获的几种常规处理方法介绍 09-16
- asp中获取日期为星期几的技巧 09-14
- Asp编码优化参考 09-14
- .Net Core认证系统源码解析 12-26
- SharePoint Server 2019新特性介绍 01-15