Points to consider about adding shared cache to an existing application:

the below examples are taken from the provided example application.
  1. check the cache before reading from the data source
  2. put data into cache after reading from the data source
  3. clear or update the cache item when updating the data source
public Common.Country GetByName(string name)
{
	// create a unique key for this item.
	string key = string.Format(cacheKeyCountryByName, name);
	// 1 - check the cache before reading from the data source
	Common.Country result = Common.Util.CacheGet<Common.Country>(key);
	if (result == null)
	{
		foreach (Common.Country country in this.GetAll(false))
		{
			if (name.Equals(country.Name))
			{
				result = country;
				break;
			}
		}
		// 2 - put data into cache after reading from the data source
		Common.Util.CacheAdd(key, result);
	}
	return result;
}

Last edited Jan 2, 2008 at 12:47 PM by ronischuetz, version 1

Comments

No comments yet.