c#自帶緩存使用方法 c#移除清理緩存
更新時間:2014年02月07日 15:45:27 作者:
這篇文章主要介紹了c#自帶緩存使用方法,包括獲取數(shù)據(jù)緩存、設(shè)置數(shù)據(jù)緩存、移除指定數(shù)據(jù)緩存等方法,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
/// <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è)置數(shù)據(jù)緩存
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
}
/// <summary>
/// 設(shè)置數(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è)置數(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());
}
}
相關(guān)文章
C#簡單讀取、改變文件的創(chuàng)建、修改及訪問時間的方法
這篇文章主要介紹了C#簡單讀取、改變文件的創(chuàng)建、修改及訪問時間的方法,涉及C#文件類SetCreationTime、SetLastWriteTime及SetLastAccessTime的相關(guān)使用技巧,需要的朋友可以參考下2015-07-07C# WinForm調(diào)用Shell_NotifyIcon的示例代碼
這篇文章主要介紹了C# WinForm調(diào)用Shell_NotifyIcon的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-11-11