Is there a way of notifying a web server (in my case, a web server hosting a MVC2 webapp in C#) of the fact that there was a change to the database? The purpose is to keep the web server cache synchronized with the database.
There are polling constructs in ASP.NET that allow this, but I prefer a push system. I’m also under the assumption that the database can be manipulated by elements other than the web server itself.
My limited know-how of SQL Server/ASP MVC says that one way is through creating a table TRIGGER that pretty much hits a url which will force an update.
SqlDependencyis the way to go, if the rate of change is moderate. For high rates of change you better poll for changes. To understand how SqlDependency works, read The Mysterious Notification. ASP already has built-in support for SqlDependency, namely theSqlCacheDependency. There is also LinqToCache which adds SqlDependency capability to any arbitrary LINQ query, if possible.Trigger is absolutely a big no-no. You cannot have database transactions wait on some URL to respond, your performance will collapse to basically nothing. Not to mention the issue of availability (updates will fail if the URL does not respond, for whatever reason).