Example #1
0
        private async Task SetCacheItemsAsync(
            string providerName,
            string providerKey,
            string currentName,
            SettingCacheItem currentCacheItem)
        {
            var settingDefinitions = SettingDefinitionManager.GetAll();
            var settingsDictionary = (await SettingRepository.GetListAsync(providerName, providerKey))
                                     .ToDictionary(s => s.Name, s => s.Value);

            var cacheItems = new List <KeyValuePair <string, SettingCacheItem> >();

            foreach (var settingDefinition in settingDefinitions)
            {
                var settingValue = settingsDictionary.GetOrDefault(settingDefinition.Name);

                cacheItems.Add(
                    new KeyValuePair <string, SettingCacheItem>(
                        CalculateCacheKey(settingDefinition.Name, providerName, providerKey),
                        new SettingCacheItem(settingValue)
                        )
                    );

                if (settingDefinition.Name == currentName)
                {
                    currentCacheItem.Value = settingValue;
                }
            }

            await Cache.SetManyAsync(cacheItems, considerUow : true);
        }
Example #2
0
        protected virtual async Task <SettingCacheItem> GetCacheItemAsync(string name, string providerName, string providerKey)
        {
            var cacheKey  = CalculateCacheKey(name, providerName, providerKey);
            var cacheItem = await Cache.GetAsync(cacheKey, considerUow : true);

            if (cacheItem != null)
            {
                return(cacheItem);
            }

            cacheItem = new SettingCacheItem(null);

            await SetCacheItemsAsync(providerName, providerKey, name, cacheItem);

            return(cacheItem);
        }
Example #3
0
 protected virtual string GetSettingNameFormCacheKeyOrNull(string key)
 {
     //TODO: throw ex when name is null?
     return(SettingCacheItem.GetSettingNameFormCacheKeyOrNull(key));
 }
Example #4
0
 protected virtual string CalculateCacheKey(string name, string providerName, string providerKey)
 {
     return(SettingCacheItem.CalculateCacheKey(name, providerName, providerKey));
 }