How to refresh ASP.NET Cache when data is updated in database?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

Well if you haven't I suggest you do. It will bring a smile on your face. ;).

Up vote 3 down vote favorite 2 share g+ share fb share tw.

I am currently leveraging the code below to refresh a cache at midnight every day. It works great, but the requirements are going to change such that I need to update the cache when an item in the dataset changes. I understand that there is a CacheDependency class for checking to see if a file has changed in order to refresh the cache - but I don't see how that applies to what I am trying to do.

Can someone help steer me in the right direction for updating 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; } asp.net caching link|improve this question asked Jun 6 '11 at 20:09Josh723721 96% accept rate.

2 You are in the right neck of the woods with the CacheDependency but you should be looking at the SqlCacheDependency object instead. – Duncan Howe Jun 6 '11 at 20:14.

Well if you haven't I suggest you do. It will bring a smile on your face. ;) MSDN article.

DotNet 1. X approach In the old days (pre .net 2.0 and pre SQL 2005) there was also a trick with usual CacheDependency class in a way so that you created a trigger for inserts/updates on the table that needed it that barely (re)saved an empty file (so it was as fast as possible) in some folder and you depended your cache on that particular file hence getting your cache invalidated when data changed. As I heard it worked fine.

MSDN Magazine article from 2003 about it.

I was able to run aspnet_regsql. Exe and update my web. Config with the new directive.

I tried incorporating the SqlCacheDependency in the C# code by doing this: SqlCacheDependency dep = new SqlCacheDependency(sqlComm); Cache. Insert("ds", ds, dep); -- I am getting an error: When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance. – Josh Jun 6 '11 at 21:20 Nevermind... I got it... Had to do this: SqlCacheDependency dep = new SqlCacheDependency("AdventureWorks","CachePerson"); – Josh Jun 6 '11 at 21:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions