争怎路由网:是一个主要分享无线路由器安装设置经验的网站,汇总WiFi常见问题的解决方法。

ASP中CACHE技术

时间:2024/6/14作者:未知来源:争怎路由网人气:

我认为在ASP中最好的办法是用编程实现定时刷新Cache,也就是说给Application中储存的设一个过期时间。当然,在ASP中Application对象没有这样一个ExpireTime属性。这需要用程序实现。
 

Code

  • ASP:default.asp

    <%@Language=VBScript%>
    <%
    Option  Explicit%>
    <%Response.Buffer=
    True%>
    <!--#include file = "conn.asp"-->
    <!--#include file = "GetCache.asp"-->

    <HTML>
        <HEAD>

            <TITLE>ASP Cache演示</TITLE>
            <META
    HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
        </HEAD>
        <BODY>

        <h4>每隔10秒刷新Cache</h4>
        <%
        response.Flush
        GetHTMLStream
        response.Write
        HTMLStream
        %>

        </body>
    </html>

  • ASP:getcache.asp

    <%
    Const CACHE_DEFAULT_INTERVAL = 30 '每隔30秒刷新一次cache
    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"
    %>



关键词:ASP中CACHE技术




Copyright © 2012-2018 争怎路由网(http://www.zhengzen.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版