|
ASP.NET數(shù)據(jù)緩存的學(xué)習(xí)是如何呢?如何使用ASP.NET數(shù)據(jù)緩存呢?在講ASP.NET數(shù)據(jù)緩存之前還要先說一下如果在頁面中使用參數(shù)緩存。前面講過一個(gè)緩存設(shè)置VaryByParam="none"為無參數(shù),我們也可以對(duì)VaryByParam進(jìn)行設(shè)置,設(shè)置的參數(shù)與隨 GET 方法屬性發(fā)送的查詢字符串值對(duì)應(yīng),或與使用 POST 方法發(fā)送的參數(shù)對(duì)應(yīng)。將該屬性設(shè)置為多個(gè)參數(shù)時(shí),對(duì)于每個(gè)指定參數(shù)組合,輸出緩存都包含一個(gè)不同版本的請(qǐng)求文檔??赡艿闹蛋?none、星號(hào) (*) 以及任何有效的查詢字符串或 POST 參數(shù)名稱。簡(jiǎn)單點(diǎn)說,就是設(shè)置成我們?cè)陧撁嬷惺褂玫腝ueryString名稱,看個(gè)例子:
﹤%@ Page Language="C#" AutoEventWireup="true" CodeFile="date.ASPx.cs"
Inherits="date" %﹥
﹤%@ OutputCache Duration="60" VaryByParam="CustomerID" %﹥
﹤!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.
org/TR/xhtml1/DTD/xhtml1-transitional.dtd"﹥
﹤html xmlns="http://www.w3.org/1999/xhtml" ﹥
﹤head runat="server"﹥
﹤title﹥ASP.NET數(shù)據(jù)緩存﹤/title﹥
﹤/head﹥
﹤body﹥
﹤form id="form1" runat="server"﹥
﹤div﹥
﹤ASP:GridView ID="GridView1" runat="server" BackColor="LightGo
ldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
GridLines="None"﹥
﹤FooterStyle BackColor="Tan" /﹥
﹤SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /﹥
﹤PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" Horizont
alAlign="Center" /﹥
﹤HeaderStyle BackColor="Tan" Font-Bold="True" /﹥
﹤AlternatingRowStyle BackColor="PaleGoldenrod" /﹥
﹤/ASP:GridView﹥
﹤br /﹥
﹤br /﹥
﹤ASP:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/date.ASPx?Cu
stomerID=16"﹥16﹤/ASP:HyperLink﹥
﹤ASP:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/date.ASPx?Cu
stomerID=19"﹥19﹤/ASP:HyperLink﹥
﹤/div﹥
﹤/form﹥
﹤/body﹥
﹤/html﹥protected void Page_Load(object sender, EventArgs e)
{
string conn, comm, id;
if (Request.QueryString["CustomerID"] == null)
{
id = "16";
}
else
{
id = Request.QueryString["CustomerID"];
}
conn = "Server=WEB/SQLEXPRESS;Uid=moon;Pwd=1qaz2wsx;Database=store";
comm = "SELECT * FROM orders WHERE CustomerID =" + id;
SqlDataAdapter da = new SqlDataAdapter(comm, conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
Response.Write(DateTime.Now.ToString());
}
NET技術(shù):ASP.NET數(shù)據(jù)緩存之?dāng)?shù)據(jù)緩存淺談,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。