/// <summary> /// 获取指定版块下的最新回复 /// </summary> /// <param name="fid">指定的版块</param> /// <param name="count">返回记录数</param> /// <returns></returns> public DataTable GetLastPostList(int fid, int count) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable __postList = cache.RetrieveObject("/Aggregation/lastpostList_" + fid) as DataTable; if (__postList != null) { return(__postList); } else { __postList = DatabaseProvider.GetInstance().GetLastPostList(fid, count, Posts.GetPostTableName(), Forums.GetVisibleForum()); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 5; cache.LoadCacheStrategy(ics); cache.AddObject("/Aggregation/lastpostList_" + fid, __postList); cache.LoadDefaultCacheStrategy(); } return(__postList); }
/// <summary> /// 获取用户列表信息 /// </summary> /// <param name="topnumber">获取用户数量</param> /// <param name="orderby">排序字段</param> /// <param name="orderby">排序方式</param> /// <returns></returns> public DataTable GetUserList(int topnumber, string orderby) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable __userList = cache.RetrieveObject("/Aggregation/Users_" + orderby + "List") as DataTable; if (__userList != null) { return(__userList); } else { __userList = Users.GetUserList(topnumber, 1, orderby, "desc"); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 5; cache.LoadCacheStrategy(ics); cache.AddObject("/Aggregation/Users_" + orderby + "List", __userList); cache.LoadDefaultCacheStrategy(); } return(__userList); }
/// <summary> /// 最新空间评论数 /// </summary> /// <returns></returns> public DataTable GetSpaceTopComments() { DNTCache cache = DNTCache.GetCacheService(); DataTable __topNComments = cache.RetrieveObject("/Space/SpaceTopNewComments") as DataTable; if (__topNComments == null) { __topNComments = GetSpaceTopComments(AggregationConfig.GetConfig().SpaceTopNewCommentsCount); foreach(DataRow dr in __topNComments.Rows) { dr["author"] = Utils.HtmlEncode(dr["author"].ToString().Trim()); dr["posttitle"] = Utils.HtmlEncode(dr["posttitle"].ToString().Trim()); dr["content"] = Utils.HtmlEncode(dr["content"].ToString().Trim()); } //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = AggregationConfig.GetConfig().SpaceTopNewCommentsTimeout * 60; cache.LoadCacheStrategy(ics); cache.AddObject("/Space/SpaceTopNewComments", __topNComments); cache.LoadDefaultCacheStrategy(); } return __topNComments; }
/// <summary> /// 从缓存中获得指定排序的空间日志列表 /// </summary> /// <param name="orderby">排序字段</param> /// <returns></returns> public DataTable GetTopSpacePostListFromCache(string orderBy) { lock (lockHelper) { DNTCache cache = DNTCache.GetCacheService(); DataTable __topSpacePostList = cache.RetrieveObject("/Space/Top" + orderBy + "PostList") as DataTable; if (__topSpacePostList == null) { //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); cache.LoadCacheStrategy(ics); switch (orderBy) { case "commentcount": { ics.TimeOut = AggregationConfig.GetConfig().TopcommentcountPostListTimeout * 60; __topSpacePostList = GetTopSpacePostList(orderBy, AggregationConfig.GetConfig().TopcommentcountPostListCount); break; } case "views": { ics.TimeOut = AggregationConfig.GetConfig().TopviewsPostListTimeout * 60; __topSpacePostList = GetTopSpacePostList(orderBy, AggregationConfig.GetConfig().TopviewsPostListCount); break; } default: { orderBy = "commentcount"; __topSpacePostList = GetTopSpacePostList(orderBy, 1); __topSpacePostList.Rows.Clear(); break; } } try { cache.AddObject("/Space/Top" + orderBy + "PostList", __topSpacePostList); } finally { cache.LoadDefaultCacheStrategy(); } } return __topSpacePostList; } }
/// <summary> /// 从缓存中得到指定排序的空间列表 /// </summary> /// <param name="orderby">排序字段</param> /// <returns></returns> public DataTable GetTopSpaceListFromCache(string orderBy) { DNTCache cache = DNTCache.GetCacheService(); DataTable __topSpaceList = cache.RetrieveObject("/Space/Top" + orderBy + "SpaceList") as DataTable; if (__topSpaceList == null) { //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); cache.LoadCacheStrategy(ics); switch (orderBy) { case "commentcount": { ics.TimeOut = AggregationConfig.GetConfig().TopcommentcountPostListTimeout * 60; __topSpaceList = GetTopSpaceList(orderBy, AggregationConfig.GetConfig().TopcommentcountSpaceListCount); break; } case "visitedtimes": { ics.TimeOut = AggregationConfig.GetConfig().TopvisitedtimesSpaceListTimeout * 60; __topSpaceList = GetTopSpaceList(orderBy, AggregationConfig.GetConfig().TopvisitedtimesSpaceListCount); break; } } cache.AddObject("/Space/Top" + orderBy + "SpaceList", __topSpaceList); } cache.LoadDefaultCacheStrategy(); return __topSpaceList; }
/// <summary> /// 得到最近更新的空间列表 /// </summary> /// <param name="count">返回的记录数</param> /// <returns></returns> public DataTable GetRecentUpdateSpaceList(int count) { DNTCache cache = DNTCache.GetCacheService(); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = AggregationConfig.GetConfig().RecentUpdateSpaceAggregationListTimeout * 60; cache.LoadCacheStrategy(ics); DataTable __recentUpdateSpaceList = cache.RetrieveObject("/Space/RecentUpdateSpaceAggregationList") as DataTable; if (__recentUpdateSpaceList == null) { __recentUpdateSpaceList = SpacePluginProvider.GetInstance().GetWebSiteAggRecentUpdateSpaceList(count); cache.AddObject("/Space/RecentUpdateSpaceAggregationList", __recentUpdateSpaceList); } cache.LoadDefaultCacheStrategy(); return __recentUpdateSpaceList; }
/// <summary> /// 获取指定版块下的最新回复 /// </summary> /// <param name="fid">指定的版块</param> /// <param name="count">返回记录数</param> /// <returns></returns> public DataTable GetLastPostList(int fid, int count) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable postList = cache.RetrieveObject("/Aggregation/lastpostList_" + fid) as DataTable; if (postList == null) { postList = Discuz.Data.DatabaseProvider.GetInstance().GetLastPostList(fid, count, Posts.GetPostTableName(), Forums.GetVisibleForum()); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 5; cache.LoadCacheStrategy(ics); cache.AddObject("/Aggregation/lastpostList_" + fid, postList); cache.LoadDefaultCacheStrategy(); } return postList; }
/// <summary> /// 获取用户列表信息 /// </summary> /// <param name="topnumber">获取用户数量</param> /// <param name="orderby">排序字段</param> /// <param name="orderby">排序方式</param> /// <returns></returns> public DataTable GetUserList(int topNumber, string orderBy) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable userList = cache.RetrieveObject("/Aggregation/Users_" + orderBy + "List") as DataTable; if (userList == null) { userList = Users.GetUserList(topNumber, 1, orderBy, "desc"); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 5; cache.LoadCacheStrategy(ics); cache.AddObject("/Aggregation/Users_" + orderBy + "List", userList); cache.LoadDefaultCacheStrategy(); } return userList; }
/// <summary> /// 最新空间评论数 /// </summary> /// <returns></returns> public DataTable GetSpaceTopComments() { DNTCache cache = DNTCache.GetCacheService(); DataTable __topNComments = cache.RetrieveObject("/Space/SpaceTopNewComments") as DataTable; if (__topNComments == null) { __topNComments = GetSpaceTopComments(AggregationConfig.GetConfig().SpaceTopNewCommentsCount); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = AggregationConfig.GetConfig().SpaceTopNewCommentsTimeout; cache.LoadCacheStrategy(ics); cache.AddObject("/Space/SpaceTopNewComments", __topNComments); cache.LoadDefaultCacheStrategy(); } return __topNComments; }
public static DataTable GetForumAggerationHotTopics() { //从缓存读取主题列表 Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable hotTopicList = cache.RetrieveObject("/Aggregation/Hottopiclist") as DataTable; if (hotTopicList != null) return hotTopicList; //无缓存查检config文件存在否 string configPath = HttpContext.Current.Server.MapPath(BaseConfigs.GetForumPath + "config/agg_hottopics.config"); if (!File.Exists(configPath)) return new DataTable(); //从config文件中重建缓存 XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(configPath); XmlNode node = xmlDoc.SelectSingleNode("/Aggregationinfo/Forum"); if (node != null) { DataSet topicDataSet = new DataSet(); using (MemoryStream topicListXml = new MemoryStream(Encoding.UTF8.GetBytes(Regex.Replace(node.InnerXml, "[\x00-\x08|\x0b-\x0c|\x0e-\x1f]", "")))) { topicDataSet.ReadXml(topicListXml); } if (topicDataSet.Tables.Count != 0) hotTopicList = topicDataSet.Tables[0]; else hotTopicList = new DataTable(); } else hotTopicList = new DataTable(); } catch { hotTopicList = new DataTable(); } //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 300; cache.LoadCacheStrategy(ics); cache.AddObject("/Aggregation/Hottopiclist", hotTopicList); cache.LoadDefaultCacheStrategy(); return hotTopicList; }
/// <summary> /// 获取用户单位时间内的发帖数 /// </summary> /// <param name="topNumber">Top条数</param> /// <param name="dateType">时间类型</param> /// <param name="dateNum">时间数</param> /// <returns></returns> public List<UserPostCountInfo> GetUserPostCountList(int topNumber, DateType dateType, int dateNum) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); List<UserPostCountInfo> userPostCountInfoList = cache.RetrieveObject("/Aggregation/UserPostCountList") as List<UserPostCountInfo>; if (userPostCountInfoList == null) { userPostCountInfoList = Posts.GetUserPostCountList(topNumber, dateType, (dateNum > 1 ? dateNum : 1)); //声明新的缓存策略接口 Discuz.Cache.ICacheStrategy ics = new AggregationCacheStrategy(); ics.TimeOut = 120; cache.LoadCacheStrategy(ics); cache.AddObject("/UserPostCountList", userPostCountInfoList); cache.LoadDefaultCacheStrategy(); } return userPostCountInfoList; }