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

ASP
asp查询xml的代码 不刷新页面查询的方法
ASP 快速执行动态网页
asp实现本周的一周时间列表的代码
asp get和post数据接收过滤
为google量身定做的sitemap生成代码asp版
适合所有网站的rss和xml聚合功能asp代码
ASP MSSQL存储过程的实现小例
动网论坛的asp 数据库连接代码
ASP+MSSQL2000 数据库被批量注入后的解决方法
asp 去掉html中的table正则代码函数
asp 过滤非法字符函数
asp检测是否为中文字符函数
ASP 包含文件中的路径问题和使用单一数据库连接文件的解决方案
asp HTTP 500错误 常见问题分析
asp 关键词高亮显示(不区分大小写)
一段ASP的HTTP_REFERER判断代码
asp datediff 时间相减
asp下去除超链接的函数
asp连接mssql2005的代码
asp access数据库并生成XML文件范例

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


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