Search code examples
c#xmlcachingpolling

C# ASP.NET Polling XML from server and cache it


Multiple web apps are running with a same configuration XML file, and the file is downloaded from a service, which is highly-available. I, however, would like to have all the web apps running, even though the service is down. What would be a best practice? Suggest a best architectural solution and C# codes if possible.

Thanks


Solution

  • In my opinion, it really depends on how often is the service restarted, redeployed, how often the configuration service is down and how frequent the configuration changes. As well as how critical is the configuration (is it user preference or endpoint address)?

    • You can save it to a local copy into each application folder and use that as cache, and refresh it when service is available.
    • You can define a fallback configuration if configuration is not critical, and use fallback value when configuration service is offline.
    • You can use shared database to store configuration.
    • You can implement an endpoint in each application that consumes this configuration to save when the configuration services identifies a change.

    For example, This is in your configuration service, although you need a mechanism to ensure when the configuration service notifies its subscriber, they need to be online too.

        UpdateSystemSetting(setting) {
          foreach (var consumer in consumers) 
          {
            consumer.NotifyChange(newConfiguration);
          }
        }