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); }
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); }
/// <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; } } } } } }
public void ClearPostsCache() { lock (m_CachedPagePostsLocker) { cachedPagePosts = null; ThreadContent = null; ClearOtherPostsCache(); } }
public override void UpdatePostCache(PostV5 post) { base.UpdatePostCache(post); if (BestPostID == post.PostID) { BestPost = post; } }
protected void Page_Load(object sender, EventArgs e) { m_Action = _Request.Get("action", Method.Get); m_TargetID = _Request.Get("targetid", Method.Get, 0); switch (m_Action) { case "post": MaxLabs.bbsMax.Entities.PostV5 post = PostBOV5.Instance.GetPost(m_TargetID, false); if (post != null) { ManageForumPermissionSetNode permission = AllSettings.Current.ManageForumPermissionSet.Nodes.GetPermission(post.ForumID); if (permission.Can(My, ManageForumPermissionSetNode.ActionWithTarget.UpdateThreads, post.UserID) || permission.Can(My, ManageForumPermissionSetNode.ActionWithTarget.UpdatePosts, post.UserID)) { m_UserID = post.UserID; break;; } } m_UserID = MyUserID; break; case "user": if (UserBO.Instance.CanEditUserProfile(My, m_TargetID)) { m_UserID = m_TargetID; } else { m_UserID = MyUserID; } break; default: m_UserID = MyUserID; break; } SetPager("list", null, PageNumber, PageSize, CurrentGroup.TotalEmoticons); //SetPager("list", string.Format("emoticons.aspx?id={0}&page={1}&groupid={2}&ispanel={3}&from={4}&callback={5}", // _Request.Get("id", Method.Get), // "{0}", // _Request.Get("groupid", Method.Get), // IsPanel ? "true" : "false", // _Request.Get("from", Method.Get), // Callback // ), // PageNumber, // PageSize, // CurrentGroup.TotalEmoticons // ); }
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; } } }