cachecontroller.cs
来自「基于Asp.net、MS sql sever 2000、C# 论坛系统源码」· CS 代码 · 共 338 行
CS
338 行
using System;
using Stella.BusinessLogic;
using Stella.Utility;
using Stella.Model;
using System.Web;
using System.Collections;
namespace Stella.Web.ProcessFlow
{
/// <summary>
/// 缓存控制器
/// </summary>
public class CacheController
{
#region GetCachedForum
/// <summary>
/// 获取缓存的论坛
/// </summary>
/// <returns>完整的论坛</returns>
public Forum GetCachedForum()
{
if(HttpContext.Current.Cache[CType.Forum]==null)
{
Forum forum=new Forum();
ForumLogic forumlogic=new ForumLogic();
DistrictLogic districtlogic=new DistrictLogic();
if(forum.Districts!=null)
forum.Districts.Clear();
forumlogic.FillWithDistricts(forum);
if(forum.Districts==null)
HttpContext.Current.Cache.Insert(CType.Forum,forum,null,System.DateTime.Now.AddHours(24),TimeSpan.Zero);
else
{
foreach(District district in forum.Districts)
{
districtlogic.FillWithThemes(district);
}
forum.Config=GetCachedForumConfig();
HttpContext.Current.Cache.Insert(CType.Forum,forum,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
}
return (Forum)HttpContext.Current.Cache[CType.Forum];
}
#endregion
#region GetCachedThemes
/// <summary>
/// 得到缓存的版块列表
/// </summary>
/// <returns>版块列表</returns>
public ArrayList GetCachedThemes()
{
if(HttpContext.Current.Cache[CType.Themes]==null)
{
Forum forum=GetCachedForum();
ArrayList list=new ArrayList();
foreach(District dist in forum.Districts)
{
foreach(Theme theme in dist.Themes)
{
list.Add(theme);
}
}
HttpContext.Current.Cache.Insert(CType.Themes,list,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (ArrayList)HttpContext.Current.Cache[CType.Themes];
}
#endregion
#region GetCachedTopics
/// <summary>
/// 得到缓存的相应版块第一页的主题列表
/// </summary>
/// <param name="themeId">版块编号</param>
/// <returns>主题列表</returns>
public Theme GetCachedTopics(int themeId)
{
if(HttpContext.Current.Cache[CType.Topics(themeId)]==null)
{
ThemeLogic tl=new ThemeLogic();
Theme thm=new Theme();
if(thm.Topics!=null)
thm.Topics.Clear();
thm.Tid=themeId;
tl.FillWithTopics(thm,ConfigHelper.ThemeSize,1);
HttpContext.Current.Cache.Insert(CType.Topics(themeId),thm,null,System.DateTime.Now.AddMinutes(10),TimeSpan.Zero);
}
return (Theme)HttpContext.Current.Cache[CType.Topics(themeId)];
}
#endregion
#region GetCachedNewTopics
/// <summary>
/// 得到缓存的每一版块的最新主题的列表
/// </summary>
/// <param name="themeId">版块编号</param>
/// <returns>主题列表</returns>
public Hashtable GetCachedNewTopics()
{
if(HttpContext.Current.Cache[CType.NewTopics]==null)
{
Hashtable topics=new Hashtable();
Theme theme;
ArrayList ths=GetCachedThemes();
foreach(Theme th in ths)
{
theme=GetCachedTopics(th.Tid);
if(theme.Topics!=null)
topics.Add(th.Tid,theme.Topics[0]);
else
{
Stella.Model.Topic t=new Topic();
t.Caption="尚没有任何主题";
t.AddedDate=DateTime.Now;
t.AddedMember="none";
topics.Add(th.Tid,t);
}
}
HttpContext.Current.Cache.Insert(CType.NewTopics,topics,null,System.DateTime.Now.AddMinutes(10),TimeSpan.Zero);
}
return (Hashtable)HttpContext.Current.Cache[CType.NewTopics];
}
#endregion
#region GetCachedThemeName
/// <summary>
/// 得到缓存的各版块名称
/// </summary>
/// <param name="themeId">版块编号</param>
public Hashtable GetCachedThemeName()
{
if(HttpContext.Current.Cache[CType.ThemeName]==null)
{
Hashtable names=new Hashtable();
ArrayList ts=new ArrayList();
ts=GetCachedThemes();
foreach(Theme th in ts)
{
names.Add(th.Tid,th.Tname);
}
HttpContext.Current.Cache.Insert(CType.ThemeName,names,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (Hashtable)HttpContext.Current.Cache[CType.ThemeName];
}
#endregion
#region GetCachedForumConfig
/// <summary>
/// 得到缓存的论坛设定
/// </summary>
/// <returns>论坛设定</returns>
public ForumConfig GetCachedForumConfig()
{
if(HttpContext.Current.Cache[CType.ForumConfig]==null)
{
ForumLogic forumlogic=new ForumLogic();
ForumConfig config=forumlogic.GetConfig();
HttpContext.Current.Cache.Insert(CType.ForumConfig,config,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (ForumConfig)HttpContext.Current.Cache[CType.ForumConfig];
}
#endregion
#region GetCachedPlacardList
/// <summary>
/// 得到缓存的通告列表
/// </summary>
/// <returns>通告列表</returns>
public PlacardList GetCachedPlacardList()
{
if(HttpContext.Current.Cache[CType.PlacardList]==null)
{
PlacardLogic placardLogic=new PlacardLogic();
PlacardList list=new PlacardList();
if(list.Placards!=null)
list.Placards.Clear();
placardLogic.FillList(list);
HttpContext.Current.Cache.Insert(CType.PlacardList,list,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (PlacardList)HttpContext.Current.Cache[CType.PlacardList];
}
#endregion
#region GetCachedAdminerList
/// <summary>
/// 得到缓存的管理员列表
/// </summary>
/// <returns>管理员列表</returns>
public UserList GetCachedAdminerList()
{
if(HttpContext.Current.Cache[CType.AdminerList]==null)
{
UserLogic userLogic=new UserLogic();
UserList list=new UserList();
if(list.ManagerList!=null)
list.AdminerList.Clear();
userLogic.FillAdminerList(list);
HttpContext.Current.Cache.Insert(CType.AdminerList,list,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (UserList)HttpContext.Current.Cache[CType.AdminerList];
}
#endregion
#region GetCachedManagerList
/// <summary>
/// 得到缓存的斑竹列表
/// </summary>
/// <returns>斑竹列表</returns>
public UserList GetCachedManagerList()
{
if(HttpContext.Current.Cache[CType.ManagerList]==null)
{
UserLogic userLogic=new UserLogic();
UserList list=new UserList();
if(list.ManagerList!=null)
list.ManagerList.Clear();
userLogic.FillManagerList(list);
HttpContext.Current.Cache.Insert(CType.ManagerList,list,null,DateTime.MaxValue,TimeSpan.FromHours(1));
}
return (UserList)HttpContext.Current.Cache[CType.ManagerList];
}
#endregion
#region GetCachedManagerList
//这个和上一个都是从数据库查,不同的是,上一个时在管理模式时使用
//这个则在平时浏览页面时使用
/// <summary>
/// 得到缓存的每一版块的斑竹列表
/// </summary>
/// <returns>斑竹列表</returns>
public Hashtable GetCachedThemeManagerList()
{
if(HttpContext.Current.Cache[CType.ThemeManagerList]==null)
{
Hashtable ms=new Hashtable();
ArrayList mms;
UserLogic userLogic=new UserLogic();
UserList list=new UserList();
if(list.ManagerList!=null)
list.ManagerList.Clear();
userLogic.FillManagerList(list);
ArrayList ths=GetCachedThemes();
foreach(Theme th in ths)
{
mms=new ArrayList();
foreach(Member mm in list.ManagerList)
{
//先把相同版块的斑竹放到一起
if(th.Tid==mm.Manage)
{
mms.Add(mm);
}
}
//然后统一加入,用版块号做索引键
ms.Add(th.Tid,mms);
}
HttpContext.Current.Cache.Insert(CType.ThemeManagerList,ms,null,DateTime.MaxValue,TimeSpan.FromHours(3));
}
return (Hashtable)HttpContext.Current.Cache[CType.ThemeManagerList];
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?