绶存类

绶存原代码
<%
Class Cls_Cache
 Public Reloadtime,MaxCount,CacheName
 Private LocalCacheName,CacheData,DelCount
 Private Sub Class_Initialize()
  Reloadtime=14400
  CacheName="Cache"
 End Sub
 Private Sub SetCache(SetName,NewValue)
  Application.Lock
  Application(SetName) = NewValue
  Application.unLock
 End Sub
 Public Sub MakeEmpty(MyCaheName)
  Application.Lock
  Application(CacheName&"_"&MyCaheName) = 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, "LvbbsCacheServer", " 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, "LvbbsCacheServer", " The CacheData Is Empty."
   End If
  Else
   Err.Raise vbObjectError + 1, "LvbbsCacheServer", " 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 DelCache(MyCaheName)
  Application.Lock
  Application.Contents.Remove(CacheName&"_"&MyCaheName)
  Application.unLock
 End Sub
End Class
%>
使用示例:
<%
'aplication名称为: 缓存主名字_缓存副名字, 如 myCache_tempCache
'值为:测试,Wed Oct 20 11:11:30 UTC+0800 2004,
Dim myCache,content,str
Set myCache=New Cls_Cache
myCache.Reloadtime=0.05                  '设置过期时间,单位为1分钟
myCache.CacheName = "abc"         '缓存主名字.
myCache.Name="vcd"              '缓存副名字
If myCache.ObjIsEmpty() Then          '但该缓存为空时设置缓存.
    content = "测试<br>"
    myCache.value = content
End If
Response.Write myCache.value
Set myCache = Nothing

Sub DelCahe(MyCaheName)      '删除绶存
    Application.Lock
 Application.Contents.Remove(MyCaheName)
 Application.unLock
End Sub
delCahe("abc_vcdd")
Function  GetallCache()     '显示绶存名
 Dim Cacheobj
 For Each Cacheobj in Application.Contents
  response.write Cacheobj&"<br>"
 Next
End Function
%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值