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);
                }
            }

        }

  • 相关阅读:
    Mybatis详解(二)
    Mybatis详解(一)
    Java集合
    Java基础之IO
    Java异常知识点!
    HTTP状态码
    ajax传字符串时出现乱码问题的解决
    Json 文件 : 出现 Expected value at 1:0 问题的解决
    java @XmlTransient与@Transient区别
    文件的上传和回显
  • 原文地址:https://www.cnblogs.com/DTWolf/p/4848465.html
Copyright © 2011-2022 走看看