Loading

C#缓存

代码
 protected void Page_Load(object sender, EventArgs e)
        {
            ArrayList myarray 
= new ArrayList();
            myarray.Add(
"1.学习园地");
            myarray.Add(
"2.交流论坛");
            myarray.Add(
"3.帮助");
            
//将数组添加到缓存中——使用Add方法
            Cache.Add("Category", myarray, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);
            myarray[
1= "2.hello";
            Cache.Insert(
"Catory", myarray);//使用insert方法修改缓存数据
            string tmpstr = "这是一个临时数据";
            Cache[
"tmpdata"= tmpstr;
            Response.Write(Cache.Get(
"tmpdata").ToString());//使用get方法获得缓存数据
            if (Cache["Category"].GetType().Name == "ArrayList")//用gettype()获取类型
                Response.Write("类型是数组");
            IDictionaryEnumerator mycache 
= Cache.GetEnumerator();//使用GetEnumerator遍历缓存中的数据
            while (mycache.MoveNext())
            {
                Response.Write(mycache.Value 
+ "</br>");//这里读取出来是arraylist对象,要进行类型转换
            }
            Cache.Remove(
"tmpdata");
            Response.Write(Cache.Count);
//获取缓存中所有项的总数

        }

 

posted @ 2011-01-19 14:56  一只小青蛙  阅读(196)  评论(0编辑  收藏  举报