Exemple #1
0
        private static void GetCacheType(ThreadOrderType orderType, out CacheTime?cacheTime, out CacheExpiresType expiresType, out int?minute)
        {
            minute = null;
            switch (orderType)
            {
            case ThreadOrderType.AllForumTopWeekViewThreads:
            case ThreadOrderType.ForumTopWeekViewThreads:
                cacheTime   = null;
                minute      = AllSettings.Current.CacheSettings.WeekPostCacheTime;
                expiresType = CacheExpiresType.Absolute;
                break;

            case ThreadOrderType.ForumTopDayViewThreads:
            case ThreadOrderType.AllForumTopDayViewThreads:
                cacheTime   = null;
                minute      = AllSettings.Current.CacheSettings.DayPostCacheTime;
                expiresType = CacheExpiresType.Absolute;
                break;

            case ThreadOrderType.MovedThreads:
                cacheTime   = null;
                minute      = 20;
                expiresType = CacheExpiresType.Absolute;
                break;

            default:
                cacheTime   = CacheTime.Default;
                expiresType = CacheExpiresType.Sliding;
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// 要缓存的条数
        /// </summary>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static int GetTotalCacheCount(ThreadOrderType orderType)
        {
            switch (orderType)
            {
            case ThreadOrderType.ForumTopThreadsBySortOrder:
                return(300);

            case ThreadOrderType.ForumTopThreadsByThreadID:
            case ThreadOrderType.ForumTopThreadsByLastPostID:
            case ThreadOrderType.ForumTopValuedThreads:
            case ThreadOrderType.ForumTopDayHotThreads:
            case ThreadOrderType.ForumTopWeekHotThreads:
            case ThreadOrderType.ForumTopDayViewThreads:
            case ThreadOrderType.ForumTopWeekViewThreads:
                return(30);

            case ThreadOrderType.AllForumTopThreadsByThreadID:
            case ThreadOrderType.AllForumTopThreadsByLastPostID:
            case ThreadOrderType.AllForumTopValuedThreads:
            case ThreadOrderType.AllForumTopWeekHotThreads:
            case ThreadOrderType.AllForumTopDayHotThreads:
            case ThreadOrderType.AllForumTopWeekViewThreads:
            case ThreadOrderType.AllForumTopDayViewThreads:
                return(50);

            case ThreadOrderType.MovedThreads:
            case ThreadOrderType.GlobalStickThreads:
            case ThreadOrderType.ForumStickThreads:
                return(int.MaxValue);

            default:
                return(0);
            }
        }
Exemple #3
0
 public static void SetForumThreadsCache(int forumID, ThreadOrderType orderType, ThreadCollectionV5 threads)
 {
     lock (s_ForumLockers[forumID])
     {
         SetForumThreadsCache(forumID, orderType, threads, true);
     }
 }
Exemple #4
0
 /// <summary>
 /// 判断是否是在缓存里   还是在静态变量里
 /// </summary>
 /// <param name="orderType"></param>
 /// <returns></returns>
 private static bool IsInCache(ThreadOrderType orderType)
 {
     if (s_AllForumTopThreadsLockers != null)
     {
         return(s_AllForumTopThreadsLockers.ContainsKey(orderType) == false);
     }
     return(true);
 }
Exemple #5
0
        /// <summary>
        /// 已经被缓存的个数
        /// </summary>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static int GetTopThreadCachedCount(ThreadOrderType orderType)
        {
            ThreadCollectionV5 threads = GetAllForumThreads(orderType);

            if (threads == null)
            {
                return(0);
            }
            else
            {
                return(threads.Count);
            }
        }
Exemple #6
0
        /// <summary>
        /// 已经被缓存的个数
        /// </summary>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static int GetForumThreadCachedCount(int forumID, ThreadOrderType orderType)
        {
            ThreadCollectionV5 threads = GetForumThreads(forumID, orderType);

            if (threads == null)
            {
                return(0);
            }
            else
            {
                return(threads.Count);
            }
        }
Exemple #7
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);
        }
