http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx
One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can store these items on the Web server or other software in the request stream, such as the proxy server or browser.
ASP.NET provides two types of caching: The first is called output caching, which allows you to store dynamic page and user control responses;
<%@ OutputCache Duration="60" VaryByParam="None" %>
The required VaryByParam attribute allows you to vary the cached output depending on GET query string or form POST parameters.
The second type of caching is traditional application data caching, which you can use to programmatically store arbitrary objects, such as data sets, to server memory.
Cache.Insert("MyData1", connectionString, new CacheDependency(Server.MapPath(\\myServer\myConfig.xml)));
Following code show how application responds when a data source or data set is not in the Cache:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
SqlConnection myConnection = new SqlConnection("server=localhost;Integrated Security=SSPI;database=pubs");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
没有评论:
发表评论