c#清理缓存 c#自带缓存使用方法 c#移除清理缓存

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c#清理缓存 c#自带缓存使用方法 c#移除清理缓存

  2021-03-19 我要评论
想了解c#自带缓存使用方法 c#移除清理缓存的相关内容吗,在本文为您仔细讲解c#清理缓存的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:清理缓存,下面大家一起来学习吧。

复制代码 代码如下:

/// <summary>
/// 获取数据缓存
/// </summary>
/// <param name="CacheKey">键</param>
public static object GetCache(string CacheKey)
{
    System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    return objCache[CacheKey];
}
/// <summary>
/// 设置数据缓存
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
    System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    objCache.Insert(CacheKey, objObject);
}
/// <summary>
/// 设置数据缓存
/// </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>
/// 设置数据缓存
/// </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>
/// 移除指定数据缓存
/// </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());
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们