Exemple #8
0
        /// <summary>
        /// 将主题加入列表  如果不存在则加入列表最前面  如果存在则提到最前面 并更新
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="orderType"></param>
        /// <param name="thread"></param>
        public static void AddForumThread(int forumID, ThreadOrderType orderType, BasicThread thread)
        {
            object obj;

            if (s_ForumLockers.TryGetValue(forumID, out obj) == false)
            {
                obj = new object();
                s_ForumLockers.Add(forumID, obj);
            }

            lock (obj)
            {
                ThreadCollectionV5 cachedThreads = GetForumThreads(forumID, orderType);

                if (cachedThreads != null)
                {
                    ThreadCollectionV5 threads = new ThreadCollectionV5(cachedThreads);
                    int count = GetTotalCacheCount(orderType);
                    ThreadCollectionV5 removedThreads = new ThreadCollectionV5();

                    BasicThread tempThread = threads.GetValue(thread.ThreadID);
                    if (tempThread != null)
                    {
                        UpdateThreadCache(tempThread, thread);
                        threads.RemoveByKey(thread.ThreadID);
                        threads.Insert(0, tempThread);
                    }
                    else
                    {
                        UpdateAllCachedThreadsAddThreads(thread);
                        threads.Insert(0, thread);
                    }


                    if (threads.Count > count)
                    {
                        removedThreads.Add(threads[threads.Count - 1]);
                        threads.RemoveAt(threads.Count - 1);
                    }

                    if (removedThreads.Count > 0)
                    {
                        string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, count);
                        UpdateAllCachedThreadsRemoveThreads(removedThreads, forumID, null, cacheKey);
                    }

                    SetForumThreadsCache(forumID, orderType, threads, false);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// 如获取整站的最新帖子等  跟具体版块无关
        /// </summary>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static ThreadCollectionV5 GetAllForumThreads(ThreadOrderType orderType)
        {
            if (IsInCache(orderType))
            {
                return(GetAllForumThreadsFromCache(orderType));
            }

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

            ThreadCollectionV5 threads;

            s_AllForumTopThreads.TryGetValue(orderType, out threads);

            return(threads);
        }
Exemple #10
0
        public static void ClearAllForumThreadsCache(ThreadOrderType orderType)
        {
            if (IsInCache(orderType))
            {
                ClearForumThreadsCache(0, orderType);
                return;
            }

            if (s_AllForumTopThreads == null)
            {
                return;
            }

            ThreadCollectionV5 threads;

            if (s_AllForumTopThreads.TryGetValue(orderType, out threads))
            {
                s_AllForumTopThreads.Remove(orderType);
                UpdateAllCachedThreadsRemoveThreads(threads, null, null);
            }
        }
Exemple #11
0
        public static void SetAllForumThreads(ThreadOrderType orderType, ThreadCollectionV5 threads)
        {
            if (IsInCache(orderType))
            {
                SetAllForumThreadsToCache(orderType, threads);
                return;
            }

            lock (s_AllForumTopThreadsLocker)
            {
                if (s_AllForumTopThreads == null)
                {
                    s_AllForumTopThreads = new Dictionary <ThreadOrderType, ThreadCollectionV5>();
                }

                if (s_AllForumTopThreads.ContainsKey(orderType))
                {
                    ThreadCollectionV5 removedThreads = new ThreadCollectionV5();
                    foreach (BasicThread thread in s_AllForumTopThreads[orderType])
                    {
                        if (threads.ContainsKey(thread.ThreadID) == false)
                        {
                            removedThreads.Add(thread);
                        }
                    }

                    UpdateAllCachedThreadsRemoveThreads(removedThreads, null, orderType, null);
                    s_AllForumTopThreads[orderType] = threads;
                }
                else
                {
                    s_AllForumTopThreads.Add(orderType, threads);
                }
            }

            UpdateAllCachedThreadsAddThreads(threads);
        }
Exemple #12
0
 /// <summary>
 /// 已经被缓存的个数
 /// </summary>
 /// <param name="orderType"></param>
 /// <returns></returns>
 public static int GetForumThreadCachedCount(int forumID, ThreadOrderType orderType)
 {
     ThreadCollectionV5 threads = GetForumThreads(forumID, orderType);
     if (threads == null)
         return 0;
     else
         return threads.Count;
 }
Exemple #13
0
 /// <summary>
 /// 判断是否是在缓存里   还是在静态变量里
 /// </summary>
 /// <param name="orderType"></param>
 /// <returns></returns>
 private static bool IsInCache(ThreadOrderType orderType)
 {
     if (s_AllForumTopThreadsLockers != null)
     {
         return s_AllForumTopThreadsLockers.ContainsKey(orderType) == false;
     }
     return true;
 }
Exemple #14
0
        /// <summary>
        /// 如获取整站的最新帖子等  跟具体版块无关
        /// </summary>
        /// <param name="orderType"></param>
        /// <returns></returns>
        public static ThreadCollectionV5 GetAllForumThreads(ThreadOrderType orderType)
        {
            if (IsInCache(orderType))
            {
                return GetAllForumThreadsFromCache(orderType);
            }

            if (s_AllForumTopThreads == null)
                return null;

            ThreadCollectionV5 threads;

            s_AllForumTopThreads.TryGetValue(orderType, out threads);

            return threads;
        }
Exemple #15
0
        /// <summary>
        /// 将主题加入列表  如果不存在则加入列表最前面  如果存在则提到最前面 并更新
        /// </summary>
        /// <param name="orderType"></param>
        /// <param name="thread"></param>
        public static void AddAllForumThread(ThreadOrderType orderType, BasicThread thread)
        {
            if (IsInCache(orderType))
            {
                AddAllForumThreadToCache(orderType, thread);
                return;
            }

            int count = GetTotalCacheCount(orderType);

            lock (s_AllForumTopThreadsLocker)
            {
                if (s_AllForumTopThreads == null)
                {
                    return;
                    //AllForumTopThreads = new Dictionary<ThreadOrderType, ThreadCollectionV5>();
                }

                Dictionary<ThreadOrderType, ThreadCollectionV5> tempAllForumTopThreads = new Dictionary<ThreadOrderType, ThreadCollectionV5>();

                foreach (KeyValuePair<ThreadOrderType, ThreadCollectionV5> pair in s_AllForumTopThreads)
                {
                    tempAllForumTopThreads.Add(pair.Key, pair.Value);
                }

                lock (s_AllForumTopThreadsLockers[orderType])
                {
                    ThreadCollectionV5 temp;
                    tempAllForumTopThreads.TryGetValue(orderType, out temp);

                    if (temp == null)
                        return;

                    ThreadCollectionV5 threads = new ThreadCollectionV5(temp);
                    if (threads.Count == 0)
                    {
                        threads.Add(thread);

                        tempAllForumTopThreads[orderType] = threads;

                        UpdateAllCachedThreadsAddThreads(thread);
                    }
                    else
                    {
                        BasicThread tempThread;
                        threads.TryGetValue(thread.ThreadID, out tempThread);

                        ThreadCollectionV5 removedThreads = new ThreadCollectionV5();
                        if (tempThread != null)
                        {
                            UpdateThreadCache(tempThread, thread);//此处是为了更新  AllCachedThreads 和其它缓存 里的这个主题
                            threads.RemoveByKey(thread.ThreadID);
                            //removedThreads.Add(tempThread);
                        }
                        else
                        {
                            UpdateAllCachedThreadsAddThreads(thread);
                        }

                        threads.Insert(0, thread);

                        if (threads.Count > count)
                        {
                            removedThreads.Add(threads[threads.Count - 1]);
                            threads.RemoveAt(threads.Count - 1);
                        }

                        UpdateAllCachedThreadsRemoveThreads(removedThreads, null, orderType, null);

                    }

                    tempAllForumTopThreads[orderType] = threads;
                }

                s_AllForumTopThreads = tempAllForumTopThreads;
            }
        }
Exemple #16
0
 public static bool Contains(int forumID, ThreadOrderType orderType)
 {
     return GetForumThreads(forumID, orderType) != null;
 }
Exemple #17
0
 private static void AddAllForumThreadToCache(ThreadOrderType orderType, BasicThread thread)
 {
     AddForumThread(0, orderType, thread);
 }
Exemple #18
0
 private static void SetAllForumThreadsToCache(ThreadOrderType orderType, ThreadCollectionV5 threads)
 {
     SetForumThreadsCache(0, orderType, threads);
 }
Exemple #19
0
        public static void ClearForumThreadsCache(int forumID, ThreadOrderType orderType)
        {
            string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, GetTotalCacheCount(orderType));

            ClearForumThreadsCache(cacheKey, forumID);
        }
Exemple #20
0
 private static ThreadCollectionV5 GetAllForumThreadsFromCache(ThreadOrderType orderType)
 {
     return GetForumThreads(0, orderType);
 }
Exemple #21
0
 public static void ClearForumThreadsCache(int forumID, ThreadOrderType orderType)
 {
     string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, GetTotalCacheCount(orderType));
     ClearForumThreadsCache(cacheKey, forumID);
 }
