当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP教程:applicaton对象的使用集合

ASP
Microsoft 脚本编码器(3) --- 使用脚本编码器
WAP中的ASP技术(一)
WAP中的ASP技术(二)
WAP中的ASP技术(三)
WAP中的ASP技术(四)
在ADO使用SELECT语法一
在ADO使用SELECT语法二
在ADO使用SELECT语法三
在ADO使用SELECT语法四
在ADO使用SELECT语法五
在ADO使用SELECT语法六
Asp+语法介绍(六)----数据库篇
vbscript错误代码及对应解释大全
ASP系列讲座(三)创建 ASP 页
ASP系列讲座(四)使用脚本语言
ASP系列讲座(五)使用变量和常量
ASP系列讲座(六)编写过程
ASP系列讲座(七)使用组件和对象
ASP系列讲座(八)使用集合
ASP系列讲座(九)设置对象作用域

ASP教程:applicaton对象的使用集合


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 220 ::
收藏到网摘: n/a

如果您不了解application对象的基本特征,可以查看本站的对象参考部分。
<%
''下面的function用来从动网论坛数据库中提出数据更新缓存 很简单的 提出最新发表的十个帖子
function refreshrecords()
Dim sql, conn, rs
sql = "select top 10 * FROM Dv_Topic order by DateAndTime desc"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("dv.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn, 1, 1

If Not rs.EOF Then
Dim temp
temp="<ul>"
for i=1 to 10
temp = temp&"<li><a href=""http:*/bbs.sfte.net/dispbbs.asp?
boardID="&rs("Boardid")&"&ID="&rs
("topicid")&"&page=1"">"&rs("Title")&"("&rs("PostUserName")
&")</a></li>"
''这个地方各有所好了,显然和一个用table,td,tr,tbody来写前台的人合作,是一件很痛苦的事情.
rs.MoveNext
i=i+1
next
temp = temp & "</ul>"
refreshrecords = temp
Else
refreshrecords = "数据调用失败."
End If
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Function

''下面的function则是用来更新缓存的
function displayrecords(secs)

if Application("cache")="" or isempty(Application("cache")) then '''' 程序第一次运行时候更新缓存
''''application("cache")用来保存我们需要缓存在内存中的内容
''''application("cache_time")用来保留缓存上次更新的时间
''''我们只在两种情况下是需要调用refresh函数来访问数据库来更新缓存
''''第一种就是服务器重启 或者其他意外导致application存储的值丢失
Application.Lock
Application("cache_date")=now()
''更新缓存时间
Application("cache") = refreshrecords()
''更新缓存内容
''codeby niceidea 签名
Application.UnLock
end if

if DateDiff("s", Application("cache_date"),Now)> secs then ''比较上次更新时间与当前时间的差值
''''另外一种需要更新缓存的情况就是缓存到期 所谓缓存就是保留一定时间的数据 定期更新恐怕是最常见的
Application.Lock
Application("cache_date")=now()
Application("cache") = refreshrecords()
Application.UnLock
end if
Response.Write Application("cache")
End Function
%>


最后 调用的方法是
<%displayrecords(300)%>
300表示5分钟更新一次 60×5=300!