richard
-
7/15/2011 5:00:03 PM
Caching on MessageBoard Webpart
I am trying to get my head around caching.
Here is the senario:
I have a messageboard web part on a bunch of cms.news documents to allow users to comment.
In another part of the site I have a repeater with a transformation which shows these documents.
I have a custom function which checks the number of comments on each of these documents to shows in the transformation .
What I would like to know is:
1: do I need to write code in my custom function which caches the MessageBoard object for each of the documents (as below) 2: if so, how do I make sure that the cache is cleared when a new comment is added to a message board on a document
Here's what I have so far:
Custom Function to get number of comments on a document:
public static string GetMessageBoardCount(object documentid, object nodeid, string boardname) {
BoardInfo bi = null; //check the cache using (CachedSection<BoardInfo> cs = new CachedSection<BoardInfo>(ref bi, 1, true, null,"BoardCountCache" , documentid + boardname))
{ if (cs.LoadData)//cache item not found {
bi = BoardInfoProvider.GetBoardInfo(boardname,ValidationHelper.GetInteger(documentid,0));
cs.Data = bi;
CacheDependency cd = null; cd = CacheHelper.GetCacheDependency(new string[] { "nodeid|" + nodeid.ToString() });
cs.CacheDependency = cd;
} }
return bi.BoardMessages.ToString();//count of messages
}
Cheers
Richard
|