Exemple #22
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);
        }
Exemple #23
0
 public static void SetForumThreadsCache(int forumID, ThreadOrderType orderType, ThreadCollectionV5 threads)
 {
     lock(s_ForumLockers[forumID])
     {
         SetForumThreadsCache(forumID, orderType, threads, true);
     }
 }
Exemple #24
0
        /// <summary>
        /// 将主题加入列表  如果不存在则加入列表最前面  如果存在则提到最前面 并更新
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="orderType"></param>
        /// <param name="thread"></param>
        public static void AddForumThread(int forumID, ThreadOrderType orderType, BasicThread thread)
        {
            object obj;
            if (s_ForumLockers.TryGetValue(forumID, out obj) == false)
            {
                obj = new object();
                s_ForumLockers.Add(forumID, obj);

            }

            lock (obj)
            {
                ThreadCollectionV5 cachedThreads = GetForumThreads(forumID, orderType);

                if (cachedThreads != null)
                {
                    ThreadCollectionV5 threads = new ThreadCollectionV5(cachedThreads);
                    int count = GetTotalCacheCount(orderType);
                    ThreadCollectionV5 removedThreads = new ThreadCollectionV5();

                    BasicThread tempThread = threads.GetValue(thread.ThreadID);
                    if (tempThread != null)
                    {
                        UpdateThreadCache(tempThread, thread);
                        threads.RemoveByKey(thread.ThreadID);
                        threads.Insert(0, tempThread);
                    }
                    else
                    {
                        UpdateAllCachedThreadsAddThreads(thread);
                        threads.Insert(0, thread);
                    }


                    if (threads.Count > count)
                    {
                        removedThreads.Add(threads[threads.Count - 1]);
                        threads.RemoveAt(threads.Count - 1);
                    }

                    if (removedThreads.Count > 0)
                    {
                        string cacheKey = string.Format(CacheKey_ForumThreadOrderType, orderType.ToString(), forumID, count);
                        UpdateAllCachedThreadsRemoveThreads(removedThreads, forumID, null, cacheKey);
                    }

                    SetForumThreadsCache(forumID, orderType, threads, false);
                }
            }
        }
