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

ASP教程:applicaton对象的使用集合,第1张

ASP教程:applicaton对象的使用集合,第2张

<%
  ’’下面的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="

    "
      for i=1 to 10
      temp = temp&"
  •   boardID="&rs("Boardid")&"&ID="&rs
      ("topicid")&"&page=1"">"&rs("Title")&"("&rs("PostUserName")
      &")
  • "
      ’’这个地方各有所好了,显然和一个用table,td,tr,tbody来写前台的人合作,是一件很痛苦的事情.
      rs.MoveNext
      i=i+1
      next
      temp = temp & "
"
  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!

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » ASP教程:applicaton对象的使用集合

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情