先说明一下到底什么是ASP的缓存技术。 所谓缓存其实就是在内存中开辟一个用来保存数据的空间,使用缓存你就不用频繁的访问你保存在硬盘上的数据了,灵活的使用缓存你就免去了心疼的看着可怜的硬盘饱受读数据时的折磨了。当你一旦执行了一个查询动作,并且将查询结果放入缓存中后,你就可以很迅速的重复访问这些数据了。而如果你不把数据放入缓存的话,当你再次执行这个查询时,服务器会将进程耗费在从数据库中获取并排序上了。 当数据保存在缓存中时,再次查询时耗费的时间主要是在显示数据的时间上了。 也就是说,我们不应该把经常需要改变的数据放到服务端的缓存中,我们应该把改变少,但是又需要经常访问的数据放到缓存中。 下面是一个典型的ASP缓存类
Class clsCache ' 属性valid,是否可用,取值前判断 ' 属性value,返回cache内容 ' 属性name,cache名,新建对象后赋值 ' 方法add(值,到期时间),设置cache内容 ' 方法expire(tm),设置缓存过期时间为tm ' 方法clean() '释放缓存 ' 方法verify(变量1) '比较缓存值是否与‘变量1’相同——返回是或否 private cache private cacheNames private expireTime private expireTimeName private path private sub class_initialize() path=request.servervariables("url") path=left(path,instrRev(path,"/")) end sub private sub class_terminate() end sub public property get valid '读取缓存是否有效/属性 if isempty(cache) or (not isdate(expireTime) or CDate(expireTime)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 ENd Class