예제 #1
0
        public ClubMemberStatus?GetClubMemberStatus(int clubID, int userID)
        {
            if (userID <= 0)
            {
                return(null);
            }

            string cachekey = GetCacheKeyForClubMemberStatus(userID, clubID);

            ClubMemberStatus cache = ClubMemberStatus.Normal;

            if (CacheUtil.TryGetValue <ClubMemberStatus>(cachekey, out cache))
            {
                return(cache);
            }

            ClubMemberStatus?result = ClubDao.Instance.GetClubMemberStatus(clubID, userID);

            if (result != null)
            {
                CacheUtil.Set <ClubMemberStatus>(cachekey, result.Value);
            }

            return(result);
        }
예제 #2
0
파일: DoingBO.cs 프로젝트: zhangbo27/bbsmax
        /// <summary>
        /// 获取大家的记录包含当前页的记录的评论(通过记录的CommentList属性访问)
        /// </summary>
        /// <param name="visitorID">访问者ID</param>
        /// <param name="friendOwnerID">好友所有者ID</param>
        /// <param name="pageNumber">数据分页每页条数</param>
        /// <param name="pageSize">数据分页当前页码</param>
        /// <returns></returns>
        public DoingCollection GetEveryoneDoingsWithComments(int pageNumber, int pageSize)
        {
            pageNumber = pageNumber <= 0 ? 1 : pageNumber;

            pageSize = pageSize <= 0 ? Consts.DefaultPageSize : pageSize;

            DoingCollection doings = null;

            #region 获取Doings缓存

            string doingsCacheKey = GetCacheKeyForEveryoneDoings(pageNumber, pageSize);

            bool doingsNeedCache = pageNumber <= Consts.ListCachePageCount;

            bool doingsCached = doingsNeedCache && CacheUtil.TryGetValue(doingsCacheKey, out doings);

            if (doingsCached)
            {
                return(doings);
            }

            #endregion

            #region 获取TotalCount缓存

            int?totalCount = null;

            string totalCountCacheKey = GetCacheKeyForEveryoneDoingsTotalCount();

            bool totalCountCached = CacheUtil.TryGetValue(totalCountCacheKey, out totalCount);

            #endregion

            doings = DoingDao.Instance.GetEveryoneDoingsWithComments(pageNumber, pageSize, ref totalCount);

            #region 设置TotalCount缓存

            if (totalCountCached == false)
            {
                CacheUtil.Set(totalCountCacheKey, totalCount);
            }

            #endregion

            #region 设置Articles缓存

            if (doingsNeedCache)
            {
                CacheUtil.Set(doingsCacheKey, doings);
            }

            #endregion

            ProcessKeyword(doings, ProcessKeywordMode.TryUpdateKeyword);

            return(doings);
        }
예제 #3
0
        public static ThreadCollectionV5 GetForumThreads(int forumID, ThreadOrderType orderType)
        {
            string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, GetTotalCacheCount(orderType));

            ThreadCollectionV5 threads;

            if (CacheUtil.TryGetValue <ThreadCollectionV5>(cacheKey, out threads))
            {
                return(threads);
            }

            return(null);
        }
예제 #4
0
파일: TagBO.cs 프로젝트: zhangbo27/bbsmax
        /// <summary>
        /// 获取标签
        /// </summary>
        public TagCollection GetUnlockTags(int pageNumber, int pageSize, ref int?count)
        {
            TagCollection tags     = null;
            string        cacheKey = string.Format(CacheKey_Tag_List_All, pageSize, pageNumber);

            if (!CacheUtil.TryGetValue <TagCollection>(cacheKey, out tags))
            {
                tags = TagDao.Instance.GetMostTags(false, pageNumber, pageSize, ref count);
                CacheUtil.Set <TagCollection>(cacheKey, tags);
            }

            return(tags);
        }
예제 #5
0
파일: DiskBO.cs 프로젝트: zhangbo27/bbsmax
        public DiskDirectory GetDiskDirectory(int userID, int directoryID)
        {
            string        cacheKey = string.Format(cacheKey_directory, userID, directoryID);
            DiskDirectory Directory;

            if (!CacheUtil.TryGetValue <DiskDirectory>(cacheKey, out Directory))
            {
                Directory = DiskDao.Instance.GetDiskDirectory(userID, directoryID);
                if (Directory != null)
                {
                    CacheUtil.Set <DiskDirectory>(cacheKey, Directory);
                }
            }
            return(Directory);
        }
예제 #6
0
        /// <summary>
        /// 移除用户的表情分组缓存
        /// </summary>
        /// <param name="userID"></param>
        private void RemoveCachedUserEmoticonGroups(int userID)
        {
            string cacheKey = string.Format(cacheKey_EmoticonUserGroups, userID);


            EmoticonGroupCollection cachedGroups;

            if (CacheUtil.TryGetValue <EmoticonGroupCollection>(cacheKey, out cachedGroups))
            {
                CacheUtil.Remove(cacheKey);
                foreach (EmoticonGroup group in cachedGroups)
                {
                    CacheUtil.Remove(string.Format(cacheKey_EmoticonGroup, group.GroupID));
                }
            }
        }
