/// <summary>
        /// 获取城市
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="province">省份</param>
        /// <returns>城市数组</returns>
        public string[] GetCity(BaseUserInfo userInfo, string province)
        {
            var parameter = ServiceParameter.CreateWithMessage(userInfo
                                                               , MethodBase.GetCurrentMethod()
                                                               , this.serviceName
                                                               , AppMessage.OrganizeService_GetCity);

            string[] result = null;
            ServiceUtil.ProcessUserCenterReadDb(parameter, (dbHelper) =>
            {
                System.Web.Caching.Cache cache = HttpRuntime.Cache;
                string cacheObject             = "OrganizeCity" + province;
                if (cache == null || cache[cacheObject] == null)
                {
                    lock (locker)
                    {
                        if (cache == null || cache[cacheObject] == null)
                        {
                            var manager = new BaseOrganizeManager(dbHelper, userInfo);
                            result      = manager.GetCity(province);
                            cache.Add(cacheObject, result, null, DateTime.Now.AddHours(8), TimeSpan.Zero, CacheItemPriority.Normal, null);
                        }
                    }
                }
                result = cache[cacheObject] as string[];
            });
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 获取城市
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="province">省份</param>
        /// <returns>城市数组</returns>
        public string[] GetCity(BaseUserInfo userInfo, string province)
        {
            string[] result = null;

#if Redis
            result = BaseOrganizeManager.GetCityByCache(province);
#else
            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());
            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                System.Web.Caching.Cache cache = HttpRuntime.Cache;
                string cacheObject             = "AreaOrganizeCity" + province;

                if (cache != null && cache[cacheObject] == null)
                {
                    // BaseAreaManager areaManager = new BaseAreaManager(dbHelper, result);
                    // result = areaManager.GetCityList(provinceId);
                    var manager = new BaseOrganizeManager(dbHelper, userInfo);
                    result      = manager.GetCity(province);
                    cache.Add(cacheObject, result, null, DateTime.Now.AddHours(8), TimeSpan.Zero, CacheItemPriority.Normal, null);
                }

                result = cache[cacheObject] as string[];
            });
#endif

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 获取城市
        /// 2015-11-25 吉日嘎拉 采用缓存方式,效率应该会更高
        /// </summary>
        /// <param name="province">省份</param>
        /// <returns>城市数组</returns>
        public static string[] GetCityByCache(string province = null)
        {
            string[] result = null;

            string city = string.Empty;

            if (string.IsNullOrWhiteSpace(province))
            {
                province = string.Empty;
            }
            // string key = "OrganizeCity:" + province;
            string key = "OC:" + province;

            using (var redisClient = PooledRedisHelper.GetReadOnlyClient())
            {
                city = redisClient.Get <string>(key);
            }
            if (!string.IsNullOrWhiteSpace(city))
            {
                result = city.Split('.');
            }
            else
            {
                // 从数据库读取数据
                BaseOrganizeManager organizeManager = new BaseOrganizeManager();
                result = organizeManager.GetCity(province);
                // 设置缓存
                if (result != null && result.Length > 0)
                {
                    city = string.Join(".", result);
                    using (var redisClient = PooledRedisHelper.GetClient())
                    {
                        redisClient.Set <string>(key, city, DateTime.Now.AddHours(4));
                    }
                }
            }

            return(result);
        }