• 实现ASP缓存技术


    1.服务器端缓存

        ListBox=Application("ListBox")

        If ListBox<>"" then

            Response.Write "本次通过服务器缓存读取数据:<BR>"

        End If

        If ListBox="" then

            Response.Write "本次为第一次读取数据,从数据库中读取:<BR>"

            Response.Write "另外打开窗口读取或者刷新页面即可验证从服务器缓存中读取数据<BR>"

            Set Conn=Server.CreateObject("ADODB.Connection")

            Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Map("Book.mdb")

            Conn.Open

            Set rs=Server.CreateObject("ADODB.Recordset")

            sql="select * from book"

            set rs=conn.Execute(sql)

            ListBox="<select>"

            '用一个循环把Recordset赋值给ListBox变量

            Do Until rs.Eof

                 ListBox=ListBox & "<option>" & rs("book_press") & "</option>"

                 rs.MoveNext

            Loop

            rs.Close

            Set rs=nothing

            ListBox=ListBox & "</select>"

            Application("ListBox")=ListBox

        End If    

        Reponse.Write Application("ListBox")

        用了简单的Application变量后,可以发现服务器上的请求数量会降低不少,这种方法尤其适合那些更新不是很频繁的网站

    2.客户端缓存

        客户端缓存技术也叫断开连接的ADO技术,主要用来保护用户的个人信息,密码,代号等,如在Global.asa中,添加如下代码

    <script language="vbscript" runat="Server">

        Sub Applicaion_OnStart()

            Set Conn=Server.CreateObject("ADODB.Connection")

            Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("user.mdb")

            Conn.Open

            Set rs=Server.CreateObject("ADODB.RecordSet")

            sql="select username,password from userinfo"

            rs.CursorLocation=3

            rs.Open sql,Conn,3,1

            set rs.ActiveConnection=Nothing

            set Application("rs")=rs

        End Sub

    </script>

    在User.Asp中,添加如下代码

    set youruser=Application("rs").Clone

    set yourname=yourusers("username")

    set password=yourusers("password")

    Do Until yourusers.Eof

        Response.Write "您的姓名:" & username

        Response.Write "您的密码:" & password

        yourusers.MoveNext

    loop

  • 相关阅读:
    PAT A1097 Deduplication on a Linked List (25 分)——链表
    PAT A1115 Counting Nodes in a BST (30 分)——二叉搜索树,层序遍历或者dfs
    PAT A1113 Integer Set Partition (25 分)——排序题
    PAT A1112 Stucked Keyboard (20 分)——字符串
    PAT A1118 Birds in Forest (25 分)——并查集
    JAVA入门之程序设计环境搭建
    Win7命令终端基础配色指南
    泛微e-cology和Oracle无法启动的解决方案
    C指针和数组
    float类型与16进制的相互转换
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035757.html
Copyright © 2020-2023  润新知