예제 #7
0
        public PointShowUserCollection GetTopUserShows(int userID, int count)
        {
            PointShowUserCollection users;
            PointShowUserCollection result = new PointShowUserCollection();

            if (CacheUtil.TryGetValue <PointShowUserCollection>(showUsersKey, out users))
            {
                int i = 0;
                foreach (PointShowUser user in users)
                {
                    result.Add(user);
                    i++;
                    if (i == count)
                    {
                        break;
                    }
                }

                return(users);
            }

            Dictionary <int, int>    points;
            Dictionary <int, string> contents;
            UserCollection           temp = GetUserShows(userID, 1, count, out points, out contents);

            users = new PointShowUserCollection();

            int m = 0;

            foreach (User u in temp)
            {
                PointShowUser pointShowUser = new PointShowUser();
                pointShowUser.Content = contents[u.UserID];
                pointShowUser.Price   = points[u.UserID];
                pointShowUser.UserID  = u.UserID;

                users.Add(pointShowUser);
                if (m < count)
                {
                    result.Add(pointShowUser);
                    m++;
                }
            }

            CacheUtil.Set <PointShowUserCollection>(showUsersKey, users);
            return(result);
        }
예제 #8
0
        public ClubCategoryCollection GetClubCategories()
        {
            string cacheKey = GetCacheKeyForClubCategories();

            ClubCategoryCollection result = null;

            if (CacheUtil.TryGetValue <ClubCategoryCollection>(cacheKey, out result))
            {
                return(result);
            }

            result = ClubDao.Instance.GetClubCategories();

            CacheUtil.Set <ClubCategoryCollection>(cacheKey, result);

            return(result);
        }
예제 #9
0
        /// <summary>
        /// 获取指定用户指定类型的所有通知
        /// </summary>
        /// <param name="notifyType">指定类型</param>
        /// <returns>指定用户指定类型的所有通知集合</returns>
        public NotifyCollection GetNotifiesByType(int userID, int notifyType, int pageSize, int pageNumber, ref int?count)
        {
            if (userID <= 0)
            {
                ThrowError(new NotLoginError());
                return(new NotifyCollection());
            }

            pageNumber = pageNumber <= 0 ? 1 : pageNumber;
            pageSize   = pageSize <= 0 ? Consts.DefaultPageSize : pageSize;

            if (HasUnCatchedError)
            {
                return(new NotifyCollection());
            }

#if !Passport
            PassportClientConfig settings = Globals.PassportClient;
            if (settings.EnablePassport)
            {
                NotifyProxy[] proxys = settings.PassportService.Notify_GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count);


                NotifyCollection notifies = new NotifyCollection();
                foreach (NotifyProxy proxy in proxys)
                {
                    notifies.Add(GetNotify(proxy));
                }

                return(notifies);
            }
            else
#endif
            {
                NotifyCollection notifys;
                string           cacheKey = string.Format(cacheKey_pagedNotify, userID, notifyType, pageSize, pageNumber);
                if (!CacheUtil.TryGetValue <NotifyCollection>(cacheKey, out notifys))
                {
                    notifys = NotifyDao.Instance.GetNotifiesByType(userID, notifyType, pageSize, pageNumber, ref count);
                    CacheUtil.Set <NotifyCollection>(cacheKey, notifys);
                }
                count = notifys.TotalRecords;
                return(notifys);
            }
        }
예제 #10
0
        public void GetDenouncingCount(
            out int? denouncingPhotoCount, 
            out int? denouncingArticleCount, 
            out int? denouncingShareCount,
            out int? denouncingUserCount,
            out int? denouncingTopicCount,
            out int? denouncingReplyCount)
        {
            string cacheKey = "Denouncing/Count";

            int?[] cachedata = null;

            if (CacheUtil.TryGetValue<int?[]>(cacheKey, out cachedata) == false)
            {
                DenouncingDao.Instance.GetDenouncingCount(
                    out denouncingPhotoCount,
                    out denouncingArticleCount,
                    out denouncingShareCount,
                    out denouncingUserCount,
                    out denouncingTopicCount,
                    out denouncingReplyCount);

                cachedata = new int?[] { 
                    denouncingPhotoCount,
                    denouncingArticleCount,
                    denouncingShareCount,
                    denouncingUserCount,
                    denouncingTopicCount,
                    denouncingReplyCount
                };

                CacheUtil.Set<int?[]>(cacheKey, cachedata);
            }
            else
            {
                int i = 0;

                denouncingPhotoCount = cachedata[i ++];
                denouncingArticleCount = cachedata[i ++];
                denouncingShareCount = cachedata[i ++];
                denouncingUserCount = cachedata[i ++];
                denouncingTopicCount = cachedata[i ++];
                denouncingReplyCount = cachedata[i++];
            }
        }
