This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes EhCache and the fly likes Query Cacheing using EHCACHE Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Caching » EhCache
Reply Bookmark "Query Cacheing using EHCACHE" Watch "Query Cacheing using EHCACHE" New topic
Author

Query Cacheing using EHCACHE

Chandra Sarat
Greenhorn

Joined: Oct 18, 2011
Posts: 1
Hello,

I have a use case 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 hibnernate query caching technique instead of a daemon thread.

Now my question 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?


Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

You have to set 2 properties:-

timeToIdleSeconds:
Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that an Element can idle for infinity.
The default value is 0.

timeToLiveSeconds:
Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.


===Vyas Sanzgiri===
My Blog
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Query Cacheing using EHCACHE
 
Similar Threads
Hibernate query cache issue
How to start a daemon thread at application startup in a Spring application
Hibernate Read-Only Cache Query
clustering web servers
Use of cache through JNDI