Is reading the web config faster than Sitecore’s Cache?

Okay, I’ll admit, I felt I knew the answer to this – but after my work with the CustomCache object, I felt that this was an interesting experiment.

If I just need to read string, is it faster to read from the configuration file with Sitecore.Configuration.Settings.GetSetting() or using the cache?

Well, the short answer is that the file is roughly twice as fast. Good, no cache needed!

I found that for the below code, on my machine, the ‘reading file’ loop took about 1800ms, but the ‘reading cache’ loop took about 3600ms. There was some variation in the results – of the order of about 15% – but reading from the file was always faster. Good!

My test code:

string exampleValue = Sitecore.Configuration.Settings.GetSetting("example");
string key = "test";
int iterations = 10000000;
CacheManager.SetSettingsCache(key, exampleValue);
Stopwatch sw1 = new Stopwatch();
for (int i = 0; i < iterations; i++)
string x = Sitecore.Configuration.Settings.GetSetting("example");
Stopwatch sw2 = new Stopwatch();
for (int j = 0; j < iterations; j++)
string y = CacheManager.GetSettingsCache(key);





Is reading the web config faster than Sitecore’s Cache?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.