예제 #11
0
        public EmoticonCollection GetEmoticons(int userID, int groupID)
        {
            if (!CanUseEmoticon(userID))
            {
                return(new EmoticonCollection());
            }

            string             cacheKey = string.Format(cacheKey_ByGroup, userID, groupID);
            EmoticonCollection emoticons;

            if (!CacheUtil.TryGetValue <EmoticonCollection>(cacheKey, out emoticons))
            {
                emoticons = EmoticonDao.Instance.GetEmoticons(userID, groupID);
                CacheUtil.Set <EmoticonCollection>(cacheKey, emoticons);
            }

            return(emoticons);
        }
예제 #12
0
        /// <summary>
        /// 返回表情列表
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="groupID">分组ID</param>
        /// <param name="emoticons"></param>
        /// <returns></returns>
        public EmoticonCollection GetEmoticons(int userID, int groupID, int pageNumber, int pageSize, bool IsDesc)
        {
            if (!CanUseEmoticon(userID))
            {
                return(new EmoticonCollection());
            }
            string cacheKey = string.Format(cacheKey_EmotiocnPaged, groupID, pageSize, pageNumber);

            EmoticonCollection emotes;

            if (!CacheUtil.TryGetValue <EmoticonCollection>(cacheKey, out emotes))
            {
                int totalCount;
                emotes = EmoticonDao.Instance.GetEmoticons(userID, groupID, pageSize, pageNumber, IsDesc, out totalCount);
                CacheUtil.Set <EmoticonCollection>(cacheKey, emotes);//列表缓存
            }
            return(emotes);
        }
예제 #13
0
파일: DiskBO.cs 프로젝트: zhangbo27/bbsmax
        /// <summary>
        /// ��ȡ��Ŀ¼
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public DiskDirectory GetDiskRootDirectory(int userID)
        {
            DiskDirectory rootDirectory = null;

            if (!CacheUtil.TryGetValue <DiskDirectory>(string.Format(chcheKey_userRootDirectory, userID), out rootDirectory))
            {
                rootDirectory = DiskDao.Instance.GetDiskRootDirectory(userID);
            }
            if (rootDirectory == null)
            {
                rootDirectory = new DiskDirectory(0, 0, "\\");
            }
            else
            {
                CacheUtil.Set <DiskDirectory>(string.Format(chcheKey_userRootDirectory, userID), rootDirectory);
            }

            return(rootDirectory);
        }
예제 #14
0
        private static void ClearForumThreadsCache(string cacheKey, int forumID)
        {
            List <string> cacheKeys = null;

            if (s_ForumCacheKeys != null && s_ForumCacheKeys.TryGetValue(forumID, out cacheKeys))
            {
                if (cacheKeys.Contains(cacheKey))
                {
                    cacheKeys.Remove(cacheKey);
                }
            }

            ThreadCollectionV5 threads;

            if (CacheUtil.TryGetValue <ThreadCollectionV5>(cacheKey, out threads))
            {
                CacheUtil.Remove(cacheKey);
                UpdateAllCachedThreadsRemoveThreads(threads, forumID, null);
            }
        }
예제 #15
0
        public ImpressionRecordCollection GetTargetUserImpressionRecords(int targetUserID, int pageNumber, int pageSize)
        {
            ImpressionRecordCollection result = null;

            string cacheKey = GetCacheKeyForTargetUserImpressionRecordsTotalCount(targetUserID);

            int?totalCount = null;

            bool totalCountCached = CacheUtil.TryGetValue <int?>(cacheKey, out totalCount);

            result = ImpressionDao.Instance.GetTargetUserImpressionRecords(targetUserID, pageNumber, pageSize, ref totalCount);

            if (totalCountCached == false)
            {
                CacheUtil.Set <int?>(cacheKey, totalCount);
            }

            ProcessKeyword(result, ProcessKeywordMode.TryUpdateKeyword);

            return(result);
        }
예제 #16
0
        /// <summary>
        /// 取指定对象评论 条数
        /// </summary>
        /// <param name="targetID"></param>
        /// <param name="type"></param>
        /// <param name="count"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public CommentCollection GetComments(int targetID, CommentType type, int count)
        {
            if (targetID <= 0)
            {
                ThrowError(new InvalidParamError("targetID"));
                return(new CommentCollection());
            }
            string            key      = string.Format(cacheKey_List_Space, targetID, type);
            CommentCollection comments = new CommentCollection();

            if (CacheUtil.TryGetValue <CommentCollection>(key, out comments))
            {
                return(comments);
            }

            comments = CommentDao.Instance.GetComments(targetID, type, count);

            CacheUtil.Set <CommentCollection>(key, comments);

            return(comments);
        }