Exemple #25
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;
        }
Exemple #26
0
 /// <summary>
 /// 已经被缓存的个数
 /// </summary>
 /// <param name="orderType"></param>
 /// <returns></returns>
 public static int GetTopThreadCachedCount(ThreadOrderType orderType)
 {
     ThreadCollectionV5 threads = GetAllForumThreads(orderType);
     if (threads == null)
         return 0;
     else
         return threads.Count;
 }
Exemple #27
0
 private static void GetCacheType(ThreadOrderType orderType, out CacheTime? cacheTime, out CacheExpiresType expiresType, out int? minute)
 {
     minute = null;
     switch (orderType)
     {
         case ThreadOrderType.AllForumTopWeekViewThreads:
         case ThreadOrderType.ForumTopWeekViewThreads:
             cacheTime = null;
             minute = AllSettings.Current.CacheSettings.WeekPostCacheTime;
             expiresType = CacheExpiresType.Absolute;
             break;
         case ThreadOrderType.ForumTopDayViewThreads:
         case ThreadOrderType.AllForumTopDayViewThreads:
             cacheTime = null;
             minute = AllSettings.Current.CacheSettings.DayPostCacheTime;
             expiresType = CacheExpiresType.Absolute;
             break;
         case ThreadOrderType.MovedThreads:
             cacheTime = null;
             minute = 20;
             expiresType = CacheExpiresType.Absolute;
             break;
         default:
             cacheTime = CacheTime.Default;
             expiresType = CacheExpiresType.Sliding;
             break;
     }
 }
