Click here to Skip to main content
15,884,298 members
Articles / Desktop Programming / Win32

Considerations for caching in BizTalk

Rate me:
Please Sign up or sign in to vote.
4.60/5 (4 votes)
24 Mar 2009GPL314 min read 42.1K   211   11  
Covering common challenges and pitfalls in caching in BizTalk.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace BizTalkCaching
{
	public static class CacheSaravana
	{
		private static Random _random = new Random(Environment.TickCount);
		private static Dictionary<string, string> _authorIds = null;

		public static string GetAuthorName(string authorId)
		{
			if (_authorIds == null)
			{
				Debug.WriteLine("Cache is empty. So populating the cache...");
				_authorIds = new Dictionary<string, string>();
				lock (_authorIds)
				{

					// sandwitching in some delay
					_authorIds.Add("2FC0CF1D-E107", "Matthew Johnstone");
					Thread.Sleep(_random.Next(0, 1));
					_authorIds.Add("71F5C860-80FA", "Carl Reynolds");
					Thread.Sleep(_random.Next(0, 1));
					_authorIds.Add("158FF294-1A89", "Robert Perkins");
					Thread.Sleep(_random.Next(0, 1));
					_authorIds.Add("A71AE681-9C39", "Michael Killey");
					Thread.Sleep(_random.Next(0, 1));
					_authorIds.Add("58794661-A9A3", "Saravana Kumar");
					Thread.Sleep(_random.Next(0, 1));
				}
			}
			else
			{
				Debug.WriteLine("Cache list is pre-populated. Value is going to be taken from the cache.");
			}
			string authName = _authorIds[authorId];
			if (authName != string.Empty)
				return authName;
			else
				throw new Exception("Author cannot be found with id :" + authorId);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
An enthusiast developer...

Comments and Discussions