예제 #17
0
        /// <summary>
        /// 移除版块的主题列表缓存 同时更新主题缓存
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="threadIDs">要更新的主题缓存,如果没有传NULL</param>
        public static void ClearForumCache(int forumID, IEnumerable <int> threadIDs)
        {
            if (s_ForumCacheKeys == null)
            {
                return;
            }

            List <string> tempKeys;

            if (s_ForumCacheKeys.TryGetValue(forumID, out tempKeys))
            {
                List <string>      keys          = new List <string>(tempKeys);
                ThreadCollectionV5 cachedThreads = new ThreadCollectionV5();
                foreach (string key in keys)
                {
                    ThreadCollectionV5 tempThreads;
                    if (CacheUtil.TryGetValue <ThreadCollectionV5>(key, out tempThreads))
                    {
                        foreach (BasicThread thread in tempThreads)
                        {
                            if (cachedThreads.ContainsKey(thread.ThreadID) == false)
                            {
                                cachedThreads.Add(thread);
                            }
                        }
                        CacheUtil.Remove(key);
                    }
                }

                if (cachedThreads.Count > 0)
                {
                    UpdateAllCachedThreadsRemoveThreads(cachedThreads, null, null);
                }
            }

            if (threadIDs != null)
            {
                UpdateCache(threadIDs);
            }
        }
예제 #18
0
파일: DoingBO.cs 프로젝트: zhangbo27/bbsmax
        /// <summary>
        /// 获取用户的记录包含当前页的记录的评论(通过记录的CommentList属性访问)
        /// </summary>
        /// <param name="visitorID">访问者ID</param>
        /// <param name="doingOwnerID">数据所有者ID</param>
        /// <param name="pageNumber">数据分页每页条数</param>
        /// <param name="pageSize">数据分页当前页码</param>
        /// <returns></returns>
        public DoingCollection GetUserDoingsWithComments(int visitorID, int doingOwnerID, int pageNumber, int pageSize)
        {
            pageNumber = pageNumber <= 0 ? 1 : pageNumber;

            pageSize = pageSize <= 0 ? Consts.DefaultPageSize : pageSize;

            if (ValidateUserID(visitorID) == false || ValidateUserID(doingOwnerID) == false)
            {
                return(null);
            }

            DoingCollection doings = null;

            DataAccessLevel dataAccessLevel = GetDataAccessLevel(visitorID, doingOwnerID);

            #region 获取TotalCount缓存

            int?totalCount = null;

            string totalCountCacheKey = GetCacheKeyForUserDoingsTotalCount(doingOwnerID, dataAccessLevel);

            bool totalCountCached = CacheUtil.TryGetValue(totalCountCacheKey, out totalCount);

            #endregion

            doings = DoingDao.Instance.GetUserDoingsWithComments(doingOwnerID, dataAccessLevel, pageNumber, pageSize, ref totalCount);

            #region 设置TotalCount缓存

            if (totalCountCached == false)
            {
                CacheUtil.Set(totalCountCacheKey, totalCount);
            }

            #endregion

            ProcessKeyword(doings, ProcessKeywordMode.TryUpdateKeyword);

            return(doings);
        }
예제 #19
0
파일: TagBO.cs 프로젝트: zhangbo27/bbsmax
        public TagCollection GetUserTags(int userID, TagType type)
        {
            if (ValidateUserID(userID) == false)
            {
                return(null);
            }

            string cacheKey = GetCacheKeyForUserTags(type, userID);

            TagCollection tags = null;

            if (CacheUtil.TryGetValue <TagCollection>(cacheKey, out tags))
            {
                return(tags);
            }

            tags = TagDao.Instance.GetUserTags(userID, type);

            CacheUtil.Set <TagCollection>(cacheKey, tags);

            return(tags);
        }
예제 #20
0
        /// <summary>
        /// 返回指定用户的最近访问者数
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public VisitorCollection GetVisitors(int userID, int count)
        {
            if (userID <= 0)
            {
                ThrowError(new InvalidParamError("userID"));
                return(new VisitorCollection());
            }

            string key = string.Format(cacheKey_List_Space, userID);

            VisitorCollection visitors = new VisitorCollection();

            if (CacheUtil.TryGetValue <VisitorCollection>(key, out visitors))
            {
                return(visitors);
            }

            visitors = SpaceDao.Instance.SelectVisitors(userID, count);
            CacheUtil.Set <VisitorCollection>(key, visitors);

            return(visitors);
        }
예제 #21
0
        /// <summary>
        /// 返回所有自定义分组
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <returns></returns>
        public EmoticonGroupCollection GetEmoticonGroups(int userID)
        {
            if (!CanUseEmoticon(userID))
            {
                return(new EmoticonGroupCollection());
            }

            string cacheKey = string.Format(cacheKey_EmoticonUserGroups, userID);
            EmoticonGroupCollection groups;

            if (!CacheUtil.TryGetValue <EmoticonGroupCollection>(cacheKey, out groups))
            {
                groups = EmoticonDao.Instance.GetEmoticonGroups(userID);

                //if (Groups.Count == 0)
                //    Groups.Add(CreateDefaultGroup(userID));

                CacheUserEmoticonGroups(userID, groups);
            }

            return(groups);
        }
