论坛风格切换
您好,欢迎光临本站!   登录 注册新用户
  • 2394阅读
  • 1回复

[asp]asp自带的内存缓存 application [复制链接]

上一主题 下一主题
 

发帖
16250
黑豆
-2
威望
45224
贡献值
2
交易币
0
红豆
0
只看楼主 倒序阅读 0 发表于: 2013-11-24
asp强大的application 是 php 中所没有的。昨天朋友抱怨他的人才网站读取速度慢,于是我帮他把asp中读库比较费时的部分用application做了缓存。

函数getcache,会自动建立需要的缓存。

复制代码代码如下:

Function getcache(funsname,isreset,isarr,timeinfo)
‘funsname — 需要缓存的内容,这里要输入一个function名
‘isreset –是否更新[值:0(根据时间或判断缓存为空时自动更新)、1(主动更新)]
‘ isarr —- 所缓存的内容是否为一个数据[0为字符串,1为数组]
‘ timeinfo —- 缓存更新时间,单位为秒,当值为0时,则只在缓存为空时,才更新
dim domain = “cnzhaopin.com.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


快速回复
限100 字节
 
上一个 下一个