最近写的一个asp缓存函数
作者:hayden 来源:烦恼's BLOG 时间:2008-11-25 14:07:00
关于asp缓存函数,类什么的,在网上可以说笔笔皆是,为啥我要不辞辛苦去写一个呢?
大概看了下,各有各的优点吧,可是大部分好像不可以缓存数据额,还得把数据用一定的符号相隔转成一个变量去缓存,取出来用的时候还要split转成数组,有些麻烦了,所以这就重写了一个,也给大家分享分享,有什么更好的想法,欢迎来“稿”!谢谢~
程序代码
<%
'***********************************************
'函数名:getcache
'作 用:将需要缓存的内容,置入缓存中,并读取出来,如果缓存中存在该内容,则直接从缓存读取!
'作 者: 静¢脉(hayden)
'时 间: 2007-12-21
'参 数:funsname ---- 需要缓存的内容
' isreset ---- 是否更新[值:0(根据时间或判断缓存为空时自动更新)、1(主动更新)]
' isarr ---- 所缓存的内容是否为一个数据[0为字符串,1为数组]
' timeinfo ---- 缓存更新时间,单位为秒,当值为0时,则只在缓存为空时,才更新
'返回值:缓存名为"funsname”的内容
'***********************************************
Function getcache(funsname,isreset,isarr,timeinfo)
dim domain : domain = "www.mysuc.com" '缓存域
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
%>
调用示例:
程序代码
<%
Function out_test1 '返回一个字符串的示例函数
out_test1="这里是一个字符串"
End Function
Function out_test2 '返回一个数组的示例函数
Dim temp_out_test2
temp_out_test2="这里.是.一个.数组"
out_test2=Split(temp_out_test2,".")
End Function
Dim i
'字符串缓存(将函数out_test1从缓存读取并输出)
Dim str2 : str2 = getcache("out_test1",0,0,180) '通过getcache函数读取缓存.刷新时间为180秒,(当out_test1缓存为空,会自动访问函数out_test1输出,并同时置入缓存~)
response.write str2
response.write "<BR><BR><BR>"
'数组缓存(将函数out_test2从缓存读取并输出)
Dim str1 : str1 = getcache("out_test2",0,1,180) '同上(字符串缓存说明)
For i = 0 To UBound(str1)
response.write str1(i) & "<BR>"
Next
%>
标签:缓存,函数,asp
0
投稿
猜你喜欢
FCKeditor编辑器基本配置优化修改使用方法
2008-12-31 13:32:00
ASP教程:自己写的数据库操作类
2008-11-21 17:29:00
用ASP创建多栏选项列表SELECT
2007-10-08 13:18:00
数据库自动化技术弥补数据库DBA短缺难题
2009-02-04 16:53:00
Iinternet Explorer浏览器简介(IE)
2009-02-05 20:59:00
合理设置内存让数据库与其他程序共存
2009-05-21 16:24:00
陌生网页交互行为分析(1)——奇怪的关闭按钮
2009-01-08 12:22:00
来看看如何防止采集
2007-08-19 20:11:00
再谈 Web 默认字体
2009-11-24 12:48:00
Linux操作系统下MySQL数据库的使用方法
2008-12-26 09:24:00
如何动态产生变量?
2009-11-18 16:33:00
也谈 CSS Sprites
2009-10-06 15:14:00
css网页下拉菜单制作方法(3):样式修饰
2007-02-03 11:39:00
清理你的CSS
2009-10-06 15:11:00
页面新开窗口的一点补充
2008-09-10 12:57:00
asp截取字符串的两种应用
2009-08-19 17:11:00
oracle 数据库连接分析
2009-07-28 10:42:00
Mobile Web下的编码设计
2010-01-28 10:42:00
详细介绍查询优化技术在现实系统中的运用
2009-01-04 13:34:00
再说淘宝的评价和信用机制
2008-07-10 12:43:00