Skip to content

Instantly share code, notes, and snippets.

@kasunkv
Created February 2, 2020 16:49
Show Gist options
  • Save kasunkv/da7fb0148e2d0fc9d2d1754d9416b9f3 to your computer and use it in GitHub Desktop.
Save kasunkv/da7fb0148e2d0fc9d2d1754d9416b9f3 to your computer and use it in GitHub Desktop.
Configure Cache Expiry time for the App Configuration dynamic refresh
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