Esempio n. 1
0
        public void CacheFeatureToggles()
        {
            try
            {
                var featureToggles = _featureToggleProvider.GetFeatureToggles();

                _cache.CacheFeatureToggles(MogglesConfigurationKeys.FeatureTogglesCacheKey, featureToggles, _mogglesConfigurationManager.GetCachingTime());
                _cache.CacheFeatureToggles(MogglesConfigurationKeys.PreviouslyCachedFeatureTogglesCacheKey, featureToggles, isExpiringCacheEntry: false);
                _cache.SubscribeToCacheExpirationEvent(CacheFeatureToggles);

                _featureToggleLoggingService.TrackEvent("Main cache and backup cache were set successfully.", _mogglesConfigurationManager.GetApplicationName(), _mogglesConfigurationManager.GetEnvironment());
            }
            catch (MogglesClientException)
            {
                _cache.CacheFeatureToggles(MogglesConfigurationKeys.FeatureTogglesCacheKey, new List <FeatureToggle>(), _mogglesConfigurationManager.GetOnErrorCachingTime());
                _cache.SubscribeToCacheExpirationEvent(CacheFeatureToggles);
            }
        }
        public Task Consume(ConsumeContext <RefreshTogglesCache> context)
        {
            _featureToggleService        = (MogglesToggleService)MogglesContainer.Resolve <MogglesToggleService>();
            _featureToggleLoggingService = (IMogglesLoggingService)MogglesContainer.Resolve <IMogglesLoggingService>();
            _mogglesConfigurationManager = (IMogglesConfigurationManager)MogglesContainer.Resolve <IMogglesConfigurationManager>();

            var msg = context.Message;

            var currentApplication = _mogglesConfigurationManager.GetApplicationName();
            var currentEnvironment = _mogglesConfigurationManager.GetEnvironment();

            if (msg.ApplicationName.ToLowerInvariant() == currentApplication.ToLowerInvariant() &&
                msg.Environment.ToLowerInvariant() == currentEnvironment.ToLowerInvariant())
            {
                _featureToggleLoggingService.TrackEvent($"Handled cache refresh event for {msg.ApplicationName}/{msg.Environment}", currentApplication, currentEnvironment);
                _featureToggleService.CacheFeatureToggles();
            }

            return(Task.FromResult(0));
        }