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

            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            string cacheObject             = "Parameter";

            if (!string.IsNullOrEmpty(categoryCode) && !string.IsNullOrEmpty(parameterId) && !string.IsNullOrEmpty(parameterCode))
            {
                cacheObject = "Parameter" + categoryCode + parameterId + parameterCode;
            }
            if (cache != null && cache[cacheObject] == null)
            {
                lock (locker)
                {
                    if (cache != null && cache[cacheObject] == null)
                    {
                        List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                        parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryCode, categoryCode));
                        parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, parameterId));
                        parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterCode, parameterCode));
                        parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldDeletionStateCode, 0));

                        BaseParameterManager parameterManager = new Business.BaseParameterManager();
                        result = parameterManager.GetProperty(parameters, BaseParameterEntity.FieldParameterContent);

                        // 若是空的不用缓存,继续读取实体
                        if (result != null)
                        {
                            cache.Add(cacheObject, 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[cacheObject] as string;
            return(result);
        }