Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Patterns and Origins: SueetieCache Class

The second of three new Sueetie Wiki Document for today follows.  Patterns and Origins: SueetieCache Class.


____________________

The SueetieCache class contains enhancements to HttpContext server caching, making it easier to use caching to optimize Sueetie performance.

SueetieCache - Patterns



The SueetieCache Class is a helper function to make working with the HttpContext.Current.Cache object more efficient. A sample use of caching would be in obtaining a User object, where SueetieCache is checked for the presence of a User object by that user's unique caching key. If not in the SueetieCache, a User object retrieved is 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:

Comments (0) | Post RSS RSS comment feed

Posted on 3/19/2009 4:54:22 PM by Dave Burke
Categories: Sueetie
Tags: no tags for this post

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke