c#自帶緩存使用方法 c#移除清理緩存
更新時(shí)間: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#實(shí)現(xiàn)餐飲管理系統(tǒng)完整版
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)餐飲管理系統(tǒng)的完整版,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01C#簡(jiǎn)單讀取、改變文件的創(chuàng)建、修改及訪(fǎng)問(wèn)時(shí)間的方法
這篇文章主要介紹了C#簡(jiǎn)單讀取、改變文件的創(chuàng)建、修改及訪(fǎng)問(wèn)時(shí)間的方法,涉及C#文件類(lèi)SetCreationTime、SetLastWriteTime及SetLastAccessTime的相關(guān)使用技巧,需要的朋友可以參考下2015-07-07C# WinForm調(diào)用Shell_NotifyIcon的示例代碼
這篇文章主要介紹了C# WinForm調(diào)用Shell_NotifyIcon的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-11-11C#難點(diǎn)逐個(gè)擊破(2):out返回參數(shù)
之前提到ref是將原方法中的參數(shù)影響的結(jié)果返回到調(diào)用它的方法中,out與ref類(lèi)似,相比之下,ref傳遞參數(shù)的地址,out是返回值。2010-02-02C#使用foreach語(yǔ)句搜索數(shù)組元素的方法
這篇文章主要介紹了C#使用foreach語(yǔ)句搜索數(shù)組元素的方法,涉及C#使用foreach語(yǔ)句遍歷數(shù)組實(shí)現(xiàn)搜索功能的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04