zoukankan      html  css  js  c++  java
  • C# Cache的类方法

     public class DataCache
        {
            /// <summary>
            /// 获取当前应用程序指定CacheKey的Cache值
            /// </summary>
            /// <param name="CacheKey"></param>
            /// <returns></returns>
            public static object GetCache(string CacheKey)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                return objCache[CacheKey];
            }

            /// <summary>
            /// 设置当前应用程序指定CacheKey的Cache值
            /// </summary>
            /// <param name="CacheKey"></param>
            /// <param name="objObject"></param>
            public static void SetCache(string CacheKey, object objObject)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Insert(CacheKey, objObject);
            }

            /// <summary>
            /// 移除指定数据缓存
            /// </summary>
            public static void RemoveCache(string CacheKey)
            {
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                objCache.Remove(CacheKey);
            }

            /// <summary>
            /// 清空所有的Cache
            /// </summary>
            public static void RemoveAllCache()
            {
                List<string> cacheKeys = new List<string>();
                IDictionaryEnumerator cacheEnum = HttpContext.Current.Cache.GetEnumerator();
                while (cacheEnum.MoveNext())
                {
                    cacheKeys.Add(cacheEnum.Key.ToString());
                }
                foreach (string cacheKey in cacheKeys)
                {
                    HttpContext.Current.Cache.Remove(cacheKey);
                }
            }

        }

  • 相关阅读:
    省选模拟17 题解
    省选模拟16 题解
    省选模拟15 题解
    省选模拟14 题解
    省选模拟13 题解
    省选模拟12 题解
    图论专项测试
    数学专题测试4
    省选模拟11 题解
    爬虫框架:scrapy
  • 原文地址:https://www.cnblogs.com/DTWolf/p/4848465.html
Copyright © 2011-2022 走看看