protected void Page_Load(object sender, EventArgs e) { Label1.Text = "Cache Refresh: " + DateTime.Now.ToLongTimeString(); // Create a dependency connection to the database. SqlDependency.Start(GetConnectionString()); using (SqlConnection connection = new SqlConnection(GetConnectionString())) { using (SqlCommand command = new SqlCommand(GetSQL(), connection)) { SqlCacheDependency dependency = new SqlCacheDependency(command); // Refresh the cache after the number of minutes // listed below if a change does not occur. // This value could be stored in a configuration file. int numberOfMinutes = 1; DateTime expires = DateTime.Now.AddMinutes(numberOfMinutes); Response.Cache.SetExpires(expires); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.AddCacheDependency(dependency); connection.Open(); GridView1.DataSource = command.ExecuteReader(); GridView1.DataBind(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)