一个asp缓存函数,支持字符串和数组

商帝国咨询头像

阅读 9736 | 分类:文章

<%
'***********************************************
'函数名:getcache
'作 用:将需要缓存的内容,置入缓存中,并读取出来,如果缓存中存在该内容,则直接从缓存读取!
'作 者: 静¢脉(hayden)
'时 间: 2007-12-21
'参 数:funsname ----    需要缓存的内容
'       isreset ---- 是否更新[值:0(根据时间或判断缓存为空时自动更新)、1(主动更新)]
'       isarr ---- 所缓存的内容是否为一个数据[0为字符串,1为数组]
'       timeinfo   ---- 缓存更新时间,单位为秒,当值为0时,则只在缓存为空时,才更新
'返回值:缓存名为"funsname”的内容
'***********************************************
Function getcache(funsname,isreset,isarr,timeinfo)
    dim domain = "myhhe.cn"    '缓存域
    Dim temp_getconfig
    Dim re_getcache : re_getcache = False
    Dim temp_isarray_type : temp_isarray_type = False
    Dim Appfunsname : Appfunsname = Replace(Replace(Replace(funsname,"(",""),")",""),",",".")
    If isarr = 1 Then temp_isarray_type = True
    If isreset = 1 Then re_getcache = True
    If isreset = 2 Then
        execute("temp_getconfig="&funsname)
        getcache = temp_getconfig
        Exit Function
    End If
    If Application(domain&"_"&Appfunsname&"_time") = "" And timeinfo<>0 Then re_getcache = True
    If Not re_getcache Then
        If temp_isarray_type Then
         If Not IsArray(Application(domain&"_"&Appfunsname)) Then re_getcache = True
        Else
            If Application(domain&"_"&Appfunsname) = "" Then re_getcache = True
        End If
    End If
    If Not re_getcache And timeinfo<>0 Then
        If Int(DateDiff("s",Application(domain&"_"&Appfunsname&"_time"),now()))>timeinfo Then re_getcache = True
    End If
    If re_getcache Then
        execute("temp_getconfig="&funsname)
        Application.Lock
        Application(domain&"_"&Appfunsname) = temp_getconfig
        Application(domain&"_"&Appfunsname&"_time") = Now()
        Application.UnLock
    Else
        temp_getconfig=Application(domain&"_"&Appfunsname)
    End If
    getcache = temp_getconfig
End Function
%>

留言区(共0条)

暂无留言,快来抢占沙发~
作者声明:非原创
平台声明:文章及评论仅代表作者本人观点,五略商书系信息发布平台,仅提供信息存储空间服务,如有侵权,请联系13521509118。转载请注明作者和出处:转自五略商书m.shangdiguo.com,作者商帝国咨询!