/// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public static string GetParameterByCache(string tableName, string categoryCode, string parameterId, string parameterCode)
        {
            string result = null;

            System.Web.Caching.Cache cache = HttpRuntime.Cache;

            string cacheKey = "Parameter";

            if (!string.IsNullOrEmpty(categoryCode) && !string.IsNullOrEmpty(parameterId) && !string.IsNullOrEmpty(parameterCode))
            {
                cacheKey = "Parameter:" + tableName + ":" + categoryCode + ":" + parameterId + ":" + parameterCode;
            }
            if (cache != null && cache[cacheKey] == null)
            {
                BaseParameterManager parameterManager = new Business.BaseParameterManager();
                result = parameterManager.GetParameter(tableName, categoryCode, parameterId, parameterCode);

                // 若是空的不用缓存,继续读取实体
                if (result != null)
                {
                    cache.Add(cacheKey, result, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, CacheItemPriority.Normal, null);
                    // System.Console.WriteLine(System.DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " cache Parameter " + parameterCode);
                }
            }
            result = cache[cacheKey] as string;

            return(result);
        }
Exemple #2
0
        public static string GetParameterByCache(string tableName, string categoryCode, string parameterId, string parameterCode, bool refreshCache = false)
        {
            string result = string.Empty;

            if (!string.IsNullOrEmpty(categoryCode) && !string.IsNullOrEmpty(parameterId) && !string.IsNullOrEmpty(parameterCode))
            {
                string key = "Parameter:" + tableName + ":" + categoryCode + ":" + parameterId + ":" + parameterCode;
                using (var redisClient = PooledRedisHelper.GetClient())
                {
                    if (!refreshCache)
                    {
                        result = redisClient.Get <string>(key);
                    }

                    if (string.IsNullOrEmpty(result))
                    {
                        BaseParameterManager parameterManager = new Business.BaseParameterManager(tableName);
                        result = parameterManager.GetParameter(tableName, categoryCode, parameterId, parameterCode);
                        if (!string.IsNullOrEmpty(result))
                        {
                            redisClient.Set <string>(key, result, DateTime.Now.AddMinutes(10));
                        }
                    }
                }
            }

            return(result);
        }