I have a scenario where I am displaying the data in the database which changes frequently (changed by outside application) on a webpage using Spring MVC, somewhat similar to a stock monitoring application. Currently i am using a daemon thread which fires on web container startup and queries the database every 45 secs and stores the data in the application wide hashmap object. And the web application reads the data from hashmap (instead of database) for displaying the data.
I have read about third party caching API’s like Ehcache and OSCache. I have read the documentation on Ehcache and seems like I can use the Hibernate query caching technique instead of a daemon thread.
Now my query if I use hibernate and enable query caching and set timetoidle to 45 secs will the data in the cache is automatically refreshed to reflect latest data in the database or do i need force refresh (query the database again and repopulate the cache) the cache, also can you explain what a self populating cache is.
In the Ehcache docs a
SelfPopulatingCacheis described as a:That means when asking the
SelfPopulatingCachefor a value and that value is not in the cache, it will create this value for you. This blog article gives a lot of details and also code (inclusively auto-updating).For me, it sounds that a Ehcache
SelfPopulatingCacheis what would fit your needs best. So I’d recommend to have a closer look at.A Hibernate 2nd level cache would surely help to increase system performance, but not solve your problem, as I understand it. It’s true when using Ehcache and setting
timeToIdleSecondsthe cache expires after that time, but it’s not refreshed automatically.Take a look at what Hibernate docs write about query cache:
Finally, OSCache is outdated.