ASP缓存技术详解(7)


 
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 Function   
 
Private Sub makeEmpty(SetName) '释放内存   
Application.Lock   
Application(SetName) = Empty   
Application.unLock   
End Sub   
 
Public Sub DelCahe(MyCaheName) '删除缓存   
makeEmpty(CacheName"_"&MyCaheName)   
End Sub   
End Class   
 
'Set WydCache=New Cls_Cache   
'WydCache.Reloadtime=0.5 '定义过期时间 (以分钟为单位)   
'WydCache.CacheName="pages" '定义缓存名   
'IF WydCache.ObjIsEmpty() Then ''判断是否可用(包括过期,与是否为空值)   
'Response.write WydCache.Value   

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2071.html