ASP中Cache技术的应用(2)


  Dim HTMLStream
  Dim IsExpires
  IsExpires = CacheExpires
  Function CacheExpires
  Dim strLastUpdate
  Dim result strLastUpdate = Application("LastUpdate")
  If (strLastUpdate = "") Or (CACHE_DEFAULT_INTERVAL < DateDiff("s", strLastUpdate, Now)) Then
  result = true
  SetLastUpdateTime
  Else
  result = false
  End If
  CacheExpires = result
  End Function

Sub SetLastUpdateTime
  Application.Lock
  Application("LastUpdate") = CStr(now())
  Application.UnLock
  End Sub

  Sub GetHTMLStream
  If IsExpires Then
  UpdateHTMLStream
  End If
  HTMLStream=Application("CACHE_HTMLStream")
  End Sub

  Sub UpdateHTMLStream
  dim d
  d = FetchHTMLStream
  Application.Lock
  Application("CACHE_HTMLStream") = d
  Application.UnLock
  End Sub

  Function FetchHTMLStream
  Dim rs ,strSQL, strHTML
  Set rs = CreateObject("ADODB.Recordset")
  strSQL = "select categoryID , categoryname from categories"
  rs.Open strSQL, strConn,adOpenForwardOnly,adLockReadOnly
  strHTML = strHTML & "<select name=""slt_search"">"
  while (not rs.EOF)
  strHTML = strHTML & "<option>"
  strHTML = strHTML & rs.Fields("categoryname")
  strHTML = strHTML & "</option>" rs.MoveNext
  wend
  strHTML = strHTML & "</select>"
  rs.Close
  Set rs = Nothing
  FetchHTMLStream = strHTML
  End Function
  %>

 

  ASP:conn.asp

<!--METADATA NAME="Microsoft ActiveX Data Objects 2.5 Library" TYPE="TypeLib" UUID="{00000205-0000-0010-8000-00AA006D2EA4}"-->
  <%
  dim strConn
  strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind"
  %>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3687.html