Beispiel #1
0
        /// <summary>
        /// Register the specified key-value to be refreshed when the configuration provider's <see cref="IConfigurationRefresher"/> triggers a refresh.
        /// The <see cref="IConfigurationRefresher"/> instance can be obtained by calling <see cref="AzureAppConfigurationOptions.GetRefresher()"/>.
        /// </summary>
        /// <param name="key">Key of the key-value.</param>
        /// <param name="label">Label of the key-value.</param>
        /// <param name="refreshAll">If true, a change in the value of this key refreshes all key-values being used by the configuration provider.</param>
        public AzureAppConfigurationRefreshOptions Register(string key, string label = LabelFilter.Null, bool refreshAll = false)
        {
            RefreshRegistrations[key] = new KeyValueWatcher
            {
                Key        = key,
                Label      = label,
                RefreshAll = refreshAll
            };

            return(this);
        }
        private void UpdateCacheExpirationTime(KeyValueWatcher changeWatcher, bool success)
        {
            TimeSpan cacheExpirationTime;

            if (success)
            {
                changeWatcher.RefreshAttempts = 0;
                cacheExpirationTime           = changeWatcher.CacheExpirationInterval;
            }
            else
            {
                if (changeWatcher.RefreshAttempts < int.MaxValue)
                {
                    changeWatcher.RefreshAttempts++;
                }

                cacheExpirationTime = changeWatcher.CacheExpirationInterval.CalculateBackoffTime(changeWatcher.RefreshAttempts);
            }

            changeWatcher.CacheExpires = DateTimeOffset.UtcNow.Add(cacheExpirationTime);
        }