以前看过dvbbs7.0,里面用到了很多cache,性能比以前好了很多。的确,cache对于数据量较大的情况还是有很大的用武之地的。
关于cache,msdn的帮助里面还是讲的很详细的,还有例子!一般,缓存的最多的还是用在数据缓存上,看一下DataSet数据的缓存:
void Page_Load(Object Src, EventArgs E) {
DataView Source;
// try to retrieve item from cache
// if it's not there, add it
Source = (DataView)Cache["MyDataSet"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "作者");
Source = new DataView(ds.Tables["作者"]);
Cache["MyDataSet"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
}
缓存被限制在应用程序的范围内,并且它的生存期与应用程序的生存期相同。(这个生存期到底指的什么?不是很明白)
浙公网安备 33010602011771号