예제 #22
0
        public EmoticonGroup GetEmoticonGroup(int userID, int groupID)
        {
            string cacheKey = string.Format(cacheKey_EmoticonUserGroups, userID);

            EmoticonGroupCollection groups;

            if (CacheUtil.TryGetValue <EmoticonGroupCollection>(cacheKey, out groups))
            {
                if (groups.GetValue(groupID) != null)
                {
                    return(groups.GetValue(groupID));
                }
            }
            else
            {
                EmoticonGroup group = EmoticonDao.Instance.GetEmoticonGroup(userID, groupID);
                //并不进行单个分组缓存, 通常是用户的全部分组缓存
                CacheUtil.Remove(cacheKey);
                return(group);
            }
            return(null);
        }
예제 #23
0
        public void UpdateTopUserShowsWhenVisited(int userID, int price)
        {
            PointShowUserCollection users;

            if (CacheUtil.TryGetValue <PointShowUserCollection>(showUsersKey, out users))
            {
                PointShowUser user = users.GetValue(userID);
                if (user == null)
                {
                    return;
                }

                //如果比缓存里最小的单价还小  那么需要清除缓存
                if (users[users.Count - 1].Price > price)
                {
                    ClearTopUserShowsCache();
                    return;
                }


                PointShowUserCollection newUsers = new PointShowUserCollection();
                foreach (PointShowUser tempUser in users)
                {
                    if (tempUser.UserID == userID)
                    {
                        continue;
                    }

                    if (price > tempUser.Price)
                    {
                        newUsers.Add(tempUser);
                    }
                    newUsers.Add(tempUser);
                }

                CacheUtil.Set <PointShowUserCollection>(showUsersKey, newUsers);
            }
        }
예제 #24
0
        public Club GetClub(int clubID)
        {
            if (ValidateClubID(clubID) == false)
            {
                return(null);
            }

            Club club = null;

            string cacheKey = GetCacheKeyForClub(clubID);

            if (CacheUtil.TryGetValue <Club>(cacheKey, out club) == false)
            {
                club = ClubDao.Instance.GetClub(clubID);

                if (club != null)
                {
                    CacheUtil.Set <Club>(cacheKey, club);
                }
            }

            return(club);
        }
