View Single Post
  #74 (permalink)  
Old September 19th, 2007, 11:18 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

Max,

getting into delegates a bit, so changed the category forum stuff to the following (first is the old revised code, followed by the new implementation:

     public static List<Forum> GetForums(int CategoryID)
     {
         List<Forum> forums = null;
         string key = "Forums_Forums_" + CategoryID.ToString();

         if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
         {
             forums = (List<Forum>)BizObject.Cache[key];
         }
         else
         {
             List<Forum> allforums = BLL.Forums.Forum.GetForums();
             forums = new List<Forum>();
             foreach (Forum forumCat in allforums)
             {
                 if (forumCat.CategoryID == CategoryID || forumCat.CategoryID==0)
                 {
                     forums.Add(forumCat);
                 }
             }
             BaseForum.CacheData(key, forums);
         }
         return forums;
     }

        public static List<Forum> GetForums(int CategoryID)
        {
            List<Forum> forums = null;
            string key = "Forums_Forums_" + CategoryID.ToString();

            if (BaseForum.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                forums = (List<Forum>)BizObject.Cache[key];
            }
            else
            {
                List<Forum> allforums = BLL.Forums.Forum.GetForums();
                forums = allforums.FindAll(
                                    delegate(Forum forum)
                                    {
                                        return forum.CategoryID == CategoryID
                                            || forum.CategoryID == 0;
                                    });
                BaseForum.CacheData(key, forums);
            }
            return forums;
        }

saves doing a big loop to find the items -pretty neet actually.!!


jimi

http://www.originaltalent.com