欢迎光临
我们一直在努力

蛙蛙推荐:asp中模拟.net中的cache-ASP教程,ASP应用

建站超值云服务器,限时71元/月

<!–

为了提高网站首页的性能,首页凡是需要调用数据库显示数据的地方都会先试图从缓存中调用数据,

如果缓存中没有可用数据再打开数据库取出记录集,为了让页面显示数据和数据库在一定时间内同步,

我们把缓存的过期时间设置成30秒.

声明:缓存管理类出自于动网论坛7.0

注意:最好不要在缓存里直接缓存带状态的对象和mta模式的对象,比如说直接缓存记录集或者数据库链接对象等.

–>

<%

sub showrsarr(rsarr)

2005-1-27 by 蛙蛙王子

用表格显示记录集getrows生成的数组的表结构

response.write "<table width=100% border=0 cellspacing=0 cellpadding=0>"

if not isempty(rsarr) then

for y=0 to ubound(rsarr,2)

response.write"<tr>"

for x=0 to ubound(rsarr,1)

response.write "<td>"&rsarr(x,y)&"</td>"

next

response.write"</tr>"

next

else

response.write "<tr>"

response.write "<td colspan="&rs.fields.count-1&">no records</td>"

response.write "</tr>"

end if

response.write "</table>"

end sub

class cls_cache

rem ==================使用说明=================================================================================

rem = 本类模块是动网先锋原创,作者:迷城浪子。如采用本类模块,请不要去掉这个说明。这段注释不会影响执行的速度。=

rem = 作用:缓存和缓存管理类 =

rem = 公有变量:reloadtime 过期时间(单位为分钟)缺省值为14400, =

rem = maxcount 缓存对象的最大值,超过则自动删除使用次数少的对象。缺省值为300 =

rem = cachename 缓存组的总名称,缺省值为"dvbbs",如果一个站点中有超过一个缓存组,则需要外部改变这个值。 =

rem = 属性:name 定义缓存对象名称,只写属性。 =

rem = 属性:value 读取和写入缓存数据。 =

rem = 函数:objisempty()判断当前缓存是否过期。 =

rem = 方法:delcahe(mycahename)手工删除一个缓存对象,参数是缓存对象的名称。 =

rem ===========================================================================================================

public reloadtime,maxcount,cachename

private localcachename,cachedata,delcount

private sub class_initialize()

reloadtime=14400

cachename="dvbbs"

end sub

private sub setcache(setname,newvalue)

application.lock

application(setname) = newvalue

application.unlock

end sub

private sub makeempty(setname)

application.lock

application(setname) = empty

application.unlock

end sub

public property let name(byval vnewvalue)

localcachename=lcase(vnewvalue)

end property

public property let value(byval vnewvalue)

if localcachename<>"" then

cachedata=application(cachename&"_"&localcachename)

if isarray(cachedata) then

cachedata(0)=vnewvalue

cachedata(1)=now()

else

redim cachedata(2)

cachedata(0)=vnewvalue

cachedata(1)=now()

end if

setcache cachename&"_"&localcachename,cachedata

else

err.raise vbobjecterror + 1, "dvbbscacheserver", " please change the cachename."

end if

end property

public property get value()

if localcachename<>"" then

cachedata=application(cachename&"_"&localcachename)

if isarray(cachedata) then

value=cachedata(0)

else

err.raise vbobjecterror + 1, "dvbbscacheserver", " the cachedata is empty."

end if

else

err.raise vbobjecterror + 1, "dvbbscacheserver", " please change the cachename."

end if

end property

public function objisempty()

objisempty=true

cachedata=application(cachename&"_"&localcachename)

if not isarray(cachedata) then exit function

if not isdate(cachedata(1)) then exit function

if datediff("s",cdate(cachedata(1)),now()) < 60*reloadtime then

objisempty=false

end if

end function

public sub delcahe(mycahename)

makeempty(cachename&"_"&mycahename)

end sub

end class

dim strconn,rs

strconn="driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;"

public function getemployees()

dim sql,rs,cache

set cache=new cls_cache

cache.reloadtime=0.5

cache.cachename="wawa"

cache.name="employees"

if cache.objisempty() then

set rs=server.createobject("adodb.recordset")

sql = "select employeeid, lastname, firstname from employees order by employeeid desc"

rs.open sql,strconn,1,1

cache.value = rs.getrows(5)

rs.close:set rs=nothing

end if

getemployees=cache.value

set cache=nothing

end function

showrsarr(getemployees)

%>

<script>

function timeout(a){

var c=a-1;

if(c==0) {

window.location.href=window.location;

}else{

document.all.abc.innerhtml="离缓存结束还有:"+c+"秒";

window.settimeout(timeout(+c+),1000);

}

}

</script>

<body onload="timeout(30)">

<div id="abc"></div>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 蛙蛙推荐:asp中模拟.net中的cache-ASP教程,ASP应用
分享到: 更多 (0)