当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp自带的内存缓存 application

ASP
ASP技巧:在Access数据库中重命名表
用ASP编程实现网络内容快速查找
比较ASP生成静态HTML文件的几种方法
ASP实例:实现邮件发送普通附件和嵌入附件
如何用ASP实现去掉三个最高分和三个最低分
ASP实例:Access为后台数据库的网站统计系统
用标签替换的方法生成静态网页
例程:用ASP判断文件地址是否有效
学ASp动态网页必备:常用的38个函数
ASP教程:初次接触学习ASP脚本程序
ASPJPEG水印中关于文字水印的帮助文档(中英文对照)
ASP例子:ASP把汉字转化为拼音的函数
ASP教程:学习ASP应用Cookies的技巧
ASP入门:认识ASP程序所使用的几种脚本语言
初学者的ASP教程:常用ASP内置函数
ASP初级教程之ASP对表单和用户输入的处理
学习ASP文件引用的方法
用ASP编写更人性化的弹出窗口程序
谈谈学习ASP动态网页制作技术的编程心得
用ASP程序实现网站在线人数统计

ASP 中的 asp自带的内存缓存 application


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 120 ::
收藏到网摘: n/a

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

使用时:
复制代码 代码如下:

Function output3
output3=”"
set newrs=conn.execute(”select TOP 60 companyname,comid,vipdata,ishot from company where isok=1 and vipqx>60 and vipqx<300 and vip=1 and comid in (select comid from jobs where zt<>1) order by newid()”)
do while not newrs.eof
output3=output3 & “……….”
newrs.movenext
loop
newrs.close
set newrs=nothing
End function
response.write getcache(”output3″,0,0,3600)