c#自帶緩存使用方法 c#移除清理緩存
更新時間:2014年02月07日 15:45:27 作者:
這篇文章主要介紹了c#自帶緩存使用方法,包括獲取數(shù)據(jù)緩存、設置數(shù)據(jù)緩存、移除指定數(shù)據(jù)緩存等方法,需要的朋友可以參考下
復制代碼 代碼如下:
/// <summary>
/// 獲取數(shù)據(jù)緩存
/// </summary>
/// <param name="CacheKey">鍵</param>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
/// 設置數(shù)據(jù)緩存
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
/// <summary>
/// 設置數(shù)據(jù)緩存
/// </summary>
public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
}
/// <summary>
/// 設置數(shù)據(jù)緩存
/// </summary>
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);
}
/// <summary>
/// 移除指定數(shù)據(jù)緩存
/// </summary>
public static void RemoveAllCache(string CacheKey)
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
_cache.Remove(CacheKey);
}
/// <summary>
/// 移除全部緩存
/// </summary>
public static void RemoveAllCache()
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
_cache.Remove(CacheEnum.Key.ToString());
}
}
相關文章
C#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable
這篇文章介紹了C#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
C#實現(xiàn)的優(yōu)酷真實視頻地址解析功能(2014新算法)
這篇文章主要介紹了C#實現(xiàn)的優(yōu)酷真實視頻地址解析功能(2014新算法),本文在當前環(huán)境下是有效的,因為優(yōu)酷之前更新了算法,需要的朋友可以參考下2014-10-10

