Пример #1
0
        /// <summary>
        /// 移除缓存项
        /// </summary>
        /// <param name="cacheKey">The cache key.</param>
        /// <returns></returns>
        public static object Remove(string cacheKey)
        {
            switch (Config.CacheModule.ToLower())
            {
            case "json":
                HttpRuntime.Cache.Remove(cacheKey);
                try
                {
                    JsonCache.Remove(cacheKey);
                    return(true);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                return(false);

            case "xml":
                HttpRuntime.Cache.Remove(cacheKey);
                try
                {
                    XmlCache.Remove(cacheKey);
                    return(true);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                return(false);

            default:
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                return(objCache.Remove(cacheKey));
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        public static T Get <T>(string cacheKey)
        {
            switch (Config.CacheModule.ToLower())
            {
            case "json":
                var json = HttpRuntime.Cache[cacheKey] ?? JsonCache.Get <T>(cacheKey);
                return((T)json);

            case "xml":
                var xml = HttpRuntime.Cache[cacheKey] ?? XmlCache.Get <T>(cacheKey);
                return((T)xml);

            default:
                System.Web.Caching.Cache objCache = HttpRuntime.Cache;
                var de = objCache[cacheKey];
                return(de != null ? (T)de : default(T));
            }
        }
Пример #3
0
        /// <summary>
        /// Inserts the specified cache key.
        /// </summary>
        /// <param name="cacheKey">The cache key.</param>
        /// <param name="objObject">The obj object.</param>
        public static void Insert(string cacheKey, object objObject)
        {
            switch (Config.CacheModule.ToLower())
            {
            case "time":
                Set(cacheKey, objObject, Config.CacheDuration);
                break;

            case "json":
                var jsonFile = JsonCache.Set(cacheKey, objObject);
                Set(cacheKey, objObject, jsonFile);
                break;

            case "xml":
                var xmlFile = XmlCache.Set(cacheKey, objObject);
                Set(cacheKey, objObject, xmlFile);
                break;

            default:
                Set(cacheKey, objObject);
                break;
            }
        }