最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASP缓存类含调用演示技巧

日期:10-10    来源:中国设计秀    作者:cnwebshow.com

程序代码du3中国设计秀
<%du3中国设计秀
    'by xilou,www.chinacms.org,20090115du3中国设计秀
    '最后更新:20090115du3中国设计秀
    '修改记录:无du3中国设计秀
    du3中国设计秀
    CONST CACHEPREFIX = "CACHE_" '缓存前缀,不能为空du3中国设计秀

    '说明:du3中国设计秀
    '        1,缓存的格式为application(CACHEPREFIX & key) = array("缓存key","缓存时间","缓存内容","缓存说明","到期时间")du3中国设计秀
    '          2,缓存key不区分大小写du3中国设计秀
    du3中国设计秀
    du3中国设计秀
    du3中国设计秀
    '添加缓存,不检查缓存是否存在,如果存在则相当于更新缓存du3中国设计秀
    'varAry :  参数,格式为:array("缓存key","缓存时间","缓存内容","缓存说明")du3中国设计秀
    '           缓存key :application()格式相同du3中国设计秀
    '           缓存时间:单位秒,可以为负数,表示立即过期,可以为空,空或不是数字则默认为20分钟过期du3中国设计秀
    '          缓存内容:缓存数据,不支持对对象的缓存du3中国设计秀
    '           缓存说明:缓存描述说明du3中国设计秀
    Function AddCache(varAry)du3中国设计秀
        Dim c,ary(4)du3中国设计秀
        If Not IsArray(varAry) Thendu3中国设计秀
            Response.Write "Error:AddCache(varAry)参数错误,参数不是数组"du3中国设计秀
            Response.End()du3中国设计秀
        End Ifdu3中国设计秀
        If UBound(varAry) <> 3 Thendu3中国设计秀
            Response.Write "Error:AddCache(varAry)参数错误,数组长度错误"du3中国设计秀
            Response.End()du3中国设计秀
        End Ifdu3中国设计秀
        If varAry(0) = "" Thendu3中国设计秀
            Response.Write "Error:AddCache(varAry)错误,key不能为空"du3中国设计秀
            Response.End()du3中国设计秀
        End Ifdu3中国设计秀
        If varAry(1) = "" or Not IsNumeric(varAry(1)) Then varAry(1) = 1200du3中国设计秀
        Application.Lock()du3中国设计秀
        Application(CACHEPREFIX & varAry(0)) = array(varAry(0),varAry(1),varAry(2),varAry(3),DateAdd("s",varAry(1),Now()))du3中国设计秀
        Application.UnLock()du3中国设计秀
    End Functiondu3中国设计秀
    du3中国设计秀
    '检查某个缓存是否存在,存在返回True否则返回Falsedu3中国设计秀
    'key : 缓存keydu3中国设计秀
    Function CheckCache(key)du3中国设计秀
        Dim kdu3中国设计秀
        For Each k In Application.Contentsdu3中国设计秀
            If LCase(k) = LCase(CACHEPREFIX & key) Then CheckCache = True : Exit Functiondu3中国设计秀
        Nextdu3中国设计秀
        CheckCache = Falsedu3中国设计秀
    End Functiondu3中国设计秀
    du3中国设计秀
    '获取缓存du3中国设计秀
    '返回数组,格式为:array("缓存key","缓存时间","缓存内容","缓存说明","到期时间",是否过期True|False)du3中国设计秀
    '如果不存在则出错,所以获取之前先用CheckCache(key)检查du3中国设计秀
    Function GetCache(key)du3中国设计秀
        Dim app,isExpdu3中国设计秀
        app = Application(CACHEPREFIX & key)du3中国设计秀
        isExp = Falsedu3中国设计秀
        If DateDiff("s",Now(),app(4)) <= 0 Then isExp = Truedu3中国设计秀
        GetCache = Array(app(0),app(1),app(2),app(3),app(4),isExp)du3中国设计秀
    End Functiondu3中国设计秀
    du3中国设计秀
    '清除缓存du3中国设计秀
    Function RemoveCache(key)du3中国设计秀
        Application.Lock()du3中国设计秀
        Application.Contents.Remove(CACHEPREFIX & key)du3中国设计秀
        Application.UnLock()du3中国设计秀
    End Functiondu3中国设计秀
    du3中国设计秀
    '更新缓存,如果缓存不存在则出错,所以更新之前先用CheckCache(key)检查du3中国设计秀
    'varAry :  参数,格式为:array("缓存key","缓存时间","缓存内容","缓存说明")du3中国设计秀
    '           缓存key :application()格式相同du3中国设计秀
    '           缓存时间:单位秒,可以为负数,表示立即过期,可以为空,空或不是数字则默认为20分钟过期du3中国设计秀
    '          缓存内容:缓存数据,不支持对对象的缓存du3中国设计秀
    '           缓存说明:缓存描述说明du3中国设计秀
    '注意   : 如果不更新varAry某个值则设置该值为null即可,du3中国设计秀
    '           如UpdateCache(array("key",null,"内容",null)),就是不更新过期时间和说明du3中国设计秀
    Function UpdateCache(varAry)du3中国设计秀
        Dim appdu3中国设计秀
        app = GetCache(varAry(0))du3中国设计秀
        If Not IsNull(varAry(1)) Then app(1) = varAry(1)du3中国设计秀
        If Not IsNull(varAry(2)) Then app(2) = varAry(2)du3中国设计秀
        If Not IsNull(varAry(3)) Then app(3) = varAry(3)du3中国设计秀
        If app(1) = "" or Not IsNumeric(app(1)) Then app(1) = 1200du3中国设计秀
        Application.Lock()du3中国设计秀
        Application(CACHEPREFIX & app(0)) = array(app(0),app(1),app(2),app(3),DateAdd("s",app(1),Now()))du3中国设计秀
        Application.UnLock()du3中国设计秀
    End Functiondu3中国设计秀
    'www.knowsky.comdu3中国设计秀
    '打印cache,做调试用du3中国设计秀
    Function PrintCache(key)du3中国设计秀
        Dim app,i,tdu3中国设计秀
        If CheckCache(key) Thendu3中国设计秀
            app = GetCache(key)du3中国设计秀
            Response.Write "<pre>{"&chr(10)du3中国设计秀
            Response.Write chr(32) & "缓存名称" & chr(32) & ":" & chr(32) & CACHEPREFIX & app(0) & chr(10)du3中国设计秀
            Response.Write chr(32) & "缓存key " & chr(32) & ":" & chr(32) & app(0) & chr(10)du3中国设计秀
            Response.Write chr(32) & "缓存时间" & chr(32) & ":" & chr(32) & app(1) & chr(10)du3中国设计秀
            Response.Write chr(32) & "到期时间" & chr(32) & ":" & chr(32) & app(4) & chr(10)du3中国设计秀
            Response.Write chr(32) & "是否到期" & chr(32) & ":" & chr(32) & app(5) & chr(10)du3中国设计秀
            Response.Write chr(32) & "缓存说明" & chr(32) & ":" & chr(32) & app(3) & chr(10)du3中国设计秀
            '内容du3中国设计秀
            Response.Write chr(32) & "缓存内容" & chr(32) & ":" & chr(32) du3中国设计秀
            t = VarType(app(2))du3中国设计秀
            If InStr(",0,1,2,3,4,5,6,7,8,11,",","&t&",") > 0 Thendu3中国设计秀
                Response.Write app(2)du3中国设计秀
            Elsedu3中国设计秀
                Response.Write TypeName(app(2))du3中国设计秀
            End Ifdu3中国设计秀
            Response.Write chr(10)du3中国设计秀
            du3中国设计秀
            Response.Write "}</pre>"&chr(10)du3中国设计秀
        Elsedu3中国设计秀
            Response.Write "不存在该缓存"du3中国设计秀
        End Ifdu3中国设计秀
    End Functiondu3中国设计秀
    du3中国设计秀
    du3中国设计秀
   '-----------demodu3中国设计秀

    Sub br(str)du3中国设计秀
        Response.Write str & "<br />" & vbcrlfdu3中国设计秀
    End Subdu3中国设计秀
    du3中国设计秀
    'RemoveCache "xilou"du3中国设计秀
    'AddCache Array("xilou","",array("数据内容"),"缓存说明")du3中国设计秀
    br CheckCache("xilou")du3中国设计秀
    PrintCache "xilou"du3中国设计秀
    du3中国设计秀
    Dim appdu3中国设计秀
    If CheckCache("xilou") Thendu3中国设计秀
        app = GetCache("xilou") '获取du3中国设计秀
        UpdateCache array(app(0),null,"testsfsfsf",null)'更新du3中国设计秀
    Elsedu3中国设计秀
        AddCache array("xilou","","内容","说明") du3中国设计秀
    End Ifdu3中国设计秀
    'Dim kdu3中国设计秀
    'For Each k In Application.Contentsdu3中国设计秀
        'br kdu3中国设计秀
    'Nextdu3中国设计秀
%>du3中国设计秀

本文引用地址:/bc/article_46249.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明