Interview Questions Headline Animator

Friday, July 28, 2006

Cached dependancy...

During my interview for the next project, I was asked a question. How would you refresh the UI on a page or a cache as soon as the data in the back end database changes (seems to be a very common interview question these days). The best answer that I could come up with at the spur of the moment was the observer pattern.
Since there is no way that one could send back a signal from the database to an application saying "I have changed", the only thing I could think of at that moment was to implement the subject in the application itself. I thought at that moment that the subject would be something like a windows service that would keep an eye on the database and when the data changes, it would notify all the observers which in turn would either refresh the cache / UI or ask the right component to do so.
I was not convinced though that this is the best solution and did a little research. Well it seems that they have come up with a cleaner solution in ASP.Net 2.0. In fact Dr. Dobb's Jounal had an article about it. ASP.Net 2.0 supplies a class called the SQLCacheDependancy that inherits from the CacheDependancy. Check it out...