一个web页面由多个 用户控件(User Controls)组成.有些用户控件显示的内容任何人浏览都一样(大都为统计数据包括图表,消耗大量服务器资源)
有些用户控件显示的内容为个人信息(资源占用比较小)请问如何才能减轻服务器压力?
谢谢!页面缓存?以前还听说过局部缓存?cache?……注:请不要只给超链接,我不能访问其他网站,麻烦把内容帖出来。

解决方案 »

  1.   

    前几天买的 100 MB asp 和 asp .net空间50元/年!,
    同学们可以做一个简单的个人网站用来找工作 
    http: // www.hi876.com 你们也看看吧 
      

  2.   

    谢谢各位的回复!缓存整个页是不实际的;需要为每个请求动态创建页的某些部分——应采用片段缓存。.NET Framework 开发员指南  《缓存 ASP.NET 页的某些部分》这个好像比较适合解决现在的问题。
      

  3.   

    public static int GetTopicListCount(
    int ClassID,
    int BarID,
    string T_PostUserName,
    int ShowType,
    bool IsCache
    )
    {
    SqlPersistenceContainer spc  = new SqlPersistenceContainer( CMPConfigurationHandler.ContainerMaps["GetTopicListCount"] );
    TopicSet MySet = new TopicSet();
    MySet.ClassID = ClassID;
    MySet.BarID = BarID;
    MySet.T_PostUserName = T_PostUserName;
    MySet.ShowType = ShowType;
    if( IsCache )
    {
    string CacheKeyStr = "Count" + ClassID.ToString() + BarID.ToString() + ShowType.ToString() ;
    if ( System.Web.HttpContext.Current.Cache[ CacheKeyStr ]  == null )
    {
    spc.Select( MySet ); string nCount = MySet.ResultSet.Tables[0].Rows[0][0].ToString().Trim();
    System.Web.HttpContext.Current.Cache[ CacheKeyStr ] = int.Parse( MySet.ResultSet.Tables[0].Rows[0][0].ToString() );
    }
    return (int)System.Web.HttpContext.Current.Cache[ CacheKeyStr ];
    }
    else
    {
    spc.Select( MySet ); string nCount = MySet.ResultSet.Tables[0].Rows[0][0].ToString().Trim();
    return int.Parse( nCount );
    }
    }
      

  4.   

    上面一个参数bool IsCache
    看看这个,有些东西放到Cache里.另外,几点:
    1,生成静态
    2,关闭不用的ViewState
    3,可以使用页面的缓存.
    4,数据库的索引做好优化.
    归根就是代码和数据结构的好坏.
      

  5.   

    #region 缓存相关的。
    /// <summary>
    /// 利用反射设置缓存。
    /// </summary>
    /// <param name="key"></param>
    public static System.Data.DataTable setCache(string key)
    {
    System.Data.DataTable dt=new DataTable();
    Type t = Type.GetType("DreamZone.Core.sysCollection");
    MethodInfo method = t.GetMethod(key);
    dt=(System.Data.DataTable)method.Invoke(null,null);
    setCache(key,dt);  
    return dt;
    }
    /// <summary>
    /// 直接利用key和dt设置。
    /// </summary>
    /// <param name="key"></param>
    /// <param name="dt"></param>
    /// <returns></returns>
    public static System.Data.DataTable setCache(string key,System.Data.DataTable dt)
    {
    //HttpContext.Current.Cache.Add(key,dt,null,DateTime.MaxValue,new TimeSpan(0,0,1,0),CacheItemPriority.High,null);
    HttpContext.Current.Cache.Add(key,dt,null,DateTime.MaxValue,new TimeSpan(0,0,1,0),CacheItemPriority.High,null);
    return dt;
    }
    /// <summary>
    /// 从缓存中获取,如果为空设置缓存
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static System.Data.DataTable getCache(string key)
    {  
    System.Data.DataTable dt=new DataTable();
    if(HttpContext.Current.Cache[key]!=null)
    {
    dt=(System.Data.DataTable)HttpContext.Current.Cache[key];  
    }
    else
    {  
    dt= setCache(key);
    }
     
    return dt;
    }
    /// <summary>
    /// 清空缓存
    /// </summary>
    /// <param name="key"></param>
    public static void clearCache(string key)
    {
    HttpContext.Current.Cache.Remove(key); 
    }
    #endregion
      

  6.   

    少用重量级控件webcontrols
    用轻量级的htmlcontrols
      

  7.   

    Cache
    把生成图形的数据写入Cache中