View Single Post
  #1 (permalink)  
Old October 15th, 2007, 07:22 AM
jimibt jimibt is offline
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default Articles/links that have TBH relevance

The idea of this thread is that articles or links are posted hi-lighting various techniques or tips that can be adapted for use in TBH to either make it more scalable, simpler or generally more elegant. I'll kick off with this article:

http://davidhayden.com/blog/dave/arc...erPattern.aspx

followed by code examples of it's use presently and proposed in TBH:

presently from BLL\Forums\Forum.cs:

        public static Forum GetForumByID(int forumID)
        {
            Forum forum = null;
            string key = "Forums_Forum_" + forumID.ToString();

            if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                forum = (Forum)BizObject.Cache[key];
            }
            else
            {
                forum = GetForumFromForumDetails(SiteProvider.Forums.GetFo rumByID(forumID));
                BaseForum.CacheData(key, forum);
            }
            return forum;
        }

proposed/amended:

        public static Forum GetForumByID(int forumID)
        {
            Forum forum = null;
            string key = "Forums_Forum_" + forumID.ToString();

            // get the cachedata upfront into an object
            object data = BizObject.Cache[key];
            if (BaseForum.Settings.EnableCaching && data != null)
            {
                // if test is passed, then set forum to typeof (Forum)data;
                forum = (Forum)data;
            }
            else
            {
                forum = GetForumFromForumDetails(SiteProvider.Forums.GetFo rumByID(forumID));
                BaseForum.CacheData(key, forum);
            }
            return forum;
        }

hope this makes sense. it certainly 'beats' the race condition and the if statement really only tests for cacheing being enabled as well as the data object not being null. if the condition is met, then the Forum forum object is set to the data object as type Forum.

one worth modifying and using throughout.

[edit] the url above is making the page very wide, i couldn't get the standard <a href="www.site.com">description</a> to work. any tips??

jimi

http://www.originaltalent.com
__________________
jimi

http://www.originaltalent.com
The Following User Says Thank You to jimibt For This Useful Post:
jminatel (December 16th, 2008)