Exemple #28
0
 private static void SetAllForumThreadsToCache(ThreadOrderType orderType, ThreadCollectionV5 threads)
 {
     SetForumThreadsCache(0, orderType, threads);
 }
Exemple #29
0
 private static ThreadCollectionV5 GetAllForumThreadsFromCache(ThreadOrderType orderType)
 {
     return(GetForumThreads(0, orderType));
 }
Exemple #30
0
        public static void SetAllForumThreads(ThreadOrderType orderType, ThreadCollectionV5 threads)
        {
            if (IsInCache(orderType))
            {
                SetAllForumThreadsToCache(orderType, threads);
                return;
            }

            lock (s_AllForumTopThreadsLocker)
            {
                if (s_AllForumTopThreads == null)
                    s_AllForumTopThreads = new Dictionary<ThreadOrderType, ThreadCollectionV5>();

                if (s_AllForumTopThreads.ContainsKey(orderType))
                {
                    ThreadCollectionV5 removedThreads = new ThreadCollectionV5();
                    foreach (BasicThread thread in s_AllForumTopThreads[orderType])
                    {
                        if (threads.ContainsKey(thread.ThreadID) == false)
                            removedThreads.Add(thread);
                    }

                    UpdateAllCachedThreadsRemoveThreads(removedThreads, null, orderType, null);
                    s_AllForumTopThreads[orderType] = threads;
                }
                else
                    s_AllForumTopThreads.Add(orderType, threads);
            }

            UpdateAllCachedThreadsAddThreads(threads);
        }
