0

I have a problem related to updating values in Azure Configuration Manager. What is not clear to me is whether the update occurs only when the specified cache period elapses or if it should also occur when the value of the sentinel key is changed.

This is the code in my Program.cs.

var builder = WebApplication.CreateBuilder(args);

ConfigureServices();

var app = builder.Build();
Configure(app, app.Environment);

app.Run();


void ConfigureServices()
{
    
    // Servizio per connettersi a AzureApp Configuration
    builder.Services.AddAzureAppConfiguration();
    builder.Configuration.AddAzureAppConfiguration(options =>
    {
        var connectionString = builder.Configuration.GetConnectionString("AppConfiguration");
        options.Connect(connectionString)
            .ConfigureRefresh(r => r.Register(key: "Settings:Refresh", refreshAll: true)
            .SetCacheExpiration(TimeSpan.FromMinutes(10)));
    });
    ...
}

void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseAzureAppConfiguration();

    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyApp v1"));

    if (env.IsDevelopment())
        app.UseDeveloperExceptionPage();
    else
    {
        app.UseHttpsRedirection();
        app.UseExceptionHandler("/Error");
    }

    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}

From what I understand, if the value of the Settings:Refresh item is updated, the entire configuration should be updated.

I have created this simple Controller method to read the configuration:

[HttpGet()]
public IActionResult Test()
{
    var settings = configuration.GetSection("Settings").GetChildren().ToList();
    return Ok(settings);
}

However, even though I change the value of the sentinel key, the configuration is only updated when the cache expires.

What am I doing wrong?

skysurfer
  • 721
  • 2
  • 5
  • 23

0 Answers0