コード例 #1
0
        public PostV5 GetPostFromCache(int postID)
        {
            PostV5 threadContent = ThreadContent;

            if (threadContent != null && threadContent.PostID == postID)
            {
                return(threadContent);
            }

            PostCollectionV5[] cachedPosts = cachedPagePosts;

            if (cachedPosts == null)
            {
                return(null);
            }

            PostV5 post;

            for (int i = 0; i < CacheFirstPageCount + CacheLastPageCount; i++)
            {
                PostCollectionV5 tempPosts = cachedPosts[i];
                if (tempPosts != null && tempPosts.TryGetValue(postID, out post))
                {
                    return(post);
                }
            }
            return(null);
        }
コード例 #2
0
        public bool ContainPostCache(int postID)
        {
            PostV5 threadContent = ThreadContent;

            if (threadContent != null && threadContent.PostID == postID)
            {
                return(true);
            }

            PostCollectionV5[] cachedPosts = cachedPagePosts;

            if (cachedPosts == null)
            {
                return(false);
            }

            for (int i = 0; i < CacheFirstPageCount + CacheLastPageCount; i++)
            {
                PostCollectionV5 tempPosts = cachedPosts[i];
                if (tempPosts != null && tempPosts.ContainsKey(postID))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// 更新缓存 如果缓存里不存在该帖子  则不进行任何操作
        /// </summary>
        /// <param name="post"></param>
        public virtual void UpdatePostCache(PostV5 post)
        {
            lock (m_CachedPagePostsLocker)
            {
                PostV5 threadContent = ThreadContent;

                if (threadContent != null && post.PostID == threadContent.PostID)
                {
                    ThreadContent = post;
                }

                else
                {
                    if (cachedPagePosts != null)
                    {
                        for (int i = 0; i < CacheFirstPageCount + CacheLastPageCount; i++)
                        {
                            PostCollectionV5 posts = cachedPagePosts[i];
                            if (posts != null && posts.ContainsKey(post.PostID))
                            {
                                posts.Set(post);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 临时 使用的
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <returns></returns>
        public bool ContainPageCache(int pageNumber)
        {
            if (cachedPagePosts == null)
            {
                return(false);
            }
            if (pageNumber <= CacheFirstPageCount || pageNumber > TotalPages - CacheLastPageCount)
            {
                PostCollectionV5 posts = cachedPagePosts[GetCachedPageIndex(pageNumber)];
                if (posts == null || posts.Count == 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
 public PostCollectionV5(PostCollectionV5 posts)
     : base(posts)
 {
 }
コード例 #6
0
        public void AddPostToCache(PostV5 post)
        {
            if (cachedPagePosts == null)
            {
                return;
            }

            int pageSize = AllSettings.Current.BbsSettings.PostsPageSize;

            lock (m_CachedPagePostsLocker)
            {
                int index = GetCachedPageIndex(TotalPages);
                //int total = TotalRepliesForPage + 1;
                //if (total % AllSettings.Current.BbsSettings.PostsPageSize > 0)
                //{
                //    //如果最后页 没缓存 那就不加入
                //    if (cachedPagePosts[index] == null)
                //    {
                //        return;
                //    }
                //}

                PostCollectionV5 posts = cachedPagePosts[index];

                if (posts == null)
                {
                    posts = new PostCollectionV5();
                }

                if (posts.Count > 0)
                {
                    int tempi = -1;
                    for (int i = posts.Count - 1; i > -1; i--)
                    {
                        if (post.PostID < posts[i].PostID)
                        {
                            tempi = i;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (tempi > -1)
                    {
                        posts.Insert(tempi, post);
                        post = posts[posts.Count - 1];
                    }
                }

                if (posts.Count >= pageSize) //需要新的页面 缓存
                {
                    PostCollectionV5 tempPosts = new PostCollectionV5();
                    tempPosts.Add(post);

                    if (index == CacheFirstPageCount + CacheLastPageCount - 1)//已经是最后一页
                    {
                        //需要新的页面 则把LastCachePage的最前面一页 删除 后面的页面往前挪一个位置  新页加到后面
                        PostCollectionV5[] tempPages = new PostCollectionV5[CacheFirstPageCount + CacheLastPageCount];
                        for (int i = 0; i < CacheFirstPageCount + CacheLastPageCount; i++)
                        {
                            if (i < CacheFirstPageCount)
                            {
                                tempPages[i] = cachedPagePosts[i];
                            }
                            else
                            {
                                if (i + 1 < CacheFirstPageCount + CacheLastPageCount)
                                {
                                    tempPages[i] = cachedPagePosts[i + 1];
                                }
                            }
                        }

                        tempPages[CacheFirstPageCount + CacheLastPageCount - 1] = tempPosts;
                        cachedPagePosts = tempPages;
                    }
                    else
                    {
                        cachedPagePosts[index + 1] = tempPosts;
                    }
                }
                else
                {
                    posts.Add(post);
                    cachedPagePosts[index] = posts;
                }
            }
        }