Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the CloudConfigurationManager GetSetting method cache?

Tags:

.net

azure

Does anyone know if you take a performance hit calling CloudConfigurationManager GetSetting method? Does it reparse the azure file for example or is it cached? Not sure if I should add my own caching/static variable to improve perf for something called often like a connection string.

Thanks

like image 921
Bryan Avatar asked Nov 20 '12 18:11

Bryan


3 Answers

The source is available on github.

If you take a look at the source you can see that it isn't doing any caching, so if you are seeing performance issues you may want to implement your own caching.

The body of GetSetting shows a simple return:

value = GetValue("ServiceRuntime", name, GetServiceRuntimeSetting);

if (value == null)
{
    value = GetValue("ConfigurationManager", name, n => ConfigurationManager.AppSettings[n]);
}

return value;
like image 95
Estyn Avatar answered Oct 18 '22 07:10

Estyn


The accepted answer might not be correct.

It's true that CloudConfigurationManager itself does not cache, but that's because it internally delegates to ConfigurationManager or WebConfigurationManager, which do cache values.

From MSDN:

For <appSettings> and <connectionStrings>, you use the AppSettings and ConnectionStrings properties. These methods perform read-only operations, use a single cached instance of the configuration, and are multithread aware.

So that even if you access from CloudConfigurationManager directly, most probably, there would be no IO operation incurred.

like image 5
Lifu Huang Avatar answered Oct 18 '22 07:10

Lifu Huang


No, it is not cached, as you suggested you would have to create you own caching for performance improvement.

like image 1
AvkashChauhan Avatar answered Oct 18 '22 06:10

AvkashChauhan