예제 #1
0
        public async Task <BBThread> GetThreadWithComments(int threadId)
        {
            if (_memoryCache.TryGetValue(Constant.Session.GlobalThreadsWithComments, out List <BBThread> fetchData))
            {
                if (!fetchData.IsNullOrEmpty() && fetchData.Any(x => x.ThreadId == threadId))
                {
                    return(fetchData.First(x => x.ThreadId == threadId));
                }
            }

            // Results does not exist, or fetchData itself is non-existant.
            if (fetchData.IsNullOrEmpty())
            {
                fetchData = new List <BBThread>();
            }

            BBThread result = await CommunityLogic.GetThreadWithComments(threadId, CurrentUser);

            fetchData.Add(result);
            _memoryCache.Set(Constant.Session.GlobalThreadsWithComments, fetchData, TimeSpan.FromHours(24));

            return(result);
        }