Esempio n. 1
0
        /// <summary>
        /// 获得公司列表
        /// 2015-11-25 吉日嘎拉 进行改进
        /// </summary>
        /// <param name="province">省</param>
        /// <param name="city">城市</param>
        /// <param name="district">县区</param>
        /// <returns>数据表</returns>
        public static string[] GetOrganizeByDistrictByCache(string province, string city, string district)
        {
            string[] result = null;

            string organize = string.Empty;

            if (string.IsNullOrWhiteSpace(province))
            {
                province = string.Empty;
            }
            if (string.IsNullOrWhiteSpace(city))
            {
                city = string.Empty;
            }
            if (string.IsNullOrWhiteSpace(district))
            {
                district = string.Empty;
            }
            string key = "OrganizeByDistrict_" + province + "_" + city + "_" + district;

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

            return(result);
        }
Esempio n. 2
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;

            using (var redisClient = PooledRedisHelper.GetOrganizeClient())
            {
                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.GetOrganizeClient())
                    {
                        redisClient.Set <string>(key, city, DateTime.Now.AddHours(4));
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取省份
        /// 2015-11-25 吉日嘎拉 采用缓存方式,效率应该会更高
        /// </summary>
        /// <param name="area">区域</param>
        /// <returns>省份数组</returns>
        public static string[] GetProvinceByCache(string area = null)
        {
            string[] result = null;

            if (string.IsNullOrWhiteSpace(area))
            {
                area = string.Empty;
            }
            string key      = "OrganizeProvince_" + area;
            string province = string.Empty;

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

            return(result);
        }