Hi, The database our application is using, gets reloaded with a new set of data on a daily basis. I was wondering if using a cache in this scenario would be a good idea or not. Is there any way I can detect the backend data change in my application somehow, so that I can reset application cache when the data changes in DB?
The answer lies in the question itself. You may want to build a database notification application that would appropriately notify your main application on any DB changes,thereby triggering a cache refresh.
Alternatively, your application would have to periodically poll the DB for changes continuously which is definitely going to hit the performance of your application,as the polling would consume some CPU cycles.
I'd prefer to go with the former method which is an implementation of asynchronous notification mechanism. [ October 15, 2008: Message edited by: Ajay Saxena ]
Database caching is at its best when the same data is likely to be needed within at most a few minutes of the last request. Holding all that data in the server for a full day at a time deprives other apps of resources.
You might consider what's known as a "materialized view", however. That's basically a way of marshalling what you need on the DBMS server for later retrieval.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
Thanks for your reply Tim, but I think I was not able to make you understand my question.
When I talk about caching data, I don't intend to cache it for the whole day. A particular set of the data will be i) added to cache when I make a search(say a List of Customer value objects) ii)updated in cache when I change something related to the cached dataset above(say, when I add a new customer). and iii) removed from cache based on the cache eviction settings(say in 10 minutes)
My question is to be able to reset this cache whenever the data is being changed in the database not due to the my application user's actions but by a backend sql process that writes a new set of data(causing the cached data to be obsolete) to the same database tables I'm caching my data from.
Kuldeep. [ October 15, 2008: Message edited by: K Tewari ]
Would the "database notification application" not itself be polling DB to check for the updates?
Well,certainly it would,but then you need not host it on the same machine your main app is running on.Polling at some point has to happen from the application end as the DB server doesn't have any client callback mechanism,in which case you could have some listener thread in the main app waiting on notifications from the DB server. [ October 15, 2008: Message edited by: Ajay Saxena ]