【文件属性】:
文件名称:缓存操作类
文件大小:9KB
文件格式:CS
更新时间:2016-08-23 09:29:51
cache
C#对数据集缓存
///
/// 获取当前应用程序指定CacheKey的Cache值
///
///
///
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
///
/// 设置当前应用程序指定CacheKey的Cache值
///
///
///
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
///
/// 设置当前应用程序指定CacheKey的Cache值
///
///
///
public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
}
///
/// 设置当前应用程序指定CacheKey的Cache值(可不设置绝对过期事件)
///
///
///
///
public static void SetCache(string CacheKey, object objObject, TimeSpan slidingExpiration)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, Cache.NoAbsoluteExpiration, slidingExpiration);
}
public static void RemoveCache(string cacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
if (objCache[cacheKey] != null)
objCache.Remove(cacheKey);
}