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

ASP
asp 网站静态化函数代码html
asp利用Split函数进行多关键字检索
ASP动态include文件
用ASP开发网页需要牢记的注意事项
利用ASP发送和接收XML数据的处理方法
Session对象失效的客户端解决方法
一次性下载远程页面上的所有内容
asp模板引擎终结者(WEB开发之ASP模式)
浅谈 ASP 模板技术之参数传递
本人常用的分页代码
也谈采集入库的技术
简单分页函数一 常用
msxml3.dll 错误 ''800c0005''解决方案
[原创]本人常用的asp代码
生成所有页面的效果+分页生成
[原创]关于Script的Defer属性
[原创]asp截取字符串的两种应用
内容分页函数
[ASP]精华代码
asp提高首页性能的一个技巧

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 38 ::
收藏到网摘: 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!