先锋缓存类(极度加速ASP和提高执行效率)

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 applebbs 的 blog

clscache 公共属性 

引用内容:
 valid   返回是否有效。true表示有效,false表示无效。只读。 
 version  获取类的版本信息。只读。 
 value   返回缓存内容。只读。 
 name  设置缓存名称,写入。 
 expire  设置缓存过期时间,写入。 

 
 
clscache 公共方法 
引用内容:
 add(cache,expiretime)  对缓存赋值(缓存内容,过期时间) 
 clean()  清空缓存 
 verify(cache2)  比较缓存值是否相同——返回是或否。 

 
  
clscache 使用示例 
程序代码:
<!--#include file="clscache" -->
<%
dim content,mycache
set mycache=new cache
mycache.name="lkstar" '定义缓存名称 
if mycache.valid then '如果缓存有效
content=mycache.value '读取缓存内容
else
content="......" '大量内容,可以是非常耗时大量数据库查询记录集
mycache.add content,dateadd("n",1000,now) '将内容赋值给缓存,并设置缓存有效期是当前时间+1000分钟
end if 
set clscache=nothing '释放对象
%>


程序代码:
<% 
'-------------------------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'**************************   【先锋缓存类】ver2004  ********************************
'作者:孙立宇、apollosun、ezhonghua
'官方网站:http://www.lkstar.com   技术支持论坛:http://bbs.lkstar.com
'电子邮件:kickball@netease.com    在线qq:94294089
'版权声明:版权没有,盗版不究,源码公开,各种用途均可免费使用,欢迎你到技术论坛来寻求支持。
'目前的asp网站有越来越庞大的趋势,资源和速度成了瓶颈
'——利用服务器端缓存技术可以很好解决这方面的矛盾,大大加速asp运行和改善效率。
'本人潜心研究了各种算法,应该说,这个类是当前最快最纯净的缓存类。
'详细使用说明或范例请见下载附件或到本人官方站点下载!
'--------------------------------------------------------------------------------------
class clscache
'----------------------------
private cache           '缓存内容
private cachename       '缓存application名称
private expiretime      '缓存过期时间
private expiretimename  '缓存过期时间application名称
private path            '缓存页url路径

private sub class_initialize()
path=request.servervariables("url")
path=left(path,instrrev(path,"/"))
end sub
 
private sub class_terminate()
end sub

public property get version
 version="先锋缓存类 version 2004"
end property

public property get valid '读取缓存是否有效/属性
if isempty(cache) or (not isdate(expiretime)) then
vaild=false
else
valid=true
end if
end property

public property get value '读取当前缓存内容/属性
if isempty(cache) or (not isdate(expiretime)) then
value=null
elseif cdate(expiretime)<now then
value=null
else
value=cache
end if
end property

public property let name(str) '设置缓存名称/属性
cachename=str&path
cache=application(cachename)
expiretimename=str&"expire"&path
expiretime=application(expiretimename)
end property

public property let expire(tm) '设置缓存过期时间/属性
expiretime=tm
application.lock()
application(expiretimename)=expiretime
application.unlock()
end property

public sub add(varcache,varexpiretime) '对缓存赋值/方法
if isempty(varcache) or not isdate(varexpiretime) then
exit sub
end if
cache=varcache
expiretime=varexpiretime
application.lock
application(cachename)=cache
application(expiretimename)=expiretime
application.unlock
end sub

public sub clean() '释放缓存/方法
application.lock
application(cachename)=empty
application(expiretimename)=empty
application.unlock
cache=empty
expiretime=empty
end sub
 
public function verify(varcache2) '比较缓存值是否相同/方法——返回是或否
if typename(cache)<>typename(varcache2) then
 verify=false
elseif typename(cache)="object" then
 if cache is varcache2 then
  verify=true
 else
  verify=false
 end if
elseif typename(cache)="variant()" then
 if join(cache,"^")=join(varcache2,"^") then
  verify=true
 else
  verify=false
 end if
else
 if cache=varcache2 then
  verify=true
 else
  verify=false
 end if
end if
end function
%>

本文关键:先锋缓存类(极度加速ASP和提高执行效率)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top