解决方案 »

  1.   

    类似缓存池,实际上不就是静态全局变量LIST或DATATABLE么...
      

  2.   

    使用Cache.Add()方法将数据加入到缓存中
    //将数据项目加入缓存
        protected void btnAddCache_Click(object sender, EventArgs e)
        {
            //利用Cache.Add()方法将数据加入缓存
            Cache.Add("Name", txtUserName.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            Cache.Add("Photo", txtTel.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            Cache.Add("Position", txtJob.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            txtMsg.Text = "缓存加入成功!";
    }
    //读取缓存
    //显示缓存数据
        protected void btnDisplayCache_Click(object sender, EventArgs e)
        {
            IDictionaryEnumerator CacheIDE = Cache.GetEnumerator();//显示缓存数据
            int i = 0;
            string info = null;
            info += "缓存项目数据(Key / Value):" + "<br>";
            while (CacheIDE.MoveNext())//循环输出缓存项目
            {
                info += i.ToString() + ". ";
                info += CacheIDE.Key.ToString() + " : ";
                info += CacheIDE.Value.ToString() + "<br>";
                i++;
            }//CodeGo.net/
            if (Cache["Name"] == null)//判断缓存是否有数据项目
            {
                txtMsg.Text = "缓存内容为Null值!";
            }
            else
            {
                txtMsg.Text = info;
            }
        }