Azure App Config - cache expiry and sentinel changes

2022-09-15T06:30:50.583+00:00

I am trying to set cache expiry and also track changes via sentinel. Setting cache expiry to 1 day, but any value change in Message key and Sentinel does not refresh the value get fetched from Azure App Config. It seems the cache overrides sentinel changes and does not guarantee immediate fetching of key value. What I am missing from the code below?

   config.AddAzureAppConfiguration(options =>  
                               {  
                                   options.Connect(azAppConfigConnection)  
                                   .Select(KeyFilter.Any, context.HostingEnvironment.EnvironmentName)  
                                   .ConfigureRefresh(refresh =>  
                                   {  
                                       // All configuration values will be refreshed if the sentinel key changes.  
                                       refresh.Register("TestApp:Settings:Sentinel", refreshAll: true);  
                                       refresh.Register("TestApp:Settings:Message", context.HostingEnvironment.EnvironmentName).SetCacheExpiration(TimeSpan.FromDays(1));  
     
                                   });  
                               });  
     
   Thanks
Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
214 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,261 Reputation points
    2022-09-20T03:10:31.307+00:00

    @Krishnamurthy, Rajarajacholan (DG-CHN) Thank you for your patience.

    After reviewing the code snippet, found that below code doesn't set Cache expiration only to key "Message" but instead it applies to the whole ConfigureRefresh (which includes Sentinel). Hence, any change in Sentinel or Message doesn't refresh the value until cache expiration time has met (1 day).

    .ConfigureRefresh(refresh =>  
    {  
    	// All configuration values will be refreshed if the sentinel key changes.  
    	refresh.Register("TestApp:Settings:Sentinel", refreshAll: true);  
    	refresh.Register("TestApp:Settings:Message").SetCacheExpiration(TimeSpan.FromDays(30));  
    })  
    

    For your case, you can change something like below:

    .ConfigureRefresh(refresh =>  
    {  
       refresh.Register("Sentinel", refreshAll: true);  
       //refresh.SetCacheExpiration(TimeSpan.FromSeconds(30)); // optional as 30s is the default  
    })  
    .ConfigureRefresh(refresh =>  
    {  
       refresh.Register("Message");  
       refresh.SetCacheExpiration(TimeSpan.FromDays(1));  
    })  
    

    This way you can set SetCacheExpiration for different keys, and ConfigureRefresh will behave as you expected.

    I hope this answers your question and feel free to add if you have any questions. I would be happy to assist you. Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community.

    1 person found this answer helpful.

  2. Rajarajacholan Krishnamurthy 21 Reputation points
    2022-09-20T12:40:15.67+00:00

    243024-image.png

    0 comments No comments