public async Task <bool> UpdateValueAsync(string type, string value)
        {
            type = type.ToUpperInvariant();
            var baseData = await GetByCacheAsync(type);

            if (baseData == null)
            {
                baseData = new NBaseData.BaseData()
                {
                    Type  = type,
                    Value = value
                };
            }
            else
            {
                baseData.Value = value;
            }

            var result = false;

            lock (_syncObj)
            {
                result = _baseDataRepository.Update(baseData) > 0;
            }

            if (result)
            {
                await SetCacheAsync(type, baseData);
            }

            return(result);
        }
        public async Task <bool> AddListAsync(string type, BaseDataListDto dto)
        {
            type = type.ToUpperInvariant();
            var baseData = await GetByCacheAsync(type);

            if (baseData == null)
            {
                baseData = await _baseDataRepository.GetFirstAsync(b => b.Type == type);
            }
            Dictionary <string, string> baseDataDict;
            bool result;

            lock (_syncObj)
            {
                if (baseData == null)
                {
                    baseDataDict = new Dictionary <string, string>()
                    {
                        { dto.Name, dto.Code }
                    };

                    baseData = new NBaseData.BaseData()
                    {
                        Type  = type,
                        Value = JsonConvert.SerializeObject(baseDataDict)
                    };

                    result = _baseDataRepository.Insert(baseData) > 0;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(baseData.Value))
                    {
                        baseDataDict = new Dictionary <string, string>()
                        {
                            { dto.Name, dto.Code }
                        };
                    }
                    else
                    {
                        baseDataDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(baseData.Value);
                        if (!baseDataDict.ContainsKey(dto.Name))
                        {
                            baseDataDict.Add(dto.Name, dto.Code);
                        }
                    }

                    baseData.Value = JsonConvert.SerializeObject(baseDataDict);
                    result         = _baseDataRepository.Update(baseData) > 0;
                }
            }

            if (result)
            {
                await SetCacheAsync(type, baseData);
            }

            return(result);
        }
        private async Task SetCacheAsync(string type, NBaseData.BaseData baseData)
        {
            type = type.ToUpperInvariant();
            var key = $"BaseData.{type}";
            DistributedCacheEntryOptions options = new DistributedCacheEntryOptions();

            options.SetSlidingExpiration(TimeSpan.FromMinutes(30));
            await _cache.SetAsync(key, baseData, options);
        }