You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/enable-dynamic-configuration-aspnet-core.md
+10-19
Original file line number
Diff line number
Diff line change
@@ -25,14 +25,6 @@ In this tutorial, you learn how to:
25
25
26
26
Finish the quickstart: [Create an ASP.NET Core app with App Configuration](./quickstart-aspnet-core-app.md).
27
27
28
-
## Add a sentinel key
29
-
30
-
A *sentinel key* is a key that you update after you complete the change of all other keys. Your app monitors the sentinel key. When a change is detected, your app refreshes all configuration values. This approach helps to ensure the consistency of configuration in your app and reduces the overall number of requests made to your App Configuration store, compared to monitoring all keys for changes.
31
-
32
-
1. In the Azure portal, open your App Configuration store and select **Configuration Explorer > Create > Key-value**.
33
-
1. For **Key**, enter *TestApp:Settings:Sentinel*. For **Value**, enter 1. Leave **Label** and **Content type** blank.
34
-
1. Select **Apply**.
35
-
36
28
## Reload data from App Configuration
37
29
38
30
1. Open *Program.cs*, and update the `AddAzureAppConfiguration` method you added during the quickstart. You can connect to App Configuration using either Microsoft Entra ID (recommended) or a connection string. The following code snippet demonstrates using Microsoft Entra ID.
@@ -44,20 +36,20 @@ A *sentinel key* is a key that you update after you complete the change of all o
// Load all keys that start with `TestApp:` and have no label.
40
+
.Select("TestApp:*", LabelFilter.Null)
41
+
//Reload configuration if any selected key-values have changed.
42
+
.ConfigureRefresh(refreshOptions=>
43
+
refreshOptions.RegisterAll());
52
44
});
53
45
```
54
46
55
47
The `Select` methodisusedtoloadallkey-valueswhosekeynamestartswith *TestApp:*andthathave*nolabel*. Youcancallthe `Select` methodmorethanoncetoloadconfigurationswithdifferentprefixesorlabels. IfyoushareoneAppConfigurationstorewithmultipleapps, thisapproachhelpsloadconfigurationonlyrelevanttoyourcurrentappinsteadofloadingeverythingfromyourstore.
56
48
57
-
Inthe `ConfigureRefresh` method, youregisterkeysyouwanttomonitorfor changes in your App Configuration store. The `refreshAll` parameter to the `Register` method indicates that all configurations you specified by the `Select` method will be reloaded if the registered key changes.
49
+
Insidethe `ConfigureRefresh` method, youcallthe `RegisterAll` methodtoinstructtheAppConfigurationprovidertoreloadtheentireconfigurationwheneveritdetectsachangeinanyoftheselectedkey-values (thosestartingwith*TestApp:*andhavingnolabel). Formoreinformationaboutmonitoringconfigurationchanges, see [Bestpracticesforconfigurationrefresh](./howto-best-practices.md#configuration-refresh).
58
50
59
51
> [!TIP]
60
-
> You can add a call to the `refreshOptions.SetCacheExpiration` method to specify the minimum time between configuration refreshes. In this example, you use the default value of 30 seconds. Adjust to a higher value if you need to reduce the number of requests made to your App Configuration store.
@@ -108,7 +100,7 @@ You've set up your app to use the [options pattern in ASP.NET Core](/aspnet/core
108
100
109
101
## Request-driven configuration refresh
110
102
111
-
Theconfigurationrefreshistriggeredbytheincomingrequeststoyourwebapp. Norefreshwilloccurifyourappisidle. Whenyourappisactive, theAppConfigurationmiddlewaremonitorsthesentinelkey, oranyotherkeysyouregisteredfor refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the cache expiration time you set has passed.
103
+
Theconfigurationrefreshistriggeredbytheincomingrequeststoyourwebapp. Norefreshwilloccurifyourappisidle. Whenyourappisactive, theAppConfigurationmiddlewaremonitorsanykeysyouregisteredfor refreshing in the `ConfigureRefresh` call. The middleware is triggered upon every incoming request to your app. However, the middleware will only send requests to check the value in App Configuration when the refresh interval you set has passed.
112
104
113
105
- If a request to App Configuration for change detection fails, your app will continue to use the cached configuration. New attempts to check for changes will be made periodically while there are new incoming requests to your app.
114
106
- The configuration refresh happens asynchronously to the processing of your app's incoming requests. It will not block or slow down the incoming request that triggered the refresh. The request that triggered the refresh may not get the updated configuration values, but later requests will get new configuration values.
@@ -134,16 +126,15 @@ The configuration refresh is triggered by the incoming requests to your web app.
134
126
135
127
1. Signintothe [Azureportal](https://portal.azure.com). Select **All resources**, and select the App Configuration store that you created in the quickstart.
Insidethe `ConfigureRefresh` method, youcallthe `RegisterAll` methodtoinstructtheAppConfigurationprovidertoreloadtheentireconfigurationwheneveritdetectsachangeinanyoftheselectedkey-values (thosestartingwith*TestApp:*andhavingnolabel). Formoreinformationaboutmonitoringconfigurationchanges, see [Bestpracticesforconfigurationrefresh](./howto-best-practices.md#configuration-refresh).
146
145
147
-
The `SetCacheExpiration` method specifies the minimum time that must elapse before a new request is made to App Configuration to check for any configuration changes. In this example, you override the default expiration time of 30 seconds, specifying a time of 5 minutes instead. It reduces the potential number of requests made to your App Configuration store.
146
+
The `SetRefreshInterval` methodspecifiestheminimumtimethatmustelapsebeforeanewrequestismadetoAppConfigurationtocheckforanyconfigurationchanges. Inthisexample, youoverridethedefaultexpirationtimeof30seconds, specifyingatimeof5minutesinstead. ItreducesthepotentialnumberofrequestsmadetoyourAppConfigurationstore.
148
147
149
148
150
149
1. Addan `Application_BeginRequest` methodtothe `Global` class. If the method already exists, add the following code to it.
@@ -156,9 +155,9 @@ Add the following key-values to the App Configuration store and leave **Label**
156
155
```
157
156
Callingthe `ConfigureRefresh` methodalonewon't cause the configuration to refresh automatically. You call the `TryRefreshAsync` method at the beginning of every request to signal a refresh. This design ensures your application only sends requests to App Configuration when it is actively receiving requests.
158
157
159
-
Calling `TryRefreshAsync` isano-opbeforetheconfiguredcacheexpirationtimeelapses, soitsperformanceimpactisminimal. WhenarequestismadetoAppConfiguration, asyoudon't wait on the task, the configuration is refreshed asynchronously without blocking the execution of the current request. The current request may not get the updated configuration values, but subsequent requests will do.
158
+
Calling `TryRefreshAsync` isano-opbeforetheconfiguredrefreshintervalelapses, soitsperformanceimpactisminimal. WhenarequestismadetoAppConfiguration, asyoudon't wait on the task, the configuration is refreshed asynchronously without blocking the execution of the current request. The current request may not get the updated configuration values, but subsequent requests will do.
160
159
161
-
Ifthecall `TryRefreshAsync` failsfor any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured cache expiration time has passed again, and the `TryRefreshAsync` call is triggered by a new request to your application.
160
+
Ifthecall `TryRefreshAsync` failsfor any reason, your application will continue to use the cached configuration. Another attempt will be made when the configured refresh interval has passed again, and the `TryRefreshAsync` call is triggered by a new request to your application.
162
161
163
162
## Use the latest configuration data
164
163
@@ -261,16 +260,15 @@ Add the following key-values to the App Configuration store and leave **Label**
1. Refreshthebrowserpagetoseethenewconfigurationsettings. Youmayneedtorefreshmorethanoncefor the changes to be reflected or change your cache expiration time to less than 5 minutes.
271
+
1. Refreshthebrowserpagetoseethenewconfigurationsettings. Youmayneedtorefreshmorethanoncefor the changes to be reflected or change your refresh interval to less than 5 minutes.
0 commit comments