Welcome Guest, you are in: Namespace

Patterns and Origins: SueetieCache Class

RSS
Modified on 2009/03/19 14:45 by daveburke Categorized as Patterns and Origins, Sueetie Source Code
The SueetieCache class contains enhancements to HttpContext server caching, making it easier to use caching to improve Sueetie performance.

SueetieCache - Patterns



The SueetieCache Class is essentially a helper function to make it more efficient to work with the HttpContext.Current.Cache object. A sample use of caching would be in obtaining a User object, where SueetieCache is checked for the presence of a User object by unique caching key and if not, retrieved from the database and then placed into SueetieCache.

public static SueetieUser GetUser(int userID)
{
	string userCacheKey = UserCacheKey(userID);
	SueetieUser sueetieUser = 
	   SueetieCache.Current[userCacheKey]as SueetieUser;
	if (sueetieUser == null)
	{
	   SueetieDataProvider _provider = SueetieDataProvider.LoadProvider();
	   sueetieUser = _provider.GetUser(userID);
	   SueetieCache.Current.Insert(userCacheKey, sueetieUser);
	}
	return sueetieUser;
}

The statement which checks for the existence of SueetieUser in the cache is

SueetieUser sueetieUser = SueetieCache.Current[userCacheKey] as SueetieUser;

Caching functions with overrides in SueetieCache include

  1. Add()
  2. Insert()
  3. InsertMax()
  4. InsertMinutes()
  5. Remove()

SueetieCache - Origins



As with SueetieContext, we're leveraging the patterns established in YetAnotherForum.NET for handling Caching in the Sueetie Framework. I personally like the bracket-based CacheKey syntax as in the earlier example.

SueetieUser sueetieUser = SueetieCache.Current[userCacheKey] as SueetieUser;

This comes from the YAFCache utility class approach being used in Sueetie.

public object this[string key]
{
   get
   {
      return _cache[key];
   }
   set
   {
      _cachekey = value;
   }
}



For additional reference, here is the location of the YAF.NET Caching class.

YetAnotherForum.NET Class.Utils library



Sueetie.Core Patterns and Origins Documents:


ScrewTurn Wiki version 3.0.2.500.


This site was built with the Sueetie .NET Online Community Framework. Learn more about Sueetie at Sueetie.com.