public static MemberCache UpdateCache(MemberCache memberCache)
 {
     try
     {
         if (memberCache != null && memberCache.memberDisplay != null)
             lock (ThisLock)
             {
                 HttpContext.Current.Cache["MemberCache" + memberCache.memberDisplay.MemberId] = memberCache;
             }
         return memberCache;
     }
     catch (Exception exception)
     {
         ErrorDatabaseManager.AddException(exception, exception.GetType());
     }
     return null;
 }
        /// <summary>
        /// gets the cache of the member
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static MemberCache GetCache(Guid memberId, bool loadCacheIfNoneFound)
        {
            try
            {
                MemberCache dataObject = (MemberCache)HttpContext.Current.Cache["MemberCache" + memberId];
                if (dataObject == null && loadCacheIfNoneFound)
                {
                    //lock (ThisLock)
                    //{
                    dataObject = (MemberCache)HttpContext.Current.Cache["MemberCache" + memberId];

                    if (dataObject == null)
                    {
                        dataObject = new MemberCache();

                        dataObject.IsAdmin = System.Web.Security.Roles.IsUserInRole("admin");
                        dataObject.OwnersOfFederation = RDN.Library.Classes.Federation.Federation.GetAllOwnedFederations(memberId);

                        if (SiteSingleton.Instance.IsProduction)
                        {
                            dataObject.memberDisplay = RDN.Library.Classes.Account.User.GetMemberDisplay(memberId);
                        }
                        else
                        {
                            dataObject.OwnersOfFederation = new List<FederationOwnership>();
                            dataObject.memberDisplay = RDN.Library.Classes.Account.User.GetMemberDisplay(memberId, false, false);
                        }
                        dataObject.Leagues = RDN.Library.Classes.Account.User.GetLeaguesOfMember(memberId);
                        dataObject.UserStoreInfo = RDN.Library.Classes.Store.StoreGateway.GetStoreIdsFromInternalId(memberId);
                        dataObject.UnreadMessagesCount = RDN.Library.Classes.Messages.Messages.GetUnreadMessagesCount(memberId);


                        if (dataObject.memberDisplay != null)
                            dataObject.CurrentLeague = RDN.Library.Classes.League.LeagueFactory.GetLeague(dataObject.memberDisplay.CurrentLeagueId);

                        if (dataObject.CurrentLeague != null)
                        {
                            dataObject.JobsCount = RDN.Library.Classes.League.JobBoard.GetJobsCount(dataObject.CurrentLeague.LeagueId);
                            dataObject.Federations = RDN.Library.Classes.Federation.Federation.GetFederationsWithLeagueId(dataObject.CurrentLeague.LeagueId);
                            dataObject.CurrentFederation = RDN.Library.Classes.Federation.Federation.GetFederationWithLeagueId(dataObject.CurrentLeague.LeagueId);
                            for (int i = 0; i < dataObject.CurrentLeague.Groups.Count; i++)
                            {
                                var tempMem = dataObject.CurrentLeague.Groups[i].GroupMembers.Where(x => x.MemberId == memberId).FirstOrDefault();
                                if (tempMem != null)
                                {
                                    var gTemp = dataObject.CurrentLeague.Groups[i];
                                    gTemp.DoesReceiveGroupNotificationsCurrentMember = tempMem.DoesReceiveNewPostGroupNotifications;
                                    gTemp.DoesReceiveGroupBroadcastNotificationsCurrentMember = tempMem.DoesReceiveGroupBroadcastNotifications;
                                    dataObject.GroupsApartOf.Add(gTemp);
                                }
                            }
                            dataObject.Dues = Classes.Dues.DuesFactory.GetDuesSettingsByLeague(dataObject.CurrentLeague.LeagueId);
                        }
                        if (dataObject.Federations != null && dataObject.Federations.Count > 0)
                        {
                            dataObject.CurrentFederationForumId = RDN.Library.Classes.Forum.Forum.GetForumIdOfFederation(dataObject.Federations.FirstOrDefault().FederationId);
                            dataObject.CurrentFederationStoreInfo = RDN.Library.Classes.Store.StoreGateway.GetStoreIdsFromInternalId(dataObject.Federations.FirstOrDefault().FederationId);
                        }
                        else if (dataObject.OwnersOfFederation.Count > 0)
                        {
                            dataObject.CurrentFederationForumId = RDN.Library.Classes.Forum.Forum.GetForumIdOfFederation(dataObject.OwnersOfFederation.FirstOrDefault().Federation.FederationId);
                            dataObject.CurrentFederationStoreInfo = RDN.Library.Classes.Store.StoreGateway.GetStoreIdsFromInternalId(dataObject.OwnersOfFederation.FirstOrDefault().Federation.FederationId);
                        }
                        else
                            dataObject.CurrentFederationStoreInfo = new Classes.Store.Classes.Store();

                        if (dataObject.CurrentLeague != null)
                        {
                            dataObject.CurrentLeagueForumId = RDN.Library.Classes.Forum.Forum.GetForumIdOfLeague(dataObject.CurrentLeague.LeagueId);
                            dataObject.CurrentLeagueCalendarId = RDN.Library.Classes.Calendar.CalendarFactory.GetCalendarIdOfLeague(dataObject.CurrentLeague.LeagueId);
                            dataObject.CurrentLeagueStoreInfo = RDN.Library.Classes.Store.StoreGateway.GetStoreIdsFromInternalId(dataObject.CurrentLeague.LeagueId);
                            dataObject.LeagueDocuments = new List<Document>();
                            if (DateTime.UtcNow > dataObject.CurrentLeague.SubscriptionPeriodEnds)
                                dataObject.IsCurrentLeagueSubscriptionPaid = false;
                            else
                                dataObject.IsCurrentLeagueSubscriptionPaid = true;
                            dataObject.SubscriptionEndDateOfCurrentLeague = dataObject.CurrentLeague.SubscriptionPeriodEnds;
                        }
                        HttpContext.Current.Cache["MemberCache" + memberId] = dataObject;
                    }
                    //}
                }
                return dataObject;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }