Kooboo.Commerce.Multilingual.Storage.CachedTranslactionStore.UpdateCache C# (CSharp) Method

UpdateCache() private method

private UpdateCache ( CultureInfo culture, IEnumerable translations ) : void
culture System.Globalization.CultureInfo
translations IEnumerable
return void
        private void UpdateCache(CultureInfo culture, IEnumerable<EntityTransaltion> translations)
        {
            // 只有指定的类型才需要缓存
            var translationsNeedToBeCached = translations.Where(t => NeedToBeCached(t.EntityKey.EntityType)).ToList();
            if (translationsNeedToBeCached.Count == 0)
            {
                return;
            }

            _lock.EnterWriteLock();

            try
            {
                if (!_cache.ContainsKey(culture))
                {
                    _cache.Add(culture, new Dictionary<EntityKey, EntityTransaltion>());
                }

                var cache = _cache[culture];

                foreach (var translation in translationsNeedToBeCached)
                {
                    var cacheItem = IsEmptyTranslation(translation) ? null : translation.Clone();

                    if (cache.ContainsKey(translation.EntityKey))
                    {
                        cache[translation.EntityKey] = cacheItem;
                    }
                    else
                    {
                        cache.Add(translation.EntityKey, cacheItem);
                    }
                }
            }
            finally
            {
                _lock.ExitWriteLock();
            }
        }