title: how to achieve cache auto refresh in tomcat server for Grails application
body: <p>We have a web-application running on tomcat servers and we maintain cache data on the servers. We are facing issue whenever we get new data that is not fetched in the cache and not able to display on the UI. We need to restart the server every time whenever we get new traffic in order to see the new data on the UI. Below is the hibernate config part ...</p>
  
  <pre><code>hibernate {
  cache.use_second_level_cache=true
  cache.use_query_cache=true
  cache.provider_class='org.hibernate.cache.EhCacheProvider'
  show_sql=true
  }
  </code></pre>
  
  <p>let me explain the issue with example ... say I maintain <code>Services</code> in cache and this <code>Services</code> is coming from <code>OracleDB</code>. I got new <code>Services</code> in the DB and when I query in the DB for the same I do see new <code>Services</code> but when I look into the UI I am missing the new ones. I am able to see these new <code>Services</code> only when I restart the Tomcat Server.</p>
  
  <p>I would like to know is there any way to auto refresh the cache without restarting the tomcat server to get the data displayed in UI. Thanks.</p>
  
  <p>I am using <code>ehcache-core.2.4.6</code> and didn't configured <code>ehcache.xml</code> in my app, I found that two caches are maintained and those values set to below ...</p>
  
  <pre><code>      CACHE                                                CONFIGURATION
  org.hibernate.cache.StandardQueryCache      ehcache [maxElementsInMemory = 10000, overflowToDisk = true, maxElementsOnDisk = 10000000, eternal = false, timeToLiveSeconds = 120, timeToIdleSeconds = 120, memoryStoreEvictionPolicy = LRU, diskPersistent = false]  
  org.hibernate.cache.UpdateTimestampsCache   ehcache [maxElementsInMemory = 10000, overflowToDisk = true, maxElementsOnDisk = 10000000, eternal = false, timeToLiveSeconds = 120, timeToIdleSeconds = 120, memoryStoreEvictionPolicy = LRU, diskPersistent = false]
  </code></pre>
  
  <p>If I need to configure the ehcache.xml to fix the issue, do I need to change the <code>timeToIdleSeconds="120"</code> and <code>timeToLiveSeconds="120"</code> values or do I need to add anymore attributes to the config. I want the cache to be refreshed automatically whenever there is change in data from DB. Let me know if if this is not clear enough to explain the issue. Thanks.</p>