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#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable
這篇文章介紹了C#把EXCEL數(shù)據(jù)轉(zhuǎn)換成DataTable的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
通過(guò)C#實(shí)現(xiàn)自動(dòng)售貨機(jī)接口
這篇文章主要介紹了通過(guò)C#實(shí)現(xiàn)自動(dòng)售貨機(jī)接口,需要的朋友可以參考下2015-07-07
C#實(shí)現(xiàn)的優(yōu)酷真實(shí)視頻地址解析功能(2014新算法)
這篇文章主要介紹了C#實(shí)現(xiàn)的優(yōu)酷真實(shí)視頻地址解析功能(2014新算法),本文在當(dāng)前環(huán)境下是有效的,因?yàn)閮?yōu)酷之前更新了算法,需要的朋友可以參考下2014-10-10
WPF中下拉框可作選擇項(xiàng)也可以作為只讀文本框使用的方法
這篇文章主要給大家介紹了關(guān)于WPF中下拉框可以選擇項(xiàng)也可以作為只讀文本框使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-02-02
C#常用知識(shí)點(diǎn)簡(jiǎn)單回顧(有圖有真相)
C#知識(shí)點(diǎn)記錄編程的點(diǎn)點(diǎn)滴滴,本文整理了一些(傳值調(diào)用與引用調(diào)用/打印三角形/遞歸求階乘/多態(tài)性..等等),感興趣的朋友可以了解下的,不要走開(有圖有真相)2013-01-01

