//Arquivo de exemplo: SqlCacheDependency.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Data.SqlClient;
using cache = System.Web.Caching;

public partial class SqlCacheDependency : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataView origem = null;
            if (Cache["cacheItem"] == null)
            {
                cache.SqlCacheDependency dep = new cache.SqlCacheDependency("northwind", "Products");
                ConnectionStringSettings getString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["nwind"] as ConnectionStringSettings;

                if (getString != null)
                {
                    string sSql = "select Products.ProductName,Products.QuantityPerUnit, Products.UnitPrice from Products";
                    DataSet ds = new DataSet();
                    using (SqlConnection conn = new SqlConnection(getString.ConnectionString))
                    {
                        SqlCommand cmd = new SqlCommand(sSql, conn);
                        cmd.CommandType = CommandType.Text;
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.Fill(ds);
                        origem = new DataView(ds.Tables[0]);
                        Cache.Insert("cacheItem", origem, dep);
                    }
                }
            }
            else
            {
                origem = (DataView)Cache["cacheItem"];
            }
            Dt1.DataSource = origem;
            Dt1.DataBind();
        }
    }
}

