title: How can I clear ehcahe objects in spring configured java project programmatically
body: <p>Now my project need is to trigger the flushing of all active cached objects. Based on all my findings I have written the following code.</p>
  
  <pre><code>Collection&lt;String&gt; names = cacheManager.getCacheNames();
      for (String name : names) {
          Cache cache = cacheManager.getCache(name);
          cache.put(name, null);
      }
  </code></pre>
  
  <p>Here cacheManger is the object of @Autowired EhCacheCacheManager cacheManager. Even i have tried cache.evict(name); But all these hack doesn't work for me, when it comes for keyed caches. </p>
  
  <p>Yes too i have tried the annotation based envition using following code snippets:</p>
  
  <pre><code> @Caching(evict = { @CacheEvict(value = "cache1", allEntries = true), @CacheEvict(value = "cache2", allEntries = true) })
      public static boolean refresh() {
          return true;
      }
  </code></pre>
  
  <p>So the whole point I want to flush all my ehcached cached object. </p>
  
  <p>I got one understanding towards the clearing all the cached, if i could get all the keys then I could flush them by using following code snippet:</p>
  
  <pre><code>Cache cache = cacheManager.getCache(nameOfCache);
          if (cache.get(keyOfCache) != null) {
              cache.put(keyOfCache, null);
          }
  </code></pre>