asp缓存类

时间:2021-05-28

至于缓存的作用,我想我也不用再多说了,它的作用已经很明显,特别是对于信息量非常大或是全数据库页面的网站,他能很好地利用主机的内存资源,加速ASP的执行效率,减轻服务器的负担,而动网在这一方面做得是最突出的,像他现在的dvbbs7.1.0版,更是在缓存的利用上更上一层楼,前后台大多的操作都和缓存有关,而现在动网里用的也就是迷城浪子的缓存类,下面列出动网的三大高手写的ASP缓存类

木鸟写的
复制代码 代码如下:
'**********************************************
'vbsCache类

'属性valid,是否可用,取值前判断
'属性name,cache名,新建对象后赋值
'方法add(值,到期时间),设置cache内容
'属性value,返回cache内容
'属性blempty,是否未设置值
'方法makeEmpty,释放内存,测试用
'方法equal(变量1),判断cache值是否和变量1相同
'方法expires(time),修改过期时间为time
'木鸟2002.12.24
'http://
'========================
'========================
'DimApplication(2)
'Application(0)Counter计数器
'Application(1)dateTime放置时间
'Application(2)Content缓存内容

PublicPREFIX
PublicPREFIX_LENGTH

PrivateSubClass_Initialize()
PREFIX="Cached:"
PREFIX_LENGTH=7
EndSub
PrivateSubClass_Terminate
EndSub
'设置变量
PublicPropertyLetCache(ByRefKey,ByRefContent)
DimItem(2)
Item(0)=0
Item(1)=Now()
IF(IsObject(Content))Then
SetItem(2)=Content
Else
Item(2)=Content
EndIF
Application.Unlock
Application(PREFIX&Key)=Item
Application.Lock
EndProperty
'取出变量计数器++
PublicPropertyGetCache(ByRefKey)
DimItem
Item=Application(PREFIX&Key)
IF(IsArray(Item))Then
IF(IsObject(Item))Then
SetCache=Item(2)
Else
Cache=Item(2)
EndIF
Application(PREFIX&Key)(0)=Application(PREFIX&Key)(0)+1
Else
Cache=Empty
EndIF
EndProperty
'检查缓存对象是否存在
PublicPropertyGetExists(ByRefKey)
DimItem
Item=Application(PREFIX&Key)
IF(IsArray(Item))Then
Exists=True
Else
Exists=False
EndIF
EndProperty
'得到计数器数值
PublicPropertyGetCounter(ByRefKey)
DimItem
Item=Application(PREFIX&Key)
IF(IsArray(Item))Then
Counter=Item(0)
EndIF
EndProperty

'设置计数器时间
PublicPropertyLetdateTime(ByRefKey,ByRefSetdateTime)
DimItem
Item=Application(PREFIX&Key)
IF(IsArray(Item))Then
Item(1)=SetdateTime
EndIF
EndProperty
'得到计数器时间
PublicPropertyGetdateTime(ByRefKey)
DimItem
Item=Application(PREFIX&Key)
IF(IsArray(Item))Then
dateTime=Item(1)
EndIF
EndProperty

'重置计数器
PublicSubResetCounter()
DimKey
DimItem
Application.Unlock
ForEachKeyinApplication.Contents
IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then
Item=Application(Key)
Item(0)=0
Application(Key)=Item
EndIF
Next
Application.Lock
EndSub
'删除某以缓存
PublicSubClear(ByRefKey)
Application.Contents.Remove(PREFIX&Key)
EndSub
'清空没有使用的缓存
PublicSubClearUnused()
DimKey,Keys,KeyLength,KeyIndex
ForEachKeyinApplication.Contents
IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then
IF(Application(Key)(0)=0)Then
Keys=Keys&VBNewLine&Key
EndIF
EndIF
Next
Keys=Split(Keys,VBNewLine)
KeyLength=UBound(Keys)
Application.Unlock
ForKeyIndex=1ToKeyLength
Application.Contents.Remove(Keys(KeyIndex))
Next
Application.Lock
EndSub
'清空所有缓存
PublicSubClearAll()
DimKey,Keys,KeyLength,KeyIndex
ForEachKeyinApplication.Contents
IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then
Keys=Keys&VBNewLine&Key
EndIF
Next
Keys=Split(Keys,VBNewLine)
KeyLength=UBound(Keys)
Application.Unlock
ForKeyIndex=1ToKeyLength
Application.Contents.Remove(Keys(KeyIndex))
Next
Application.Lock
EndSub

EndClass
slightboyn类例子SetWyd=NewJayCache
Wyd.dateTime("Page")=时间
IfWyd.Exists("Page")Then
Response.writeWyd.Cache("Page")'输出
Else
Wyd.Cache("Page")=xxx 写入
Responxe.writexxx
EndIF
Wyd.Clear("page")'删除缓存

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章