예제 #1
0
        /// <summary>
        /// 获取BarPost内容
        /// </summary>
        /// <param name="postId"></param>
        /// <returns></returns>
        public string GetBody(long postId)
        {
            string cacheKey = RealTimeCacheHelper.GetCacheKeyOfEntityBody(postId);
            string body     = cacheService.Get <string>(cacheKey);

            if (body == null)
            {
                BarPost BarPost = CreateDAO().SingleOrDefault <BarPost>(postId);
                body = BarPost != null ? BarPost.Body : string.Empty;
                cacheService.Add(cacheKey, body, CachingExpirationType.SingleObject);
            }
            return(body);
        }
예제 #2
0
        /// <summary>
        /// 获取BarThread内容
        /// </summary>
        /// <param name="threadId"></param>
        /// <returns></returns>
        public string GetBody(long threadId)
        {
            string cacheKey = RealTimeCacheHelper.GetCacheKeyOfEntityBody(threadId);
            string body     = cacheService.Get <string>(cacheKey);

            if (body == null)
            {
                BarThread barThread = CreateDAO().SingleOrDefault <BarThread>(threadId);
                body = barThread != null ? barThread.Body : string.Empty;
                cacheService.Add(cacheKey, body, CachingExpirationType.SingleObject);
            }
            return(body);
        }
예제 #3
0
        /// <summary>
        /// 获取问题内容
        /// </summary>
        /// <param name="threadId">问题id</param>
        /// <returns>问题正文内容</returns>
        public string GetBody(long threadId)
        {
            string cacheKey = RealTimeCacheHelper.GetCacheKeyOfEntityBody(threadId);
            string body     = cacheService.Get <string>(cacheKey);

            if (body == null)
            {
                AskQuestion askQuestion = CreateDAO().SingleOrDefault <AskQuestion>(threadId);
                body = askQuestion != null ? askQuestion.Body : string.Empty;
                body = body ?? string.Empty;
                cacheService.Add(cacheKey, body, CachingExpirationType.SingleObject);
            }

            return(body);
        }
예제 #4
0
        /// <summary>
        /// 获取词条版本正文内容
        /// </summary>
        /// <param name="versionId">日志id</param>
        /// <returns>词条版本正文内容</returns>
        public string GetBody(long versionId)
        {
            string cacheKey = RealTimeCacheHelper.GetCacheKeyOfEntityBody(versionId);
            string body     = cacheService.Get <string>(cacheKey);

            if (body == null)
            {
                WikiPageVersion wikiPageVersion = CreateDAO().SingleOrDefault <WikiPageVersion>(versionId);
                if (wikiPageVersion == null)
                {
                    return(string.Empty);
                }

                body = wikiPageVersion.Body;
                cacheService.Add(cacheKey, body, CachingExpirationType.SingleObject);
            }

            return(body);
        }
예제 #5
0
        /// <summary>
        /// 获取回答内容
        /// </summary>
        /// <param name="threadId">回答id</param>
        /// <returns>回答正文内容</returns>
        public string GetBody(long threadId)
        {
            string cacheKey = RealTimeCacheHelper.GetCacheKeyOfEntityBody(threadId);
            string body     = cacheService.Get <string>(cacheKey);

            if (body == null)
            {
                AskAnswer askAnswer = CreateDAO().SingleOrDefault <AskAnswer>(threadId);
                if (askAnswer == null)
                {
                    return(string.Empty);
                }

                body = askAnswer.Body;
                cacheService.Add(cacheKey, body, CachingExpirationType.SingleObject);
            }

            return(body);
        }
예제 #6
0
        /// <summary>
        /// 数据库新增实体后自动调用该方法
        /// </summary>
        protected virtual void OnInserted(TEntity entity)
        {
            #region 处理缓存
            if (RealTimeCacheHelper.EnableCache)
            {
                //更新列表缓存版本
                RealTimeCacheHelper.IncreaseListCacheVersion(entity);

                if (RealTimeCacheHelper.PropertyNameOfBody != null)
                {
                    string body = RealTimeCacheHelper.PropertyNameOfBody.GetValue(entity, null) as string;
                    cacheService.Add(RealTimeCacheHelper.GetCacheKeyOfEntityBody(entity.EntityId), body, RealTimeCacheHelper.CachingExpirationType);

                    //启用实体正文缓存时,不在实体缓存中存储实体正文
                    RealTimeCacheHelper.PropertyNameOfBody.SetValue(entity, null, null);
                }
                cacheService.Add(RealTimeCacheHelper.GetCacheKeyOfEntity(entity.EntityId), entity, RealTimeCacheHelper.CachingExpirationType);
            }
            #endregion
        }