基本的缓存类操作封装(实现类)
2007-04-02 00:20
375 查看
'**********************************************************************************************************
' Programmer By Shadow (QQ:33512603)
' Cache Base Class
' The DataCacheRealization class is packaging simple Cache operate
' Don't use Microsoft Enterprise Library
' Corpright(C) 2006 Jiang Jian
'**********************************************************************************************************
' 程序设计:江建
'**********************************************************************************************************
Imports System
Imports System.Web
Imports System.Web.Caching
Namespace DRMSystemNamespace DRMSystem.Common.Caching
Public Class DataCacheRealizationClass DataCacheRealization
Inherits DataCacheAbstract
Private Shared ReadOnly _cache As Cache
Shared/Static Methods#Region "Shared/Static Methods"
Shared Sub New()Sub New()
_cache = HttpRuntime.Cache
End Sub
#End Region
Public utility methods#Region "Public utility methods"
'**********************************************************************************************************
'功 能:创建一个Sql Server 数据库的 缓存依赖项
'参 数:DataBaseName - 数据名称, SqlTableName - 数据库中的表名(多个表名以逗号分割)
'返回值:AggregateCacheDependency (具体说明参见 MSDN)
'**********************************************************************************************************
Public Overrides Function CreateSqlTableCacheDependency()Function CreateSqlTableCacheDependency(ByVal DataBaseName As String, ByVal SqlTableName As String) As AggregateCacheDependency
Dim Dependency As New AggregateCacheDependency
Dim strTemp As String = SqlTableName
Dim Tables() As String = strTemp.Split(",")
Dim TableName As String
For Each TableName In Tables
Dependency.Add(New SqlCacheDependency(DataBaseName, TableName))
Next
Return Dependency
End Function
'**********************************************************************************************************
'功 能:创建一个 文件(File) 缓存依赖项
'参 数:FileName - 文件名包括路径(多个文件名以逗号分割)
'返回值:AggregateCacheDependency (具体说明参见 MSDN)
'**********************************************************************************************************
Public Overrides Function CreateFileCacheDependency()Function CreateFileCacheDependency(ByVal FileName As String) As AggregateCacheDependency
Dim Dependency As New AggregateCacheDependency
Dim strTemp As String = FileName
Dim Files() As String = strTemp.Split(",")
Dim strFileName As String
For Each strFileName In Files
Dependency.Add(New CacheDependency(strFileName))
Next
Return Dependency
End Function
'**********************************************************************************************************
'功 能:从 Cache 对象检索指定项
'参 数:Key - 要检索的缓存项的标识符
'返回值:Object
'**********************************************************************************************************
Public Overrides Function GetCache()Function GetCache(ByVal Key As String) As Object
Return _cache.Get(Key)
End Function
'**********************************************************************************************************
'功 能:从应用程序的 Cache 对象移除指定项
'参 数:Key - 要移除的缓存项的 String 标识符
'返回值:NULL
'**********************************************************************************************************
Public Overrides Sub Remove()Sub Remove(ByVal Key As String)
_cache.Remove(Key)
End Sub
'**********************************************************************************************************
'功 能:删除应用程序中的所有 Cache 对象
'参 数:NULL
'返回值:NULL
'**********************************************************************************************************
Public Overrides Sub Clear()Sub Clear()
Dim CacheEnum As IDictionaryEnumerator = _cache.GetEnumerator()
While CacheEnum.MoveNext()
_cache.Remove(CacheEnum.Key)
End While
End Sub
'**********************************************************************************************************
'功 能:将指定项添加到 Cache 对象,该对象具有依赖项、过期和优先级策略以及一个委托。
'参 数:Key - 用于引用该项的缓存键, Value - 要插入缓存中的对象,Dependencies - 所插入对象的文件依赖项
'参 数:AbsoluteExpiration - 所插入对象将过期并被从缓存中移除的时间
'参 数:SlidingExpiration - 最后一次访问所插入对象时与该对象过期时之间的时间间隔
'参 数:Priority 该对象相对于缓存中存储的其他项的成本,由 CacheItemPriority 枚举表示。
'参 数:onRemoveCallback 在从缓存中移除对象时将调用的委托(如果提供)
'返回值:Object
'**********************************************************************************************************
Public Overrides Function Add()Function Add(ByVal Key As String, ByVal Value As Object, ByVal Dependencies As CacheDependency, ByVal AbsoluteExpiration As DateTime, ByVal SlidingExpiration As TimeSpan, ByVal Priority As CacheItemPriority, ByVal OnRemoveCallback As CacheItemRemovedCallback) As Object
Return _cache.Add(Key, Value, Dependencies, AbsoluteExpiration, SlidingExpiration, Priority, OnRemoveCallback)
End Function
'**********************************************************************************************************
'功 能:向 Cache 对象插入项,该项带有一个缓存键引用其位置,并使用 CacheItemPriority 枚举提供的默认值
'参 数:Key - 用于引用该项的缓存键, Value - 要插入缓存中的对象
'返回值:NULL
'**********************************************************************************************************
Public Overloads Overrides Sub Insert()Sub Insert(ByVal Key As String, ByVal Value As Object)
Insert(Key, Value, Nothing)
End Sub
'**********************************************************************************************************
'功 能:向 Cache 对象插入项,该项带有一个缓存键引用其位置,并使用 CacheItemPriority 枚举提供的默认值
'参 数:Key - 用于引用该项的缓存键, Value - 要插入缓存中的对象,Dependencies - 所插入对象的文件依赖项
'返回值:NULL
'**********************************************************************************************************
Public Overloads Overrides Sub Insert()Sub Insert(ByVal Key As String, ByVal Value As Object, ByVal Dependencies As CacheDependency)
Insert(Key, Value, Dependencies, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration)
End Sub
'**********************************************************************************************************
'功 能:向 Cache 对象插入项,该项带有一个缓存键引用其位置,并使用 CacheItemPriority 枚举提供的默认值
'参 数:Key - 用于引用该项的缓存键, Value - 要插入缓存中的对象,Dependencies - 所插入对象的文件依赖项
'参 数:AbsoluteExpiration - 所插入对象将过期并被从缓存中移除的时间
'参 数:SlidingExpiration - 最后一次访问所插入对象时与该对象过期时之间的时间间隔
'返回值:NULL
'**********************************************************************************************************
Public Overrides Sub Insert()Sub Insert(ByVal Key As String, ByVal Value As Object, ByVal Dependencies As CacheDependency, ByVal AbsoluteExpiration As DateTime, ByVal SlidingExpiration As TimeSpan)
_cache.Insert(Key, Value, Dependencies, AbsoluteExpiration, SlidingExpiration)
End Sub
'**********************************************************************************************************
'功 能:向 Cache 对象插入项,该项带有一个缓存键引用其位置,并使用 CacheItemPriority 枚举提供的默认值
'参 数:Key - 用于引用该项的缓存键, Value - 要插入缓存中的对象,Dependencies - 所插入对象的文件依赖项
'参 数:AbsoluteExpiration - 所插入对象将过期并被从缓存中移除的时间
'参 数:SlidingExpiration - 最后一次访问所插入对象时与该对象过期时之间的时间间隔
'参 数:Priority 该对象相对于缓存中存储的其他项的成本,由 CacheItemPriority 枚举表示。
'参 数:onRemoveCallback 在从缓存中移除对象时将调用的委托(如果提供)
'返回值:NULL
'**********************************************************************************************************
Public Overrides Sub Insert()Sub Insert(ByVal Key As String, ByVal Value As Object, ByVal Dependencies As CacheDependency, ByVal AbsoluteExpiration As DateTime, ByVal SlidingExpiration As TimeSpan, ByVal Priority As CacheItemPriority, ByVal OnRemoveCallback As CacheItemRemovedCallback)
_cache.Insert(Key, Value, Dependencies, AbsoluteExpiration, SlidingExpiration, Priority, OnRemoveCallback)
End Sub
#End Region
End Class
End Namespace
相关文章推荐
- Redis缓存系统(一)Java-Jedis操作Redis,基本操作以及 实现对象保存
- Redis缓存系统-Java-Jedis操作Redis,基本操作以及 实现对象保存
- [转]基本的缓存类操作封装(抽象类)
- 基本的缓存类操作封装(抽象类)
- 基本的缓存类操作封装(Shared 共享类)
- Redis缓存系统(1)Java-Jedis操作Redis,基本操作以及 实现对象保存
- 在java实现redis缓存技术的基本操作
- 泛型dao架构实现,封装crud等基本操作
- 泛型dao架构实现,封装crud等基本操作
- 链队列的(9个基本操作)实现
- Dao接口实现基本的数据库操作。增删改查
- poj 3580 Splay Tree 各种基本操作与实现
- 栈的基本操作实现-c/c++
- 循环队列的基本操作之代码实现_legend
- 双链表基本操作的实现
- 把aspx页面生成的cs文件放到其他类库中,以实现对其的封装操作.
- MongoDB学习笔记(二) 通过samus驱动实现基本数据操作
- java实现单链表的基本操作
- C语言实现单链表——之基本操作1
- java实现单链表的基本操作