asp.net Cache cache operation class code

  • 2020-05-12 02:28:29
  • OfStack

 
using System.Collections.Generic; 
using System.Web; 
using System; 
namespace DataAccess 
{ 
/// <summary> 
///  Cache control class  
/// </summary> 
public class CacheControl 
{ 
public static List<string> AllUseCacheKey = new List<string>(); 
/// <summary> 
///  Add the cache  
/// </summary> 
/// <param name="key"></param> 
/// <param name="value"></param> 
/// <param name="absoluteExpiration"></param> 
public static void AddCache(string key, object value, DateTime absoluteExpiration) 
{ 
if (!AllUseCacheKey.Contains(key)) 
{ 
AllUseCacheKey.Add(key); 
} 
HttpContext.Current.Cache.Add(key, value, null, absoluteExpiration, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); 
} 
/// <summary> 
///  Remove the cache  
/// </summary> 
/// <param name="key"></param> 
public static void RemoveCache(string key) 
{ 
if (AllUseCacheKey.Contains(key)) 
{ 
AllUseCacheKey.Remove(key); 
} 
HttpContext.Current.Cache.Remove(key); 
} 
/// <summary> 
///  Clear the used cache  
/// </summary> 
public static void ClearCache() 
{ 
foreach (string value in AllUseCacheKey) 
{ 
HttpContext.Current.Cache.Remove(value); 
} 
AllUseCacheKey.Clear(); 
} 
} 
} 

Related articles: