c comes with its own cache usage method c removes the clean cache

  • 2020-06-12 10:32:08
  • OfStack


/// <summary>
///  Get data cache 
/// </summary>
/// <param name="CacheKey"> key </param>
public static object GetCache(string CacheKey)
{
    System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    return objCache[CacheKey];
}
/// <summary>
///  Set up the data cache 
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
    System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    objCache.Insert(CacheKey, objObject);
}
/// <summary>
///  Set up the data cache 
/// </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>
///  Set up the data cache 
/// </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>
///  Removes the specified data cache 
/// </summary>
public static void RemoveAllCache(string CacheKey)
{
    System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    _cache.Remove(CacheKey);
}
/// <summary>
///  Remove all caches 
/// </summary>
public static void RemoveAllCache()
{
    System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
    while (CacheEnum.MoveNext())
    {
_cache.Remove(CacheEnum.Key.ToString());
    }
}


Related articles: