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

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

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

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

GQf中国设计秀
调用示例:GQf中国设计秀
 程序代码GQf中国设计秀
<%GQf中国设计秀
Function out_test1    '返回一个字符串的示例函数GQf中国设计秀
    out_test1="这里是一个字符串"GQf中国设计秀
End FunctionGQf中国设计秀

Function out_test2    '返回一个数组的示例函数GQf中国设计秀
    Dim temp_out_test2GQf中国设计秀
    temp_out_test2="这里.是.一个.数组"GQf中国设计秀
    out_test2=Split(temp_out_test2,".")GQf中国设计秀
End FunctionGQf中国设计秀

Dim iGQf中国设计秀

'字符串缓存(将函数out_test1从缓存读取并输出)GQf中国设计秀
Dim str2 : str2 = getcache("out_test1",0,0,180)    '通过getcache函数读取缓存.刷新时间为180秒,(当out_test1缓存为空,会自动访问函数out_test1输出,并同时置入缓存~)GQf中国设计秀
response.write str2GQf中国设计秀

response.write "<BR><BR><BR>"GQf中国设计秀

'数组缓存(将函数out_test2从缓存读取并输出)GQf中国设计秀
Dim str1 : str1 = getcache("out_test2",0,1,180)  '同上(字符串缓存说明)GQf中国设计秀
For i = 0 To UBound(str1)GQf中国设计秀
    response.write str1(i) & "<BR>"GQf中国设计秀
NextGQf中国设计秀
%>GQf中国设计秀

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