Created
February 2, 2020 16:49
-
-
Save kasunkv/da7fb0148e2d0fc9d2d1754d9416b9f3 to your computer and use it in GitHub Desktop.
Configure Cache Expiry time for the App Configuration dynamic refresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Identity; | |
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | |
namespace MusicStore.Web | |
{ | |
public class Program | |
{ | |
... | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => { | |
webBuilder.UseStartup<Startup>(); | |
}) | |
.ConfigureAppConfiguration((context, config) => { | |
var settings = config.Build(); | |
var appConfigEndpoint = settings["AppSettings:AppConfiguration:Endpoint"]; | |
var userAssignedIdentityClientId = settings["AppSettings:Identity:ClientId"]; | |
if (!string.IsNullOrEmpty(appConfigEndpoint)) | |
{ | |
var endpoint = new Uri(appConfigEndpoint); | |
config.AddAzureAppConfiguration(options => | |
{ | |
options | |
.Connect(endpoint, new ManagedIdentityCredential(clientId: userAssignedIdentityClientId)) | |
// Setting up dynamic app configuration | |
.ConfigureRefresh(refreshOpt => | |
{ | |
refreshOpt.Register(key: "AppSettings:Version", refreshAll: true, label: LabelFilter.Null); | |
// Set the cache expiry time to 10 seconds. | |
refreshOpt.SetCacheExpiration(TimeSpan.FromSeconds(10)); | |
}) | |
.UseFeatureFlags(); | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment