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
- Add()
- Insert()
- InsertMax()
- InsertMinutes()
- 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.
Top