威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
ASP教程>> ASP基础 应用技巧 数据库相关 ASP类 存储过程 FSO专栏 ASP其他
当前位置:首页 > ASP教程 > ASP类
上一节 下一节
 捌度空间 缓存类
捌度空间 缓存类代码
代码如下:

<%
class cache
    private obj            'cache内容
    private expiretime        '过期时间
    private expiretimename    '过期时间application名
    private cachename        'cache内容application名
    private path            'url

    private sub class_initialize()
        path=request.servervariables("url")
        path=left(path,instrrev(path,"/"))
    end sub

    private sub class_terminate()
    end sub

    public property get blempty
        '是否为空
        if isempty(obj) then
            blempty=true
        else
            blempty=false
        end if
    end property

    public property get valid
        '是否可用(过期)
        if isempty(obj) or not isdate(expiretime) then
            valid=false
        elseif cdate(expiretime)<now then
                valid=false
        else
            valid=true
        end if
    end property

    public property let name(str)
        '设置cache名
        cachename=str & path
        obj=application(cachename)
        expiretimename=str & "expires" & path
        expiretime=application(expiretimename)
    end property

    public property let expires(tm)
        '重设置过期时间
        expiretime=tm
        application.lock
        application(expiretimename)=expiretime
        application.unlock
    end property

    public sub add(var,expire)
        '赋值
        if isempty(var) or not isdate(expire) then
            exit sub
        end if
        obj=var
        expiretime=expire
        application.lock
        application(cachename)=obj
        application(expiretimename)=expiretime
        application.unlock
    end sub

    public property get value
        '取值
        if isempty(obj) or not isdate(expiretime) then
            value=null
        elseif cdate(expiretime)<now then
            value=null
        else
            value=obj
        end if
    end property

    public sub makeempty()
        '释放application
        application.lock
        application(cachename)=empty
        application(expiretimename)=empty
        application.unlock
        obj=empty
        expiretime=empty
    end sub

    public function equal(var2)
        '比较
        if typename(obj)<>typename(var2) then
            equal=false
        elseif typename(obj)="object" then
            if obj is var2 then
                equal=true
            else
                equal=false
            end if
        elseif typename(obj)="variant()" then
            if join(obj,"^")=join(var2,"^") then
                equal=true
            else
                equal=false
            end if
        else
            if obj=var2 then
                equal=true
            else
                equal=false
            end if
        end if
    end function
end class
%>

使用方法:
代码如下:

    set mycache=new cache
    mycache.name="flash1"
    if mycache.valid then
        startget = mycache.value
    else
        startget = gethttppage(httpurl)    
        mycache.add startget,dateadd("h",3,now)
    end if 
    list=getbody(startget,"</form>","<!-- ********网页中部代码结束******** -->",false,false)

申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
ASP基础
应用技巧
数据库相关
ASP类
存储过程
FSO专栏
ASP其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821