I am currently using the code below to update the cache at midnight every day. It works fine, but the requirements will change so that I need to update the cache when the item in the dataset changes. I understand that there is a CacheDependency class to check if a file has changed to update the cache, but I donβt see how this relates to what I'm trying to do. Can someone help me direct me in the right direction to update the cache when the dataset changes? Thanks.
try { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["localDb"].ConnectionString); DataSet ds = new DataSet(); if (Cache["ds"] == null) { conn.Open(); SqlCommand sqlComm = new SqlCommand("SELECT EmployeeID, NationalIDNumber, ContactID, LoginID, ManagerID, Title, BirthDate, MaritalStatus, Gender FROM HumanResources.Employee", conn); SqlDataAdapter adapter = new SqlDataAdapter(sqlComm); adapter.Fill(ds); Cache.Insert("ds", ds, null, DateTime.Today.AddDays(1), TimeSpan.Zero); conn.Close(); } GridViewEmployees.DataSource = (DataSet)Cache["ds"]; GridViewEmployees.DataBind(); } catch (Exception) { throw; }
source share