title: How to automatically refresh Cache using Google Guava?
body: <p>I am using Google Guava library for caching.
  For automatic cache refresh we can do as follows:</p>
  
  <pre><code>cache = CacheBuilder.newBuilder()               
                      .refreshAfterWrite(15, TimeUnit.MINUTES)
                      .maximumSize(100)
                      .build(....);
  </code></pre>
  
  <p>However, <strong>automatic refreshes are performed when the first stale request for an entry occurs</strong>.</p>
  
  <p><strong>Is there a way to refresh it automatically even though no requests came for cache data?</strong> Like for every 15 minutes the cache data should be pulled from Db and load it, no matter whether anybody called cache data or not.</p>
  
  <p>Also, Guava's cache expiry time is for entire cache. <strong>Is it possible to expire cache values based on key?</strong> Like cache data with key "NOT_SO_FREQ_CHANGE_DATA" to expire for every 1 hour and data with key "FREQ_CHANGING_DATA" should expire for every 15 minutes?</p>