asp提高執行效率

來源:互聯網
上載者:User

<%
Function DisplayRecords()
    Dim sql, conn, rs
    sql = "select [id],[st],[nd] from [table]"
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("Database.mdb")
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql,conn,1,3

    If Not rs.EOF Then
      Dim temp
      temp = "<table width=""90%"" align=""center"""
      temp = temp & " border=""1""  bordercolor=""silver"""
      temp = temp & " cellspacing=""2"" cellpadding=""0"">"
      temp = temp & "<tr bgcolor=""#CCDDEE""><td width=""5%"""
      temp = temp & ">ID</td><td>操作</td>"
      temp = temp & "<td>數值</td></tr>"

    While Not rs.EOF
      temp = temp & "<tr><td bgcolor=""#CCDDEE"">"
      temp = temp & rs("ID") & "</td><td>" & rs("st")
      temp = temp & "</td><td>" & rs("nd")
      temp = temp & "</td></tr>"
      rs.MoveNext
    Wend
      temp = temp & "</table>"
      DisplayRecords = temp
    Else
      DisplayRecords = "Data Not Available."
    End If

    rs.Close
    conn.Close
    Set rs = Nothing
    Set conn = Nothing
End Function

'寫入緩衝
Function DisplayCachedRecords(Secs)
    Dim retVal, datVal, temp1
        retVal = Application("cache_demo")
        datVal = Application("cache_demo_date")

        If datVal = "" Then
        datVal = DateAdd("s",Secs,Now)
        End If

        temp1 = DateDiff("s", Now, datVal)

    If temp1 > 0 And retVal <> "" Then
        DisplayCachedRecords = retVal
        Response.Write "<b><font color=""green"">利用緩衝讀取資料"
        Response.Write " ... (" & temp1 & " 秒剩餘)</font></b>"
        Response.Write "<br><br>"
    Else

        Dim temp2
        temp2 = DisplayRecords()

        Application.Lock
        Application("cache_demo") = temp2
        Application("cache_demo_date") = DateAdd("s",Secs,Now)
        Application.UnLock

        DisplayCachedRecords = temp2

        Response.Write "<b><font color=""red"">重新整理緩衝顯示 ..."
        Response.Write "</font></b><br><br>"

    End If
End Function
%>
<html>
<head>
    <title>利用緩衝從資料庫---讀取資料</title>
    <style>
    body, p, td { font-family:"宋體"; font-size:12px; }
    td {padding: 5px; }
    </style>
</head>
<body>
<%
                Dim t1, t2
                t1 = Timer
                Response.Write DisplayCachedRecords(60)
                t2 = Timer
%>

<p align="center">
停留時間: <%= Left((CDbl((t2 - t1) * 1000.0)), 5) %> ms
</p>

</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.