Exemple #31
0
        /// <summary>
        /// 将主题加入列表  如果不存在则加入列表最前面  如果存在则提到最前面 并更新
        /// </summary>
        /// <param name="orderType"></param>
        /// <param name="thread"></param>
        public static void AddAllForumThread(ThreadOrderType orderType, BasicThread thread)
        {
            if (IsInCache(orderType))
            {
                AddAllForumThreadToCache(orderType, thread);
                return;
            }

            int count = GetTotalCacheCount(orderType);

            lock (s_AllForumTopThreadsLocker)
            {
                if (s_AllForumTopThreads == null)
                {
                    return;
                    //AllForumTopThreads = new Dictionary<ThreadOrderType, ThreadCollectionV5>();
                }

                Dictionary <ThreadOrderType, ThreadCollectionV5> tempAllForumTopThreads = new Dictionary <ThreadOrderType, ThreadCollectionV5>();

                foreach (KeyValuePair <ThreadOrderType, ThreadCollectionV5> pair in s_AllForumTopThreads)
                {
                    tempAllForumTopThreads.Add(pair.Key, pair.Value);
                }

                lock (s_AllForumTopThreadsLockers[orderType])
                {
                    ThreadCollectionV5 temp;
                    tempAllForumTopThreads.TryGetValue(orderType, out temp);

                    if (temp == null)
                    {
                        return;
                    }

                    ThreadCollectionV5 threads = new ThreadCollectionV5(temp);
                    if (threads.Count == 0)
                    {
                        threads.Add(thread);

                        tempAllForumTopThreads[orderType] = threads;

                        UpdateAllCachedThreadsAddThreads(thread);
                    }
                    else
                    {
                        BasicThread tempThread;
                        threads.TryGetValue(thread.ThreadID, out tempThread);

                        ThreadCollectionV5 removedThreads = new ThreadCollectionV5();
                        if (tempThread != null)
                        {
                            UpdateThreadCache(tempThread, thread);//此处是为了更新  AllCachedThreads 和其它缓存 里的这个主题
                            threads.RemoveByKey(thread.ThreadID);
                            //removedThreads.Add(tempThread);
                        }
                        else
                        {
                            UpdateAllCachedThreadsAddThreads(thread);
                        }

                        threads.Insert(0, thread);

                        if (threads.Count > count)
                        {
                            removedThreads.Add(threads[threads.Count - 1]);
                            threads.RemoveAt(threads.Count - 1);
                        }

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

                    tempAllForumTopThreads[orderType] = threads;
                }

                s_AllForumTopThreads = tempAllForumTopThreads;
            }
        }
Exemple #32
0
 public static bool Contains(int forumID, ThreadOrderType orderType)
 {
     return(GetForumThreads(forumID, orderType) != null);
 }
Exemple #33
0
        public static void ClearAllForumThreadsCache(ThreadOrderType orderType)
        {
            if (IsInCache(orderType))
            {
                ClearForumThreadsCache(0, orderType);
                return;
            }

            if (s_AllForumTopThreads == null)
                return;

            ThreadCollectionV5 threads;
            if (s_AllForumTopThreads.TryGetValue(orderType, out threads))
            {
                s_AllForumTopThreads.Remove(orderType);
                UpdateAllCachedThreadsRemoveThreads(threads, null, null);
            }
        }
Exemple #34
0
 private static void AddAllForumThreadToCache(ThreadOrderType orderType, BasicThread thread)
 {
     AddForumThread(0, orderType, thread);
 }
Exemple #35
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);
            }
        }
Exemple #36
0
        private static void UpdateAllCachedThreadsRemoveThread(BasicThread thread, int? forumID, ThreadOrderType? excludeOrderType, string excludeCacheKey)
        {
            ThreadCollectionV5 threads = new ThreadCollectionV5();

            threads.Add(thread);

            UpdateAllCachedThreadsRemoveThreads(threads, forumID, excludeOrderType, excludeCacheKey);
        }
Exemple #37
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);
                    }
                }
            }
        }
Exemple #38
0
 /// <summary>
 /// 要缓存的条数
 /// </summary>
 /// <param name="orderType"></param>
 /// <returns></returns>
 public static int GetTotalCacheCount(ThreadOrderType orderType)
 {
     switch (orderType)
     {
         case ThreadOrderType.ForumTopThreadsBySortOrder:
             return 300;
         case ThreadOrderType.ForumTopThreadsByThreadID:
         case ThreadOrderType.ForumTopThreadsByLastPostID:
         case ThreadOrderType.ForumTopValuedThreads:
         case ThreadOrderType.ForumTopDayHotThreads:
         case ThreadOrderType.ForumTopWeekHotThreads:
         case ThreadOrderType.ForumTopDayViewThreads:
         case ThreadOrderType.ForumTopWeekViewThreads:
             return 30;
         case ThreadOrderType.AllForumTopThreadsByThreadID:
         case ThreadOrderType.AllForumTopThreadsByLastPostID:
         case ThreadOrderType.AllForumTopValuedThreads:
         case ThreadOrderType.AllForumTopWeekHotThreads:
         case ThreadOrderType.AllForumTopDayHotThreads:
         case ThreadOrderType.AllForumTopWeekViewThreads:
         case ThreadOrderType.AllForumTopDayViewThreads:
             return 50;
         case ThreadOrderType.MovedThreads:
         case ThreadOrderType.GlobalStickThreads:
         case ThreadOrderType.ForumStickThreads:
             return int.MaxValue;
         default:
             return 0;
     }
 }