if (!ispostback)//第一次加载
            {
                stopwatch watch = new stopwatch();//定义缓存
                watch.start();
                if (cache[“grda”] == null) //如果cache为空
                {
                    grda grda = new grda();
                    datatable dt = grda.getgrda();  //获取信息

                    //为缓存赋值的最简单的方式
                    cache[“grda”] = dt;

                    //可以设置过期时间的缓存赋值方式
                    cache.insert(“grda”, dt, null, datetime.now.addseconds(30), timespan.zero);
                    //创建关联文件
                    cachedependency file = new cachedependency(“c:\\11.txt”);

                    cache.insert(“grda”, dt, file, datetime.now.addminutes(30), timespan.zero);

//(cache名,数据,关联文件,session时间,点击增加十分钟有效期(一般不用))

                }

                this.gridview1.datasource = (datatable)cache[“grda”];//从缓存中取出数据
                this.gridview1.databind();
                watch.stop();//停止缓存
                double totaltime = watch.elapsed.totalseconds;
                this.label1.text = totaltime.tostring();//显示失效时间

 

//以上分析属于个人观点   如有不同请加q472613400  讨论

摘自 liuningshiwoa的专栏