Cache ASP.Net Tutorial

File: Default.aspx
<%@ Page Language="C#" %>
<%@ OutputCache Duration="3600" VaryByParam="none" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    protected void Page_Load(object sender, EventArgs e)
    {
        Cache.Insert("Products", DateTime.Now);
        Response.AddCacheItemDependency("Products");
    }



    Product List Key Dependency


    
    

    <%= DateTime.Now.ToString("T") %>
    
            id="grdProducts"
        DataSourceID="srcProducts"
        Runat="server" />
            id="srcProducts"
        ConnectionString="<%$ ConnectionStrings:Products %>"
        SelectCommand="SELECT Title, Director FROM Products"
        Runat="server" />
   
   Add Product
    

    


File: NextPage.aspx
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    protected void dtlProduct_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        Cache.Remove("Products");
        Response.Redirect("~/Default.aspx");
    }



    Add Product Key Dependency


    
    

    

Add Product


            id="dtlProduct"
        DefaultMode="Insert"
        DataSourceID="srcProducts"
        AutoGenerateRows="false"
        AutoGenerateInsertButton="true"
        Runat="server" OnItemInserted="dtlProduct_ItemInserted">
        
                    DataField="Title"
            HeaderText="Title:" />
                    DataField="Director"
            HeaderText="Director:" />
        

    
            id="srcProducts"
        ConnectionString="<%$ ConnectionStrings:Products %>"
        InsertCommand="INSERT Products (Title, Director)
            VALUES (@Title, @Director)"
        Runat="server" />