예제 #25
0
        /// <summary>
        /// 移除AllCachedThreads里的缓存
        /// </summary>
        /// <param name="threads"></param>
        /// <param name="forumID"></param>
        /// <param name="excludeCacheKeys">这些缓存将不去检查(这样就会去移除AllCachedThreads)</param>
        private static void UpdateAllCachedThreadsRemoveThreads(ThreadCollectionV5 threads, int?forumID, ThreadOrderType?excludeOrderType, params string[] excludeCacheKeys)
        {
            if (s_AllCachedThreads == null)
            {
                return;
            }

            if (threads == null || threads.Count == 0)
            {
                return;
            }

            List <string> cacheKeys = null;


            if (/*forumID != null &&*/ s_ForumCacheKeys != null)
            {
                List <int>            checkForumIDs = new List <int>();
                StickThreadCollection stickThreads  = null;
                foreach (BasicThread thread in threads)
                {
                    if (thread.ThreadStatus == Enums.ThreadStatus.Sticky ||
                        thread.ThreadStatus == Enums.ThreadStatus.GlobalSticky)
                    {
                        if (stickThreads == null)
                        {
                            stickThreads = PostBOV5.Instance.GetAllStickThreadInForums();
                        }
                        foreach (StickThread stick in stickThreads)
                        {
                            if (stick.ThreadID == thread.ThreadID && checkForumIDs.Contains(stick.ForumID) == false)
                            {
                                checkForumIDs.Add(stick.ForumID);
                            }
                        }
                    }

                    if (forumID == null)
                    {
                        if (checkForumIDs.Contains(thread.ForumID) == false)
                        {
                            checkForumIDs.Add(thread.ForumID);
                        }
                    }
                }

                if (forumID != null)
                {
                    checkForumIDs.Add(forumID.Value);
                    if (forumID.Value != 0)//还要从MovedThreads里检查
                    {
                        checkForumIDs.Add(0);
                    }
                    else//MovedThreads
                    {
                        foreach (BasicThread thread in threads)
                        {
                            if (checkForumIDs.Contains(thread.ForumID))
                            {
                                continue;
                            }
                            checkForumIDs.Add(thread.ForumID);
                        }
                    }
                }
                else
                {
                    checkForumIDs.Add(0);
                }

                foreach (int tempForumID in checkForumIDs)
                {
                    List <string> tempKeys = null;
                    s_ForumCacheKeys.TryGetValue(tempForumID, out tempKeys);

                    if (tempKeys != null)
                    {
                        if (cacheKeys == null)
                        {
                            cacheKeys = new List <string>(tempKeys);
                        }
                        else
                        {
                            cacheKeys.AddRange(tempKeys);
                        }
                    }
                }

                /*
                 * List<string> tempCacheKeys = null;
                 * s_ForumCacheKeys.TryGetValue(forumID.Value, out tempCacheKeys);
                 *
                 * if (tempCacheKeys != null)
                 *  cacheKeys = new List<string>(tempCacheKeys);
                 * //cacheKeys = s_ForumCacheKeys[forumID.Value];
                 *
                 * if (forumID.Value != 0)// 还要从MovedThreads里检查
                 * {
                 *  List<string> tempKeys = null;
                 *  s_ForumCacheKeys.TryGetValue(0, out tempKeys);
                 *  if (tempKeys != null)
                 *  {
                 *      if (cacheKeys == null)
                 *          cacheKeys = new List<string>(tempKeys);
                 *      else
                 *          cacheKeys.AddRange(tempKeys);
                 *  }
                 * }
                 * else//MovedThreads
                 * {
                 *  List<int> tempForumIDs = new List<int>();
                 *  foreach (BasicThread thread in threads)
                 *  {
                 *      if (tempForumIDs.Contains(thread.ForumID))
                 *          continue;
                 *      tempForumIDs.Add(thread.ForumID);
                 *
                 *      List<string> tempKeys = null;
                 *      s_ForumCacheKeys.TryGetValue(thread.ForumID, out tempKeys);
                 *
                 *      if (tempKeys != null)
                 *      {
                 *          if (cacheKeys == null)
                 *              cacheKeys = new List<string>(tempKeys);
                 *          else
                 *              cacheKeys.AddRange(tempKeys);
                 *      }
                 *  }
                 * }
                 */
            }


            lock (s_AllCachedThreadsLocker)
            {
                if (s_AllCachedThreads == null)
                {
                    return;
                }

                foreach (BasicThread thread in threads)
                {
                    //检查其他所有缓存  如果有该主题的缓存 就不从AllCachedThreads中移除  否则移除
                    if (s_AllCachedThreads != null && s_AllCachedThreads.ContainsKey(thread.ThreadID))
                    {
                        bool remove = true;
                        if (cacheKeys != null)
                        {
                            //检查当前版块中的所有缓存的主题
                            foreach (string key in cacheKeys)
                            {
                                if (excludeCacheKeys != null)
                                {
                                    bool exclude = false;
                                    foreach (string eck in excludeCacheKeys)
                                    {
                                        if (string.Compare(eck, key, true) == 0)
                                        {
                                            exclude = true;
                                            break;
                                        }
                                    }

                                    if (exclude)
                                    {
                                        continue;
                                    }
                                }

                                ThreadCollectionV5 tempThreads;
                                if (CacheUtil.TryGetValue <ThreadCollectionV5>(key, out tempThreads))
                                {
                                    if (tempThreads.ContainsKey(thread.ThreadID))
                                    {
                                        remove = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (remove == true && s_AllForumTopThreads != null)
                        {
                            //检查所有版块中的所有缓存的主题
                            foreach (KeyValuePair <ThreadOrderType, ThreadCollectionV5> pair in s_AllForumTopThreads)
                            {
                                if (excludeOrderType != null && excludeOrderType.Value == pair.Key)
                                {
                                    continue;
                                }

                                if (pair.Value.ContainsKey(thread.ThreadID))
                                {
                                    remove = false;
                                    break;
                                }
                            }
                        }

                        if (remove && s_AllCachedThreads != null)
                        {
                            s_AllCachedThreads.Remove(thread.ThreadID);
                        }
                    }
                }
            }
        }
예제 #26
0
        private static void SetForumThreadsCache(int forumID, ThreadOrderType orderType, ThreadCollectionV5 threads, bool updateAllCachedThreads)
        {
            string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, GetTotalCacheCount(orderType));

            List <string> cacheKeys = null;

            if (s_ForumCacheKeys != null)
            {
                if (!s_ForumCacheKeys.TryGetValue(forumID, out cacheKeys))
                {
                    cacheKeys = new List <string>();
                    cacheKeys.Add(cacheKey);
                    s_ForumCacheKeys.Add(forumID, cacheKeys);
                }
                else if (cacheKeys.Contains(cacheKey) == false)
                {
                    cacheKeys.Add(cacheKey);
                }
                else//原来就有的 移除
                {
                    if (updateAllCachedThreads)
                    {
                        ThreadCollectionV5 tempThreads;
                        if (CacheUtil.TryGetValue <ThreadCollectionV5>(cacheKey, out tempThreads))
                        {
                            //if (updateAllCachedThreads)
                            UpdateAllCachedThreadsRemoveThreads(tempThreads, forumID, null, new string[] { cacheKey });
                            //else
                            //    UpdateAllCachedThreadsRemoveThreads(tempThreads, forumID, null);
                        }
                    }
                }
            }
            else
            {
                s_ForumCacheKeys = new Dictionary <int, List <string> >();
                cacheKeys        = new List <string>();
                cacheKeys.Add(cacheKey);
                s_ForumCacheKeys.Add(forumID, cacheKeys);
            }

            CacheTime?       cacheTime;
            CacheExpiresType expiresType;
            int?minute;

            GetCacheType(orderType, out cacheTime, out expiresType, out minute);

            if (minute == null)
            {
                CacheUtil.Set <ThreadCollectionV5>(cacheKey, threads, cacheTime.Value, expiresType, null, CacheItemPriority.NotRemovable, delegate(string key, object value, CacheItemRemovedReason reason)
                {
                    //cacheKeys.Remove(key);
                    ThreadCollectionV5 removedThreads = (ThreadCollectionV5)value;

                    UpdateAllCachedThreadsRemoveThreads(removedThreads, forumID, null);
                });
            }
            else
            {
                CacheUtil.Set <ThreadCollectionV5>(cacheKey, threads, minute.Value, expiresType, null, CacheItemPriority.NotRemovable, delegate(string key, object value, CacheItemRemovedReason reason)
                {
                    //cacheKeys.Remove(key);
                    ThreadCollectionV5 removedThreads = (ThreadCollectionV5)value;

                    UpdateAllCachedThreadsRemoveThreads(removedThreads, forumID, null);
                });
            }

            if (updateAllCachedThreads)
            {
                UpdateAllCachedThreadsAddThreads(threads);
            }
        }
예제 #27
0
        public static bool CompressStaticContent(HttpContext context)
        {
            if (Globals.UseStaticCompress == false || StringUtil.EndsWithIgnoreCase(context.Request.PhysicalPath, ".fast.aspx") == false)
            {
                return(false);
            }

            SetInstalledKey(context);

            string physicalPath = context.Request.PhysicalPath.Remove(context.Request.PhysicalPath.Length - 10);
            string contentType  = null;

            if (StringUtil.EndsWithIgnoreCase(physicalPath, ".css"))
            {
                contentType = "text/css";
            }

            else if (StringUtil.EndsWithIgnoreCase(physicalPath, ".js"))
            {
                contentType = "application/x-javascript";
            }

            else
            {
                return(false);
            }

            CompressingType compressingType = RequestUtil.GetCompressingType(context);

            context.Response.ClearHeaders();

            if (compressingType == CompressingType.None)
            {
                if (File.Exists(physicalPath))
                {
                    DateTime lastModified = File.GetLastWriteTime(physicalPath);

                    if (context.Request.Headers["If-Modified-Since"] != null)
                    {
                        DateTime ifModifiedSince;

                        if (DateTime.TryParse(context.Request.Headers["If-Modified-Since"].Split(';')[0], out ifModifiedSince))
                        {
                            if (ifModifiedSince > lastModified.AddSeconds(-1))
                            {
                                context.Response.StatusCode        = 304;
                                context.Response.StatusDescription = "Not Modified";
                                context.ApplicationInstance.CompleteRequest();
                                return(true);
                            }
                        }
                    }

                    context.Response.ContentType = contentType;

                    if (lastModified < DateTime.Now)
                    {
                        context.Response.Cache.SetLastModified(lastModified);
                    }

                    context.Response.Cache.SetETag(lastModified.Ticks.ToString());
                    context.Response.BinaryWrite(File.ReadAllBytes(physicalPath));

                    context.ApplicationInstance.CompleteRequest();
                }
            }
            else
            {
                string cacheKey = string.Concat("fast.aspx/", compressingType.ToString(), "/", physicalPath);

                FastAspxCacheData cacheData = null;

                if (CacheUtil.TryGetValue <FastAspxCacheData>(cacheKey, out cacheData) == false)
                {
                    if (File.Exists(physicalPath))
                    {
                        cacheData = new FastAspxCacheData();

                        using (MemoryStream stream = new MemoryStream())
                        {
                            Stream compressStream = null;

                            if (compressingType == CompressingType.GZip)
                            {
                                compressStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Compress);
                            }
                            else if (compressingType == CompressingType.Deflate)
                            {
                                compressStream = new System.IO.Compression.DeflateStream(stream, System.IO.Compression.CompressionMode.Compress);
                            }

                            byte[] buffer = File.ReadAllBytes(physicalPath);

                            compressStream.Write(buffer, 0, buffer.Length);
                            compressStream.Close();
                            compressStream.Dispose();
                            compressStream = null;

                            cacheData.Data = stream.ToArray();
                        }

                        cacheData.LastModified = File.GetLastWriteTime(physicalPath);

                        CacheUtil.Set <FastAspxCacheData>(cacheKey, cacheData, CacheTime.Long, CacheExpiresType.Sliding, new CacheDependency(physicalPath));
                    }
                }

                if (cacheData != null && cacheData.Data.Length > 0)
                {
                    if (context.Request.Headers["If-Modified-Since"] != null)
                    {
                        DateTime ifModifiedSince;

                        if (DateTime.TryParse(context.Request.Headers["If-Modified-Since"].Split(';')[0], out ifModifiedSince))
                        {
                            if (ifModifiedSince > cacheData.LastModified.AddSeconds(-1))
                            {
                                context.Response.StatusCode        = 304;
                                context.Response.StatusDescription = "Not Modified";
                                context.ApplicationInstance.CompleteRequest();
                                return(true);
                            }
                        }
                    }

                    context.Response.Cache.VaryByHeaders["Accept-Encoding"] = true;

                    context.Response.ContentType = contentType;

                    if (compressingType == CompressingType.GZip)
                    {
                        context.Response.AppendHeader("Content-Encoding", "gzip");
                    }
                    else
                    {
                        context.Response.AppendHeader("Content-Encoding", "deflate");
                    }

                    if (cacheData.LastModified < DateTime.Now)
                    {
                        context.Response.Cache.SetLastModified(cacheData.LastModified);
                    }

                    context.Response.Cache.SetETag(cacheData.LastModified.Ticks.ToString());
                    context.Response.BinaryWrite(cacheData.Data);

                    context.ApplicationInstance.CompleteRequest();
                }
            }

            return(true);
        }
예제 #28
0
파일: DiskBO.cs 프로젝트: zhangbo27/bbsmax
        /// <summary>
        /// ȡ�ø�Ŀ¼�ļ�����һ��Ŀ¼�������ļ����ļ��С�
        /// </summary>
        /// <param name="userID">��ǰ�û���ID��</param>
        /// <param name="directoryID">���ļ��е�ID��</param>
        /// <param name="directories">������ļ���ʵ��<see cref="DiskDirectory"/>���б��</param>
        /// <param name="files">������ļ�ʵ��<see cref="DiskFile"/>�б��</param>
        /// <param name="totalSize">��ǰ��Ŀ¼���������ļ��Ĵ�С��</param>
        /// <returns>����ɹ�ȡ���򷵻�<c>true</c>,���򷵻�<c>false</c>��</returns>
        public List <IFile> GetDiskFiles(int userID, int directoryID, out DiskDirectoryCollection directories, out DiskFileCollection files, FileOrderBy orderBy, bool isDesc, ExtensionList fileTypes)
        {
            List <IFile> dirAndFiles;
            int          fileTypeKey          = fileTypes == null || fileTypes.Count == 0?0: fileTypes.ToString("").GetHashCode();
            string       cachekeyOfDirectorys = string.Format(cacheKey_directoryList, userID, directoryID);
            string       cacheKeyOfFiles      = string.Format(cacheKey_fileList, userID, directoryID, fileTypeKey);

            if (!CacheUtil.TryGetValue <DiskFileCollection>(cacheKey_fileList, out files) ||
                CacheUtil.TryGetValue <DiskDirectoryCollection>(cachekeyOfDirectorys, out directories))
            {
                DiskDao.Instance.GetDiskFiles(userID, directoryID, out directories, out files);
                CacheUtil.Set <DiskFileCollection>(cacheKeyOfFiles, files);
                CacheUtil.Set <DiskDirectoryCollection>(cachekeyOfDirectorys, directories);
            }

            /*���´������ܺܲ ԭ����3.0��BO������Ӧ�����ܣ� ��ʱ��Ӧ����������ѭ������*/

            string cacheKeyOfAllFiles = string.Format(cacheKey_directoryList, userID, directoryID, orderBy, isDesc);

            if (!CacheUtil.TryGetValue <List <IFile> >(cacheKeyOfAllFiles, out dirAndFiles))
            {
                dirAndFiles = new List <IFile>(directories.Count + files.Count);


                if (orderBy != FileOrderBy.None)
                {
                    DiskFile temp;
                    int      v;
                    for (int i = 0; i < files.Count - 1; i++)
                    {
                        for (int j = i + 1; j < files.Count; j++)
                        {
                            v = CompareFile(files[i], files[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    temp     = files[i];
                                    files[i] = files[j];
                                    files[j] = temp;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    temp     = files[j];
                                    files[j] = files[i];
                                    files[i] = temp;
                                }
                            }
                        }
                    }

                    DiskDirectory tempDir;

                    for (int i = 0; i < directories.Count - 1; i++)
                    {
                        for (int j = i + 1; j < directories.Count; j++)
                        {
                            v = CompareFile(directories[i], directories[j], orderBy);
                            if (isDesc)
                            {
                                if (v > 0)
                                {
                                    tempDir        = directories[i];
                                    directories[i] = directories[j];
                                    directories[j] = tempDir;
                                }
                            }
                            else
                            {
                                if (v < 0)
                                {
                                    tempDir        = directories[j];
                                    directories[j] = directories[i];
                                    directories[i] = tempDir;
                                }
                            }
                        }
                    }
                }

                if (orderBy == FileOrderBy.Type && isDesc == false)
                {
                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }
                        dirAndFiles.Add(file);
                    }
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }
                }
                else
                {
                    foreach (IFile dir in directories)
                    {
                        dirAndFiles.Add(dir);
                    }

                    foreach (DiskFile file in files)
                    {
                        if (fileTypes != null && fileTypes.Count > 0 && !fileTypes.Contains(file.ExtensionName))
                        {
                            continue;
                        }

                        dirAndFiles.Add(file);
                    }
                }

                CacheUtil.RemoveBySearch(string.Format(cacheKey_allFileListRoot, userID, directoryID));
                CacheUtil.Set <List <IFile> >(cacheKeyOfAllFiles, dirAndFiles);
            }
            return(dirAndFiles);
        }